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

using LL = long long;

int N;
vector<LL> A;

bool ok(LL x) {
  for(int i = 0; i < N; ++i) {
    auto a = lower_bound(i + begin(A), end(A), A[i] + x);
    auto b = lower_bound(a, end(A), *a + x);
    auto c = lower_bound(b, end(A), *b + x);
    if(c == end(A)) return false;
    if(c - begin(A) <= i + N) return true;
  }
  return false;
}

int main() {
  cin >> N;
  A.resize(N);
  for(auto& i: A) cin >> i;

  A.insert(end(A), begin(A), end(A));
  for(int i = 1; i < A.size(); ++i) A[i] += A[i-1];

  LL low = 0, high = A[N-1]/3 + 1;
  while(low + 1 != high) {
    auto middle = (low + high) / 2;
    if(ok(middle)) low  = middle;
    else           high = middle;
  }
  cout << low << endl;
}

Measured memory_bytes: 5252
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

  int w, h;
  cin >> h >> w;

  int array[h+3][w+3];

  REP(i, h) {
    REP (j, w) {
      cin >> array[i][j];
    }
  }

  vector<vector<int>> ans;
  REP(i, h) {
    REP (j, w) {
      if (array[i][j] % 2 == 1) {
        if (j < w - 1){
          array[i][j]--;
          array[i][j+1]++;
          //cout << i + 1 << " " << j + 1<< " " << i + 1 << " " << j + 2 << endl;
          ans.push_back({i+1, j+1, i+1, j+2});

        } else if (i != h - 1) {
          array[i][j]--;
          array[i+1][j]++;
          //cout << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1 << endl:
          ans.push_back({i+1, j+1, i+2, j+1});
        }
      }
    }
  }

  cout << ans.size() << endl;
  REP(i, ans.size()) {
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
  }
  return 0;
}


Measured memory_bytes: 9904
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, c, d;
vector<lli> u[4], s[4];

int main() {
  cin >> n >> c;
  for (lli i=0; i<n; ++i) {
    lli w, v; cin >> w >> v;
    if (i==0) d = w;
    u[w-d].push_back(v);
  }

  for (lli i=0; i<4; ++i) {
    sort(begin(u[i]), end(u[i]), greater<lli>());
    s[i].push_back(0);
    for (lli j=0; j<u[i].size(); ++j) {
      s[i].push_back(s[i][j] + u[i][j]);
    }
  }

  lli ans = 0;
  for (lli i0=0; i0<=u[0].size(); i0++) {
    for (lli i1=0; i1<=u[1].size(); i1++) {
      for (lli i2=0; i2<=u[2].size(); i2++) {
        for (lli i3=0; i3<=u[3].size(); i3++) {
          if (c >= (i0+i1+i2+i3)*d + i1 + 2*i2 + 3*i3)
            ans = max(ans, s[0][i0] + s[1][i1] + s[2][i2] + s[3][i3]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n;
    cin >> n;
    ll key;
    rep(i, 1e7 + 1) {
        if (n <= i * (i + 1) / 2) {
            key = i;
            break;
        }
    }

    rep(i, key + 1) {
        if (i != 0 && i != key * (key + 1) / 2 - n) cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
import java.math.BigDecimal;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    //scanner
        // 入力受付
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        // 処理
        int h = ty - sy;    // 高さ
        int w = tx - sx;    // 幅

        String ans = "";    // 回答用文字列

        // 計算
        // h回上昇
        for(int i=0; i<h; i++){
            ans += "U";             
        }
        // w+1回右
        for(int i=0; i<w+1; i++){
            ans += "R";
        }
        // h+1回下降
        for (int i=0; i<h+1; i++){
            ans += "D";
        }
        // w+1回左
        for(int i=0; i<w+1; i++){
            ans += "L";
        }
        // 一回上昇し，左へ
        ans += "UL";
        // h+1回上昇
        for(int i=0; i<h+1; i++){
            ans += "U";
        }
        // w+1回右へ
        for (int i=0; i<w+1; i++){
            ans += "R";
        }
        // h+1回下降
        for (int i=0; i<h+1; i++){
            ans += "D";
        }
        // w回左へ
        for(int i=0; i<w; i++){
            ans += "L";
        }

        // 出力
        System.out.println(ans);

    }
}

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

int n, x ;
int ans[200010];

main()
{
    
  scanf("%d %d", &n, &x);
  if (x == 1 || x == 2 * n - 1) return puts("No"), 0 ;
  ans[n - 1] = x ;
  int tmp = n - 2 ;
  for(int i = 1 ; i <= 2 * n - 1 ; i++) 
  {
    if(i == x) continue ;
    ans[tmp] = i ;
    tmp-- ;
    if(tmp < 0) tmp = 2 * n - 2 ;
  }
  puts("Yes");
  for(int i = 0 ; i < 2 * n - 1 ; i++) printf("%d\n", ans[i]);
  return 0;
}


Measured memory_bytes: 2304
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC141E_2
{
    class Program
    {
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            S = Console.ReadLine();
            rollingHash = new RollingHash(S);

            int ans = 0;

            // 最長の長さに関する二分探索
            int l = 0;
            int r = N - 1;
            while (r - l > 1)
            {
                int mid = (l + r) / 2;
                if (Can(mid)) l = mid;
                else r = mid;
            }

            ans = l;
            Console.WriteLine(ans);
            Console.ReadKey();
        }
        static RollingHash rollingHash;
        static string S;
        static int N;
        static bool Can(int len)
        {
            //もしハッシュが一致するものがあったらtrue
            for (int i = 0; i <= N - len; i++)
            {
                var hash = rollingHash.GetRollingHash(i, i + len);
                for (int j = i + len; j + len <= N; j++)
                {
                    if (hash == rollingHash.GetRollingHash(j, j + len)) return true;
                }
            }

            return false;
        }


        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }

    class RollingHash
    {
        const long B = 1000000009;
        string S;
        int N;
        ulong[] Power;
        ulong[] Hash;
        public RollingHash(string s)
        {
            S = s;
            N = s.Length;

            Power = new ulong[N + 1];
            Power[0] = 1;
            for (int i = 0; i < N; i++)
            {
                Power[i + 1] = Power[i] * B;
            }

            Hash = new ulong[N + 1];
            for (int i = 0; i < N; i++)
            {
                Hash[i + 1] = Hash[i] * B + S[i];
            }
        }
        //[l,r)
        public ulong GetRollingHash(int l, int r)
        {
            var hash = Hash[r] - Hash[l] * Power[r - l];
            return hash;
        }
    }

}


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

using namespace std;

int main()
{
  int N, A[1000];
  while(scanf("%d", &N), N) {
    for(int i = 0; i < N; i++) scanf("%d", A + i);
    int ret = 1e9;
    for(int i = 0; i < N; i++) for(int j = 0; j < i; j++) ret = min(ret, abs(A[i] - A[j]));
    printf("%d\n", ret);
  }
}

Measured memory_bytes: 3164
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    double A, B, T;
    cin >> A >> B >> T;
    cout << (int)(floor((T+0.5)/A)*B) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N;
string S[100];

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> S[i];
    int l = 0, r = 0, s = 0;
    int ans = 0;
    REP(i, 0, N) {
      if(S[i] == "lu") l = 1;
      if(S[i] == "ru") r = 1;
      if(S[i] == "ld") l = 0;
      if(S[i] == "rd") r = 0;
      if(s == 0 && l == 1 && r == 1) {
        ans++;
        s = 1;
      } else if(s == 1 && l == 0 && r == 0) {
        ans++;
        s = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

const int N = 100010;
typedef std::pair <int, int> pii;
typedef std::pair <int, pii> piii;
typedef long long ll;

int fa[N], edge[N];
bool flag[N];
ll sz[N];
std::vector <int> e[N];
int x[N];
piii p[N];

int find(int u){
    return u == fa[u] ? u : fa[u] = find(fa[u]);
}

void dfs(int u, int fa){
    for (auto v : e[u]){
        if (v == -1 || v == fa) continue;
        if (flag[u]){
            flag[v] = true;
        }
        dfs(v, u);
    }
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i){
        scanf("%d", &x[i]);
    }
    for (int i = 0; i < m; ++ i){
        int a, b, w;
        scanf("%d%d%d", &a, &b, &w);
        p[i] = {w, {a, b}};
    }
    std::sort(p, p + m);
    for (int i = 1; i <= n; ++ i){
        fa[i] = i;
        sz[i] = x[i];
        edge[i] = -1;
    }
    for (int i = 0; i < m; ++ i){
        int u = p[i].second.first, v = p[i].second.second;
        u = find(u), v = find(v);
        if (u == v){
            e[i].push_back(edge[u]);
            edge[u] = i;
            if (sz[u] >= p[i].first){
                flag[i] = true;
            }
        }
        else{
            sz[u] += sz[v];
            fa[v] = u;
            e[i].push_back(edge[u]);
            e[i].push_back(edge[v]);
            edge[u] = i;
            if (sz[u] >= p[i].first){
                flag[i] = true;
            }
        }
    }
    dfs(m - 1, -1);
    int cnt = 0;
    for (int i = 0; i < m; ++ i){
        cnt += flag[i];
    }
    printf("%d\n", m - cnt);
    return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n ;
	cin >> n ;
	vector<int> b(n);
	rep(i,n){
		cin >> b[i];
		b[i] --;
	} 
	vector<int> ans(n);
	int index =  n - 1;
	int good = -1;
	while(1){
		good = - 1;
		rep(i,b.size()){
			if(b[i] == i){
				good = i ;
			}
		}
		if(good != -1){
			ans[index] = good ;
			index -- ;
			if(index == -1){
				break;
				//答えの出力に映る
			}
		} else {
			cout << -1 << endl;
			return 0 ;
		}
		//goodをのぞいた配列を作る。
		b.erase(b.begin()+good,b.begin()+good+1);
	}
	rep(i,n){
		cout << ans[i]+1 << endl;
	} 
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

const int maxn = 2005;
ll dp[maxn][maxn]; // LCS
ll sub[maxn][maxn];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vll s(n), t(m);
  rep(i,n) cin>>s[i];
  rep(i,m) cin>>t[i];
  
  rep(i,n){
    rep(j,m){
      if(s[i]==t[j]){
        (dp[i+1][j+1]=sub[i][j]+1)%=MOD;
      }else{
        dp[i+1][j+1]=0;
      }
      
      (sub[i+1][j+1]=(sub[i][j+1]+sub[i+1][j]-sub[i][j]+dp[i+1][j+1]+MOD)%MOD)%=MOD;
    }
  }
  
  // rep(i,n+1){
  //   rep(j,n+1){
  //     cout<<dp[i][j]<<' ';
  //   }
  //   cout<<endl;
  // }
  
  ll ans=(sub[n][m]+1)%MOD;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 66312
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main() {
  string s;
  cin >> s;

  string ans = "No";
  for (int i = 0; i < s.length() - 1; i++)  {
    if (s[i] == 'A' && s[i+1] == 'B') ans = "Yes";
    if (s[i] == 'B' && s[i+1] == 'A') ans = "Yes";
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

s=get_nsp
n=s.size
ans=n
n.times do|i|
    if i.nonzero? and s[0..ans/2-1].join("")==s[ans/2..ans-1].join("") 
        break
    else
        ans-=1
    end
end
puts ans

Measured memory_bytes: 1788
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    for i in A:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    rt = 0
    for i in d:
        rt += (d[i] * (d[i]-1))//2
    for i in A:
        if d[i] == 1:
            print(rt)
        else:
            print(rt - ((d[i] * (d[i]-1))//2) + (((d[i]-1) * (d[i]-2))//2))
main()


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


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

ll solve(ll a, ll b) {
	if (b % a == 0) return 2 * b - a;
	return b / a * a * 2 + solve(b % a, a);
}

void Main()
{
	ll N, X; cin >> N >> X;
	ll a = X;
	ll b = N - X;
	if (a > b) swap(a, b);
	cout << N + solve(a, b) << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.array([list(map(int, input().split())) for _ in range(N)])

cnt = 0

for i in range(N):
    if np.dot(A[i], B) > -C:
        cnt += 1



print(cnt)        

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

int main()
{
    vector<char> n(3);
    for( int i = 0; i < 3; ++i){
        cin >> n.at(i);
        if ( n.at(i) == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

T,A=map(int,input().split())

min=5000

H=[int(x) for x in input().split()]

for i in range(N):
    #print(abs(A-(T-H[i]*0.006)))
    if abs(A-(T-H[i]*0.006)) <= min:
        min=abs(A-(T-H[i]*0.006))
        buf=i+1

print(buf)

Measured memory_bytes: 3060
n,m = [int(x) for x in input().split()]
l = []
for i in range(m):
  a = [int(x) for x in input().split()]
  l.append(a)
ans = [0]*n
hantei = ""
for i in range(m):
  if n != 1 and l[i][0]== 1 and l[i][1]== 0:
    hantei = -1
    break
  elif ans[l[i][0]-1] == l[i][1] or ans[l[i][0]-1] == 0:
    ans[l[i][0]-1] = l[i][1]
  else:
    hantei = -1
    break
if n != 1 and ans[0] == 0:
  ans[0] = 1
ans_str = [str(n) for n in ans]
if hantei == "":
  hantei = "".join(ans_str)
print(hantei)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int h,n;
    std::cin >> h>>n;
    std::vector<int> dp(h+10001,INF);
    int m=h+10000;
    std::vector<int> a(n),b(n);
    rep(i,n)std::cin >> a[i]>>b[i];
    dp[0]=0;
    rep(i,m){
        rep(j,n){
            if(a[j]+i<=m)dp[i+a[j]]=min(dp[i]+b[j],dp[i+a[j]]);
        }
    }    
    int ans=INF;
    rrep(i,h,m+1)ans=min(ans,dp[i]);
    std::cout << ans << std::endl;
    
    
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int tt; cin >> tt; for(int cs = 1; cs <= tt; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 200000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cout << "The value of " << #val << " is = " << val << endl;
#define testing cout << "--------------------------\n";

int main() {
	IOS
	int x;
	cin>>x;
	cout<<(x>=30?"Yes\n":"No\n");
}


Measured memory_bytes: 3648
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>N) {
		string ans = "No";
		RANGE(i, 1, 10) RANGE(j, 1, 10) if(i*j==N) ans="Yes";
		cout<<ans<<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);

    int N  = sc.nextInt();
    int[] re = new int[N];
    for(int i = 0;i<N;i++)
    {
    	  re[i] = sc.nextInt();
    }
    int sum =0;
    for(int i = 0;i<N;i++)
    {
    	  sum += re[i];
    }
    int hsum = 0;
    int min = sum;
    int ans = 0;
    for(int i = 1;i<N;i++)
    {
      hsum =0;
      for(int k = 0; k <=i;k++)
      {
          hsum+=re[k];
      }
      if(min > Math.abs(sum-2*hsum))
      {
       	min = Math.abs(sum-2*hsum);
      }
      else break;
    }

   	System.out.println(min);
 }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,k;
  cin>>n>>k;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  vector<ll> s(n+1);
  rep(i,n) {
    s[i+1]=s[i]+a[i];
  }
  vector<ll> b;
  int unko=0;
  rep(i,n+1) {
    repeat(j,i+1,n+1) {
      b.push_back(s[j]-s[i]);
      unko++;
    }
  }
  //cout << "unko="<<unko<<endl;
  ll ans=0;
  revrep(i,63) {
    int c=0;
    //cout << (1LL<<i) << endl;
    ll base = ans+(1LL<<i);
    for(auto& x : b) {
      if((x&base)==base) {
        c++;
      }
    }
    if(c>=k) ans=base;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6000
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int,int> Pii;
typedef pair<string, int> Psi;
typedef vector<int> Vi;
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int bfs(string worm) {
  queue<Psi> q;
  q.push(Psi(worm, 0));
  map<string, int> m;

  while(!q.empty()) {
    Psi p = q.front(); q.pop();
    if(m[p.fr]) continue;
    bool flag = false;
    string s = p.fr;
    for(int i=0; i<s.size()-1; i++) {
      if(s[i] != s[i+1]) {
	flag = true; 
	break;
      }
    }

    if(!flag) return p.sc;
    m[p.fr] = p.sc;
    for(int i=0; i<s.size()-1; i++) {
      if(s[i] != s[i+1]) {
	string next = s;
	char c;
	if(s[i] != 'r' && s[i+1] != 'r') {
	  c = 'r';
	}
	else if(s[i] != 'g' && s[i+1] != 'g') {
	  c = 'g';
	}
	else if(s[i] != 'b' && s[i+1] != 'b') {
	  c = 'b';
	}
	next[i] = next[i+1] = c;
	q.push(Psi(next, p.sc+1));
      }
    }
  }
  return -1;
}

int main() {
  string s;
  while(cin>> s && s != "0") {
    int ans = bfs(s);
    if(ans >= 0) cout<< ans<< endl;
    else cout<< "NA"<< endl;
  }
} 

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define mp make_pair
#define P pair<int,int>
#define ri register int
#define rb register bool
#define rc register char
#define t(i) edge[i].to
#define w(i) edge[i].wei
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt)

const int N=2*1e5+10;
int w[N],d[N],cnt[20],res,n,st,sxr[N];
bool book[N];

il int read()
{
	rc ch=gc;ri x=0;rb y=1;
	while(ch!='-' && (ch<'0' || ch>'9'))ch=gc;
	if(ch=='-')ch=gc,y=0;
	while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
	return y?x:-x;
}

int main()
{
	n=read();
	for(int i=1;i<n;i++){ri u=read(),v=read(),va=read();w[u]^=va;w[v]^=va;}
	for(int i=0;i<n;i++){cnt[w[i]]++;} 
	for(int i=1;i<=15;i++)res+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);  
	for(int i=1;i<(1<<15);i++)d[i]=d[i>>1]+(i&1);
	for(int i=1;i<(1<<15);i++)d[i]-=1;
	for(int i=1;i<(1<<15);i++)
		for(int j=0;j<15;j++)if((i>>j)&1)sxr[i]^=(j+1);
	for(int i=1;i<(1<<15);i++)
	{
		if(sxr[i]!=0)continue;
		for(int k=(i-1)&i;k;k=(k-1)&i)
			if(sxr[k]==0)d[i]=min(d[i],d[k]+d[i^k]);
	}printf("%d",res+d[st]);return 0;
}


Measured memory_bytes: 896
n = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            num = [L[i], L[j], L[k]]
            num.sort(reverse=True)
            if num[0] != num[1] and num[0] != num[2] and num[1] != num[2]:
                if num[0] < num[1] + num[2]:
                    ans += 1
print(ans)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define FOR(v, s, t) for(int v = s; v < t; ++v)
using namespace std;

int main(){
	int n, m, min;
	vector< int > p;
	
	while(cin >> n >> m, n){
		p.resize(n);
		FOR(i, 0, n) cin >> p[i];
		
		sort(p.begin(), p.end());
		reverse(p.begin(), p.end());
		
		min = 0;
		FOR(i, 0, n){
			if((i + 1) % m != 0){
				min += p[i];
			}
		}
		
		cout << min << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1224
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
    double a=0, b=0;
    cin >> a >> b;
    cout << a/b << endl;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a,b,c=l[i],l[j],l[k]
      if a+b>c and a+c>b and b+c>a and a!=b and a!=c and b!=c:
        ans+=1
print(ans)

Measured memory_bytes: 9204
#include <iostream>

using namespace std;

int main() {
    int N;
    int A[201];
    int counter = 0;


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


    bool flag = true;
    while (flag){
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 == 0) {
                int a = A[i] / 2;
                A[i] = a;
            } else {
                flag = false;
            }
        }
        if (flag == true) ++counter;
    }
    cout << counter << endl;
}

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

int factor2(int num) {
	int result = 0;
	while(num % 2 == 0) {
		num /= 2;
		result++;
	}
	return result;
}

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

	std::vector<int> a(N);
	for(int i = 0; i < N; i++) {
		std::cin >> a[i];
	}

	int result = 0;
	for(int i = 0; i < N; i++) {
		result += factor2(a[i]);
	}

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();

    let mut s = vec![vec!['a']; n];
    for i in 0..n {
        s[i] = read::<String>().chars().collect::<Vec<char>>();
        s[i].sort();
    }

    s.sort();

    let mut cnt:i64 = 0;
    let mut ans:i64 = 0;
    for i in 1..n {
        if s[i] == s[i-1] {
            cnt += 1;
        } else {
            ans += cnt * (cnt+1) / 2;
            cnt = 0;
        }
    }
    ans += cnt * (cnt+1) / 2;
    println!("{}", ans);
}

Measured memory_bytes: 14588
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <map>
#include <queue>
#include <math.h>
using namespace std;
double a, b, x, r2, S2, ans, S2_1;
double change(double x) {
	return x * 180 / 3.1415926535898;
}
int main() {
	cin >> a >> b >> x;
	r2= a * a;
	S2= r2 * b;
	S2_1= S2 / 2;
	if(x > S2_1) {
		double res= (x - b * a * a / 2) * 2 / a / a;
		// printf("%lf,%lf", (res + b) * a * a / 2, x);
		double res2= atan(fabs(res - b) / a);
		ans= change(res2);
	}
	else if(x < S2_1) {
		double res= 2 * x / a / b;
		// printf("%lf,%lf", res * b * a / 2, x);
		double res2= atan(b / res);
		ans= change(res2);
	}
	else {
		ans= 45;
	}
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

def print_data(a, flag):
    for i in range(n - 1, -1, -2):
        print(a[i], end = " ")
    
    for i in range(0 + flag, n, 2):
        print(a[i], end = " ")
    
    print()


if n % 2 == 0:
    print_data(a, 0)
else:
    print_data(a, 1)

Measured memory_bytes: 26176
mod = 10**9+7
frac = [1]*114514
for i in range(2,114514):
    frac[i] = i * frac[i-1]%mod
fraci = [None]*114514
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -114514-1, -1):
    fraci[i] = fraci[i+1] * (114514 + i + 1) % mod
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%mod

N, K = map(int, input().split())

def solve():
    if N == K:
        return [1] + [0]*(N-1)
    
    R = N - K
    Ans = [comb(K-1, i-1)*comb(R+1, i)%mod for i in range(1, K+1)]
    return Ans

print(*solve(), sep = '\n')

Measured memory_bytes: 46320
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner kbs = new Scanner(System.in);
		String S = kbs.next();
		String T = kbs.next();
		int A = kbs.nextInt();
		int B = kbs.nextInt();
		String U = kbs.next();
		if(U.equals(S)){
			A -= 1;
		}
		if(U.equals(T)){
			B -= 1;
		}
		System.out.printf("%d %d\n", A,B);
		kbs.close();
	}

}


Measured memory_bytes: 21204
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>
#include<set>
#include<math.h>
#include<iomanip>

using namespace std;


int main(void)
{
    string s;
    cin>>s;
    
    string s1(s.size(),'a'),s2(s.size(),'a');
    
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            s1[i]='0';
            s2[i]='1';
        }
        else{
            s1[i]='1';
            s2[i]='0';
        }
    }
    int a1=0,a2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=s1[i]) a1++;
        if(s[i]!=s2[i]) a2++;
    }
    
    if(a1<a2){
        cout<<a1<<endl;
    }
    else{
        cout<<a2<<endl;
    }
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(abs(a-c) <= d || (b - min(a, c) <= d && max(a, c) - b <= d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

int A, B;

string solve() {
    return (A % 2 == 1 && B % 2 == 1) ? "Yes" : "No";
}

signed main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> A >> B;
    cout << solve() << "\n";
    return 0;
}



Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    const M: i64 = 1000000007;

    let xs = (0..n).map(|_| sc.cin()).collect::<Vec<i64>>();
    let ys = (0..m).map(|_| sc.cin()).collect::<Vec<i64>>();

    let mut X = 0;
    for i in 0..(n-1) {
        let dx = xs[i + 1] - xs[i];
        let a = ((i + 1) * (n - i - 1)) as i64;
        X = (X + dx * a) % M;
    }

    let mut Y = 0;
    for j in 0..(m-1) {
        let dy = ys[j + 1] - ys[j];
        let b = ((j + 1) * (m - j - 1)) as i64;
        Y = (Y + dy * b) % M;
    }

    let total = (X * Y) % M;
    println!("{}", total);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}

Measured memory_bytes: 12324
#include<bits/stdc++.h>
#define ll long long int
#define MAX 1000003
#define pii pair<ll,ll>
#define VP vector< pii >
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(ll (i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define S2(x,y) scanf("%d%d",&(x),&(y))
#define SL(x) scanf("%lld",&(x))
#define SL2(x) scanf("%lld%lld",&(x),&(y))
#define P(x) printf("%d\n",(x))
#define FF first
#define SS second
using namespace std;

int main(){
		ll r,c;
		cin>>r>>c;
		vector<vector<char>>mat(r+1,vector<char>(c+1));
		rep(i,1,r+1)
			{
				rep(j,1,c+1)
					cin>>mat[i][j];
			}
		vector<vector<ll>>dp(r+1,vector<ll>(c+1,0));
		rep(i,1,c+1)
			{
				if(mat[1][i]=='.')
						dp[1][i]=1;
				else
						break;
			}
		rep(i,1,r+1)
			{
				if(mat[i][1]=='.')
						dp[i][1]=1;
				else
						break;
			}
		rep(i,2,r+1)
			{
				rep(j,2,c+1)
					{
						if(mat[i][j]=='#')
								dp[i][j]=0;
						else
								dp[i][j]=((dp[i-1][j]%MOD)+(dp[i][j-1]%MOD))%MOD;
					}
			}
		cout<<dp[r][c]%MOD;
 
return 0;
}

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

int n, a[1010];
int dp[1010][1010], dp2[1010] = {};

int ok(int l, int r){
    int &res = dp[l][r];
    if(res != -1) return res;
    res = false;
    if(l == r) res = true;
    for(int i = l+2; i < r; i += 2) if(ok(l,i) && ok(i,r)) res = true;
    if(abs(a[l] - a[r-1]) <= 1 && ok(l+1, r-1)) res = true;
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> n && n){
        rep(i, n) cin >> a[i];
        memset(dp, -1, sizeof dp);
        memset(dp2, 0, sizeof dp2);
        rep(i, n){
            dp2[i+1] = max(dp2[i+1], dp2[i]);
            for(int j = i + 2; j <= n; j += 2){
                if(ok(i, j)) dp2[j] = max(dp2[j], dp2[i] + j - i);
            }
        }
        cout << dp2[n] << endl;
    }
}

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

using namespace std;

int n;
string s;
int a[3];
int ans = 0;

int main(){
	scanf("%d", &n);

	while(n--){
		cin >> ws;
		getline(cin, s);

		for(int i = 0; i < s.size() - 1; i++){
			if(s[i] == 'A' && s[i + 1] == 'B') ans++;
		}

		if(s[0] == 'B' && s.back() == 'A') a[2]++;
		else if (s[0] == 'B') a[1]++;
		else if (s.back() == 'A') a[0]++;
	}

	if(a[2] == 0) ans += min(a[0], a[1]);
	else {
		if(a[0] + a[1] != 0) ans += a[2] + min(a[0], a[1]);
		else ans += a[2] - 1;
	}

	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
int main()
{
	int n,c,t,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	
	{
		c=0;t=i;
		while(t)
		{
			c++;
			t/=10;
		}
		if(c%2) ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef struct team {
    int name;
    int time, sol;
} team;

bool compt(const team & a, const team & b){
    if(a.sol != b.sol) return a.sol > b.sol;
    if(a.time != b.time) return a.time < b.time;
    return a.name > b.name;
}
bool eqt(const team & a, const team & b){
    return a.sol == b.sol && a.time == b.time;
}

int pena[51][11];
team teams[51];

int main(){
    int M,T,P,R;
    while(cin >> M >> T >> P >> R, M+T+P+R){
        memset(pena,0,sizeof(pena));
        memset(teams,0,sizeof(teams));
        for(int i=0; i<T; i++){
            teams[i].name = i+1;
        }
        for(int i=0; i<R; i++){
            int m,t,p,j;
            cin >> m >> t >> p >> j; t--;
            if(j == 0){ // ac
                teams[t].time += pena[t][p] + m;
                teams[t].sol++;
            } else { // wa
                pena[t][p] += 20;
            }
        }
        sort(teams, teams+T, compt);
        // for(int i=0; i<T; i++){
        //     cout << " " << teams[i].name << " "
        //          << teams[i].sol << " "
        //          << teams[i].time << endl;
        // }
        for(int i=0; i<T-1; i++){
            cout << teams[i].name;
            if(eqt(teams[i],teams[i+1])) cout << "=";
            else cout << ",";
        }
        cout << teams[T-1].name << endl;
    }
}
        
    
            
            
            
            

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

#define ll long long
#define lp(i,n) for(int i=0; i<n; i++)
#define pb push_back
const long double pi=3.141592654;
#define OSOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;



ll mod = 1e9+7;

bool vis[1000000] = {};
vector<vector<ll>>all;
vector<ll>vec;
vector<ll>v;

ll inv[1000000],fact[10000000];
ll fp(ll base, ll exp)
{
	if (exp == 0)
		return 1;
	ll ans = fp(base, exp / 2);
	ans = (ans * ans) % mod;
	if (exp % 2 != 0)
		ans = (ans * (base% mod)) % mod;
	return ans;
}

void calcFacAndInv(ll n)
{
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = (i * fact[i - 1]) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
	return (fact[n] * inv[n - r]) % mod;
}



int main()
{
	OSOS
	ll n,m;
	cin>>n>>m;

	calcFacAndInv(200000);

	ll ans = 0;

	vec.resize(n);

	lp(i,n)cin>>vec[i];

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

	ll min,max;
	for(int i=0; i<n; i++)
	{
		if(i >= m-1)
			max = ncr(i,m-1);
		else
			max = 0;

		if(n-i-1 >= m-1)
			min = ncr(n-i-1,m-1);
		else
			min = 0;

		ans += (vec[i]%mod * (max - min)%mod)%mod;
		ans%=mod;
	}

	cout<<ans;

}


Measured memory_bytes: 6656
Scanf.scanf "%d" @@ fun n ->
  let p = Array.make n 0 in
  for i = 1 to n do Scanf.scanf " %d" (fun x -> p.(x-1) <- i) done;
  Array.init n (fun i -> (n+1) * i + p.(i)) |> Array.iter (Printf.printf "%d ");
  print_newline ();
  Array.init n (fun i -> (n+1) * (n-i)) |> Array.iter (Printf.printf "%d ");
  print_newline ();


Measured memory_bytes: 5376
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=101010;
int n,cnt,a[N],c[N],g[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int tot=1;
    c[1]=a[1];
    g[1]=1;
    for(int i=2;i<=n;i++)
        if(a[i]!=a[i-1])
            c[++tot]=a[i],g[tot]=1;
        else g[tot]++;
    if(tot>3) puts("No");
    else if(tot==1)
    {
        if(c[1]!=0) puts("No");
        else puts("Yes");
    }
    else if(tot==2)
    {
        if(g[2]==2*g[1]&&c[1]==0)
            puts("Yes");
        else puts("No");
    }
    else if(tot==3)
    {
        if((c[1]^c[2]^c[3])!=0)
            puts("No");
        else if(g[1]!=g[2]||g[1]!=g[3])
            puts("No");
        else puts("Yes");
    }
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  string res = n>999 ? "ABD" : "ABC";
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

static const int MAX = 2e+3;
vector<int> adj[MAX];
int d[MAX][MAX];
int ans[MAX] = {};
int n;

void bfs(int s){
    for(int j = 0; j < n; j++){
        d[s][j] = -1;
    }
    queue<int> q;
    q.push(s);
    d[s][s] = 0;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(auto v : adj[u]){
            if(d[s][v] != -1) continue;
            q.push(v);
            d[s][v] = d[s][u] + 1;
            //printf("p[%d][%d] = %d\n", s, v, d[s][v]);
            ans[d[s][v]]++;
        }
    }
    return;
}

int main(){
    int x, y;
    cin >> n >> x >> y;
    for(int i = 0; i < n-1; i++){
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
    for(int i = 0; i < n; i++){
        bfs(i);
    }
    for(int i = 1; i < n; i++){
        printf("%d\n", ans[i] / 2);
    }
    return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int h,w,k;
    cin>>h>>w>>k;
    string grid[h];
    for(int i=0;i<h;i++) cin>>grid[i];
    int res=0;
    for(int mask=0;mask<(1<<(h+w));mask++) {
        int cnt=0;
        for(int col=0;col<w;col++) {
            for(int row=0;row<h;row++) {
                if(grid[row][col]!='#') continue;
                if((mask&((1<<col)|(1<<(w+row))))!=0) continue;
                cnt++;
            }
        }
        if(cnt==k) res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3640