akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
    int N,T;
    cin >> N >> T;
    vector<pair<int,int>> A(N);
    rep(i,N){
        int a,b;
        cin >> a >> b;
        A[i] = {a,b};
    }
    sort(all(A));
    vector<vector<int>> dp(N+1,vector<int>(T+1,0));
    for(int i =1;i<=N;i++)for(int t=1;t<=T;t++){
        int a,b;
        a = A[i-1].first;
        b = A[i-1].second;
        if(a>t){
            dp[i][t] = max(dp[i-1][t],dp[i][t-1]);
        } else {
            dp[i][t] = max({dp[i-1][t],dp[i][t-1],dp[i-1][t-a]+b});
        }
    }
    int mx = 0;
    int ans = 0;
    for(int i=N-1;i>=0;--i){
        int a = A[i].second;
        mx = max(mx,a);
        ans = max(ans, dp[i][T-1]+mx);
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n + 2), b(m + 2);
    a[0] = -1;
    a[n + 1] = INF;
    b[0] = -1;
    b[m + 1] = INF;
    rep(i, n) cin >> a[i + 1];
    rep(i, m) cin >> b[i + 1];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    rep(i, a.size() - 1) if (a[i] == a[i + 1])
    {
        cout << 0 << endl;
        return 0;
    }
    rep(i, b.size() - 1) if (b[i] == b[i + 1])
    {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1;
    for (int i = n * m; i > 0; i--)
    {
        int l = 0, r = a.size();
        while (r - l > 1)
        {
            int mid = (l + r) / 2;
            if (a[mid] >= i)
                r = mid;
            else
                l = mid;
        }
        int num = a.size() - r - 1, tmp = r;
        l = 0;
        r = b.size();
        while (r - l > 1)
        {
            int mid = (l + r) / 2;
            if (b[mid] >= i)
                r = mid;
            else
                l = mid;
        }
        int numm = b.size() - r - 1;
        if (a[tmp] == i)
            num = 1;
        if (b[r] == i)
            numm = 1;
        int v = num * numm;
        if (a[tmp] != i && b[r] != i)
            v -= (n * m - i);
        (ans *= v) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<double,int> P;
#define fi first
#define sec second
#define pb push_back
vector<P> v[3];
int main()
{
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<8;j++)
		{
			P a;
			cin >> a.sec >> a.fi;
			v[i].pb(a);
		}
		sort(v[i].begin(),v[i].end());
	}
	for(int i=0;i<3;i++)
	{
		printf("%d %.2f\n",v[i][0].sec,v[i][0].fi);
		printf("%d %.2f\n",v[i][1].sec,v[i][1].fi);
	}
	vector<P> rem;
	for(int i=0;i<3;i++)
	{
		for(int j=2;j<8;j++)
		{
			rem.pb(v[i][j]);
		}
	}
	sort(rem.begin(),rem.end());
	printf("%d %.2f\n",rem[0].sec,rem[0].fi);
	printf("%d %.2f\n",rem[1].sec,rem[1].fi);
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	string sharp;
	for(int i=0;i<w+2;i++){
		sharp += '#';
	}
	string a[100];
	for(int i=0;i<h;i++){
		cin >> a[i];
	}
	cout << sharp << endl;
	for(int i=0;i<h;i++){
		cout << '#' << a[i] << '#' << endl;
	}
	cout << sharp << endl;
	return 0;
}


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

using namespace std;

typedef long long  ll;

struct Data {
    int key;
    Data *prev, *nxt;
    Data() { key = -1, prev = nullptr, nxt = nullptr; }
    Data(int key, Data *prev, Data *nxt) : key(key), prev(prev) , nxt(nxt) {}
};

Data head;
int size = 0;

Data* Find(int key)
{
    for (auto it = head.nxt; it != &head; it = it->nxt)
        if (it->key == key)
            return it;
    return nullptr;
}

void Insert(int key)
{
    ++size;
    auto now = new Data;
    now->key = key;
    now->nxt = head.nxt;
    now->prev = &head;
    (*(head.nxt)).prev = now;
    head.nxt = now;
}

void Delete(Data *it)
{
    --size;
    (*(it->prev)).nxt = it->nxt;
    (*(it->nxt)).prev = it->prev;
    delete it;
}

void Delete(int key)
{
    auto it = Find(key);
    if (it != nullptr)
        Delete(it);
}

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

    int n, x;
    string s;

    head.prev = head.nxt = &head;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;

        if (s == "insert") {
            cin >> x;
            Insert(x);
        }
        else if (s == "delete") {
            cin >> x;
            Delete(x);
        }
        else if (s == "deleteFirst" && size != 0)
            Delete(head.nxt);
        else if (s == "deleteLast" && size != 0)
            Delete(head.prev);
    }

    for (auto it = head.nxt; it != &head; it = it->nxt, --size)
        cout << it->key << (size == 1 ? '\n' : ' ');

    return 0;
}

Measured memory_bytes: 32472
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans = a*x + b*y;
    int half=0;
    int rec = 0;
    while(half<=max(x,y)){
        rec = 2*c*half + a*(max(0,x-half)) + b*(max(0,y-half));
        ans = min(ans,rec);
        half++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
  char str[2000];
  char dmy[10];
  char space[] = " ";
  char *tok;
  int array[2000];
  int n = 200;
  int i = 0;
  int j = 0;
  int v;
  int k;

  // n?????????
  scanf("%d", &n);
  fgets(dmy, 20, stdin);

  // ??°????????????
  fgets(str, 2000, stdin);

  // ???????????????
  tok = strtok(str, space);
  while(tok != NULL) {
    array[i] = atoi(tok);
    i++;
    tok = strtok(NULL, space);
  }

  i = 0; // ?????????

  // ??????
  for(j = 0; j < n; j++){
    if(j == n-1){
      printf("%d\n", array[j]);
    } else {
      printf("%d ", array[j]);
    }
  }

  // ?????\?????????
  for(i = 1; i < n; i++) {

    v = array[i];
    k = i - 1;
    while(k >= 0 && array[k] > v) {
      array[k + 1] = array[k];
      k--;
    }
    array[k + 1] = v;

    // ??????
    for(j = 0; j < n; j++){
      if(j == n-1){
        printf("%d\n", array[j]);
      } else {
        printf("%d ", array[j]);
      }
    }
  }
  return 0;
}

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

int main() {
    int x, y;
    while(true){
        cin >> x >> y;
        if(x==0&&y==0) break;
        if(x>y){
            cout << y << " " << x << endl;
        }
        else{
            cout << x << " " << y << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,f[110][10],ans;
ll p[110][12];
ll c[110];
ll calc(ll mask)
{
        memset(c , 0 , sizeof c);

        for(ll i=1;i<=n;i++)
        {
                for(ll j=0;j<10;j++)
                {
                        if((mask & (1 << j)) && f[i][j]) c[i]++;
                }
        }

        ll ret = 0;

        for(ll i =1;i<=n;i++)
                ret += p[i][c[i]];

        return ret;
}
int main()
{
        ans = -1*1e16;
        cin >> n;
        for(ll i=1;i<=n;i++)
        {
                for(ll j=0;j<10;j++)
                        cin >> f[i][j];
        }
        for(ll i=1;i<=n;i++)
        {
                for(ll j=0;j<=10;j++)
                        cin >> p[i][j];
        }
        ll mask = 1;
        for(; mask < (1 << 10);mask++)
        {
                ans = max(ans , calc(mask));
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c;

  scanf("%d%d",&a,&b);

  if(a<b){
    c=a;
    a=b;
    b=c;
  }

  while(b>0){
    c=a%b;
    a=b;
    b=c;
  }
  printf("%d\n",a);
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define mod 998244353
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
const int N=2e6+7;
ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}

int main()
{
 ios::sync_with_stdio(0);
    cin.tie(0);
string s;
cin>>s;
rep(i,0,s.length())
{
    if(s[i]=='7')
    {
        cout<<"Yes";
        return 0;
    }
}
cout<<"No";

}



Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	string s;

	cin >> s;

	if (s.at(1) == 'B') {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}


}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

using P = pair<int, int>;
int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L.at(i);
    }
    int ans = 1;
    int D = 0;
    for (int i = 0; i < N; i++) {
        D += L[i];
        if (D <= X) {
            ans++;
        } else {
            break;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n; cin >> n;
  if(n&1){
    cout << 0 << endl;
  } else {
    ll ans = 0;
    ll x = 5;
    while(x <= n){
      ans += n / (x*2);
      x *= 5;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3680
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    if n % 2:
        print(0)
        exit()
    n //= 2
    res = 0
    while n:
        res += n // 5
        n //= 5
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
 int n;
 cin>>n;
 int dp[n][n];
 bool x[n][n];for(int i=0;i<n;i++)fill(x[i],x[i]+n,true);
 int p,ans=0;
 for(int i=0;i<n;i++)for(int j=0;j<n;j++)dp[i][j]=min(min(i,n-1-i),min(j,n-1-j));
for(int i=0;i<n*n;i++){
     cin>>p;p--;
     int a=p/n,b=p%n;
     ans+=dp[a][b];
     queue<pair<int,int>> que;
    x[a][b]=false;
     que.push(make_pair(a,b));
     while(!que.empty()){
          a=que.front().first;b=que.front().second;que.pop();
          if(a>0&&dp[a][b]+x[a][b]<dp[a-1][b]){
               dp[a-1][b]=dp[a][b]+x[a][b];
               que.push({a-1,b});
          }
          if(a<n-1&&dp[a][b]+x[a][b]<dp[a+1][b]){
               dp[a+1][b]=dp[a][b]+x[a][b];
               que.push({a+1,b});
          }
          if(b>0&&dp[a][b]+x[a][b]<dp[a][b-1]){
               dp[a][b-1]=dp[a][b]+x[a][b];
               que.push({a,b-1});
          }
          if(b<n-1&&dp[a][b]+x[a][b]<dp[a][b+1]){
               dp[a][b+1]=dp[a][b]+x[a][b];
               que.push({a,b+1});
          }
     }
   //  cerr<<ans<<' '<<dp[2][1]<<endl;

}
cout<<ans<<endl;





    }





      

        


Measured memory_bytes: 5752
#include <bits/stdc++.h>
#define maxn 200001
#define maxa 1000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

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

ll ceil(ll a, ll b){if((a%b) != 0) return a/b+1; return a/b;}

ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}

void solve(){
    ll x, y; cin >> x >> y; cout << ceil(x,y);
}

int main()
{
    fast();
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 long long INF = 1LL << 60;

int main(){
  map<string, int> word;
  int n; cin >> n;
  rep(i, n){
    string s; cin >> s;
    word[s]++;
  }
  int m; cin >> m;
  rep(i, m){
    string s; cin >> s;
    word[s]--;
  }
  
  int ma = 0;
  for(auto p: word){
    chmax(ma, p.second);
  }

  cout << ma << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod || x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

const int MAX_N = 1e5 + 10;

ll fpow(ll x, ll p) {
    if(p == 0) {return 1;}
    ll ans = fpow(x, p / 2);
    ans = (ans * ans) % mod;
    if(p & 1) {
        return (ans * x) % mod;
    } else {
        return ans;
    }
}

ll n, k;

ll cnt[MAX_N];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> k;
    ll ans = 0;
    for(ll i = k; i > 0; i --) {
        ll curr = k / i;
        cnt[i] = fpow(curr, n);
        ll now = cnt[i];
        for(ll j = i * 2; j <= k; j += i) {
            now -= cnt[j];
        }
        fix(now);
        //cout << curr << " " << cnt[i] << " " << now << endl;
        ans += (now * i) % mod;
        fix(ans);
        cnt[i] = now;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4320
def doit(n,m)
	if n==1 && m==0 then return 0 end

	0.upto(m-1) do |i|
		s, c = $a[i]
		s -= 1
		if $ans[s] == -1 then
			$ans[s] = c
		else
			if $ans[s] != c then return -1 end
		end
	end

	sum = 0
	if $ans[0] == 0 then
		if n==1 then 
			return 0
		else
			return -1
		end

	end

	0.upto(n-1) do |i|
		if $ans[i] == -1 then
			if i==0 then
				$ans[i] = 1
			else
				$ans[i] = 0
			end
		end
	end

	0.upto(n-1) do |i|
		sum += $ans[i]*10**(n-i-1)
	end
	return sum
end

n, m = gets.chomp.split(" ").map{|e|e.to_i}
$a = []
m.times do
	$a << gets.chomp.split(" ").map{|e|e.to_i}
end
$ans = Array.new(n,-1)

print(doit(n,m))

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int arr[1000001];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    vi v;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        v.pb(k);
    }
    sort(v.begin(),v.end());
    ll ans=0;
    for(int i=0;i<n;i++){
        int k=v[i];
        if(arr[k]==0){
            for(int j=k;j<=1000000;j+=k){
                arr[j]=1;
            }
            if(v[i+1]!=v[i])
                ans+=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7972
#include <iostream>
using namespace std;
int x, y, vis[1111111];
int main() {
	while (cin >> x >> y, x) {
		for (int i = 0; i < y; i++) vis[i] = -1;
		for (int i = 0; ; i++) {
			if (vis[x] != -1) {
				if (x == 0) cout << vis[x] << ' ' << 0 << endl;
				else cout << vis[x] << ' ' << i - vis[x] << endl;
				break;
			}
			vis[x] = i;
			x = x * 10 % y;
		}
	}
}

Measured memory_bytes: 6984
n = int(input())
hlist = list(map(int,input().split()))
mx = 0
cnt = 0
for i in range(n-1):
  if hlist[i] >= hlist[i+1]:
    cnt += 1
  else:
    if mx < cnt:
      mx = cnt
    
    cnt = 0
if mx < cnt:
  mx = cnt
print(mx)

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

int main(){
    int h, w, n, sr, sc;
    cin >> h >> w >> n >> sr >> sc;
    string s, t;
    cin >> s;
    cin >> t;
    int a = sc;
    for(int i = 0;i < n;i++){
        if(s[i] == 'R') a++;
        if(a > w){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'L' && (a-1) >= 1) a--;
    }
    a = sc;
    for(int i = 0;i < n;i++){
        if(s[i] == 'L') a--;
        if(a < 1){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'R' && (a+1) <= w) a++;
    }
    a = sr;
    for(int i = 0;i < n;i++){
        if(s[i] == 'U') a--;
        if(a < 1){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'D' && (a+1) <= h) a++;
    }
    a = sr;
    for(int i = 0;i < n;i++){
        if(s[i] == 'D') a++;
        if(a > h){
            cout << "NO" << endl;
            return 0;
        }
        if(t[i] == 'U' && (a-1) >= 1) a--;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
using namespace std;
int b[100][100], n, m;
int xx[4] = {-1, 0, 0, 1}, yy[4] = {0, -1, 1, 0};

int solv(int g[100][100], int y, int x, char c){
	if(y < 0 || x < 0 || n <= y || m <= x)return 0;
	if(c == 'a')c = g[y][x];
	if(b[y][x] || g[y][x] != c)return 0;
	b[y][x] = 1;
	for(int i = 0;i < 4;i++)solv(g, y + yy[i], x + xx[i], c);
	return 1;
}

int main(){
	int g[100][100];
	string s;
	while(cin >> n >> m, n){
		fill((int*)b, (int*)(b+100), 0);
		for(int i = 0;i < n;i++){
			cin >> s;
			for(int j = 0;j < m;j++)g[i][j] = s[j];
		}
		int ans = 0;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				ans += solv(g, i, j, 'a');
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3552
N = int(input())
A = list(map(int, input().split()))

A.sort()
chk_list = [0]*(A[-1]+1)

if N == 1:
    print(1)
    exit()

for i in A:
    if chk_list[i] == 2:
        continue

    if chk_list[i] == 1:
        chk_list[i] = 2
        continue

    chk_list[i] = 1
    for j in range(i*2, A[-1]+1, i):
        chk_list[j] = 2

print(chk_list.count(1))

Measured memory_bytes: 32168
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;




signed main() {
    ll a, b;
    cin >> a >> b;
    ll r = 0;
    r += max(a, b);
    if (r == a) a--; else if (r == b) b--;
    r += max(a, b);
    
    mes(r);
    
}


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

using namespace std;


auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t m, k;

  cin >> m >> k;
  size_t n = static_cast <size_t> (pow (2, m));

  vector <int> a (n, 2);

  vector <size_t> ans;
  ans.reserve (n * 2);

  if (m == 0)
  {
    if (k == 0)
    {
      cout << "0 0" << endl;
    }
    else
    {
      cout << "-1" << endl;
    }
    return 0;
  }
  if (m == 1)
  {
    if (k == 0)
    {
      cout << "0 0 1 1" << endl;
    }
    else
    {
      cout << "-1" << endl;
    }
    return 0;
  }
  if (k >= n)
  {
    cout << "-1" << endl;
    return 0;
  }

  ans.push_back (k);
  -- a [k];

  for (size_t i = 0; i < n; ++ i)
  {
    if (a [i] == 2)
    {
      ans.push_back (i);
      -- a [i];
    }
  }

  ans.push_back (k);
  -- a [k];

  for (size_t i = 0; i < n; ++ i)
  {
    auto j = n - 1 - i;
    if (a [j] == 1)
    {
      ans.push_back (j);
      -- a [j];
    }
  }

  copy (ans.begin (), ans.end (), ostream_iterator <decay_t <decltype (ans.front ())>> (cout, " "));
  cout << endl;
}



Measured memory_bytes: 4352
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int n;
  cin >> n;

  vector<int> ans;
  if (n == 3) ans = {2, 5, 63};
  else {
    ans.push_back(2);
    ans.push_back(3);
    ans.push_back(4);
    ans.push_back(9);
    int res = 8;
    while (ans.size() + 2 <= n && res + 2 <= 30000) {
      ans.push_back(res);
      ans.push_back(res + 2);
      res += 6;
    }
    //cout << res << endl;
    res = 15;
    while (ans.size() + 2 <= n && res <= 30000) {
      ans.push_back(res);
      res += 6;
    }
    //cout << res << endl;
    res = 6;
    while (ans.size() < n) {
      ans.push_back(res);
      res += 6;
    }
    //cout << res << endl;
  }
  rep(i, n) cout << ans[i] << ' ';
  cout << '\n';




  
  return 0;
}

Measured memory_bytes: 640
import math

n,d = map(int, input().split())
x = []
for num in range(n):
  x.append(list(map(int, input().split())))

cnt = 0
for i in range(n - 1):
  for j in range(i+1, n):
    hoge = 0
    for num in range(d):
      hoge = hoge + pow(abs(x[i][num] - x[j][num]),2)
    if(hoge == pow(int(math.sqrt(hoge)), 2)):
       cnt = cnt + 1
print(cnt)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
        #include<functional>
   //    #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------
int n,k;
vector<int> G[100050];
int x[100050],y[100050],kosuu[100050];
int visit[100050]={0};





int a[100005];
signed main(){

int n,l;
	cin>>n>>l;
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int w=0;
	for(int i=1;i<=n-1;i++){
		if(a[i]+a[i+1]>=l) w=i;
	}
	
	if(w==0) {
		cout<<"Impossible"<<endl;
		return 0;
	}
	
	else{
		cout<<"Possible"<<endl;
		for(int i=1;i<w;i++) cout<<i<<endl;
		for(int i=n-1;i>=w;i--) cout<<i<<endl;
	}
	return 0;
        }


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

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

  if (s[k - 1] == 'A') s[k - 1] = 'a';
  else if (s[k- 1] == 'B') s[k-1] = 'b';
  else s[k-1] = 'c';
  cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[200005];
int main()
{

    int n;
    char s[5];
    scanf("%s",s+1);
    int a=0,b=0;
    for(int i=1;i<=3;i++)
    {
        if(s[i]=='A')a++;
        else b++;
    }
    if(a&&b)printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() {
			while(st==null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
					
				}
				catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
	public static void main(String[] args) {
		FastReader ob =  new FastReader();
		int arr[] = new int[3];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = ob.nextInt();
		}
		Arrays.parallelSort(arr);
		if(arr[0]==arr[2]) {
			System.out.println(1);
		}
		else if(arr[0]==arr[1] || arr[1]==arr[2]) {
			System.out.println(2);
		}
		else {
			System.out.println(3);
		}
		
		
	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
int n,k;
long long w[100009];
long long s[100009];
long long dp[109][100009];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>s[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(j-w[i]<0){
				dp[i][j]=dp[i-1][j];
				continue;
			}
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+s[i]);
		}
	}
	cout<<dp[n][k]<<endl;
}


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

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);
            int[] X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x => x).ToArray();
            int[] Xs = new int[M - 1];
            for (int i = 0; i < Xs.Length; i++)
            {
                Xs[i] = X[i + 1] - X[i];
            }
            Xs = Xs.OrderBy(x => x).ToArray();
            int res = 0;
            for (int i = 0; i < M - N; i++)
            {
                res += Xs[i];
            }
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 24672
#include <iostream>

using namespace std;

int main() {
	int a,b;
	char c;
	while (cin >> a >> c >> b) {
		if (c == '?') {
			break;
		} else if (c == '+') {
			cout << a+b << endl;
		} else if (c == '-') {
			cout << a-b << endl;
		} else if (c == '*') {
			cout << a*b << endl;
		} else {
			cout << a/b << endl; 
		}
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int, input().split()))
c = "0"
ans = 1
for i in range(n-1):
  b = a[i+1]-a[i]
  if c == "+":
    if b < 0:
      c = "0"
      ans += 1
  elif c == "-":
    if b > 0:
      c = "0"
      ans += 1
  else:
    if b > 0:
      c = "+"
    elif b < 0:
      c = "-"
print(ans)
  

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  string s;cin>>s;
  rep(i,s.length()-2){
    string ss = s.substr(i,3);
    if(ss[0] == ss[2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  rep(i,s.length()-1){
    string ss = s.substr(i,2);
    if(ss[0] == ss[1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(n-1):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1
for i in range(n):
    if i+1 in d:
        print(d[i+1])
    else:
        print(0)


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

int main()
{
  int H,W;

  while(1)
  {
    cin >> H >> W;
    if(H == 0 && W == 0) break;

    for(int i = 1; i <= H; i++)
    {
      for(int j = 1; j <= W; j++)
      {
        if(i == 1 || j == 1  || i == H || j == W )
        {
          cout << "#";
        }else{
          cout << ".";
        }

      }
      cout << "\n";
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define maxm 
#define mod 
#define maxn 
 
int main()
{
	int n;
	
	scanf("%d", &n);
	puts(n % 10 == n / 100 ? "Yes" : "No");
}

Measured memory_bytes: 256
from math import factorial
def comb(n,r):
    return factorial(n) // factorial(r) // factorial(n - r)
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
x = V[-1]
ans = 0
for i in range(1,A+1):
    ans += V[-i]
    x = V[-i]
ans = ans/A
print(ans)
count = 0
import bisect
y = N - bisect.bisect(V,x)
if x == V[-1]:
    n = V.count(x)
    for i in range(A,min(B,V.count(x))+1):
        z = i - y
        count += comb(n,z)
else:
    z = A - y
    n = V.count(x)
    count += comb(n,z)
print(count)

Measured memory_bytes: 3064
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

ll power(ll a, ll b){
    if(b<1) return 1;
    if(b==1) return a;
    if(b%2!=0) return a * power(a,b-1) % MOD;
    ll t = power(a,b/2) % MOD;
    return t * t % MOD;
}

int main(void){

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

    ll ans = 0;
    for (int i = 0; i < 60; ++i) {
        ll cnt=0;
        for (int j = 0; j < N; ++j) {
            if(A[j]>>i & 1) cnt++; //1を数える
        }
        ll now = cnt * (N-cnt) % MOD;
        for (int k = 0; k < i; ++k) {
            now = now * 2 % MOD;
        }
        ans += now;
        ans %= MOD;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 2560
import sys

X="X"
N="0123456789"
for s0 in sys.stdin:
  s=s0[:-1]
  j=s.find("=")
  A=[0,s.find("+")+1,j+1,len(s)+1]
  f=0
  for a,b in zip(A[:-1],A[1:]):
    if s[a]==X and b-a>2: f=1; break
  a="NA"
  for c in N[f:]:
    b=s.replace(X,c)
    if eval(b[:j])==eval(b[j+1:]): a=c; break
  print a

Measured memory_bytes: 4284
function f()
    input = map(x->parse(Int, x), split(chomp(readline()), " "))

    h = input[1]
    w = input[2]
    s = []
    c = ""

    for i in 1:h
        push!(s, chomp(readline()))
    end

    for i in 1:h
        s_tmp = ""
        for j in 1:w
            if s[i][j] == '#' 
                c = "#"
            else
                c = 0
                if j != w c += Int(s[i][j+1] == '#') end
                if i != h && j != w c += Int(s[i+1][j+1] == '#') end
                if i != h c += Int(s[i+1][j] == '#') end
                if i != h && j != 1 c += Int(s[i+1][j-1] == '#') end
                if j != 1 c += Int(s[i][j-1] == '#') end
                if i != 1 && j != 1 c += Int(s[i-1][j-1] == '#') end
                if i != 1 c += Int(s[i-1][j] == '#') end
                if i != 1 && j != w c += Int(s[i-1][j+1] == '#') end
                c = string(c)
            end
            s_tmp = s_tmp * c
        end
        s[i] = s_tmp
    end
    for i in 1:h
        println(s[i])
    end
end
f()

Measured memory_bytes: 172752
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

ll n, m, i;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

inline void work(){
	n = read(), m = read();
	while (n != 0){
		n /= m;
		i++;
	}
	printf("%lld\n", i);
}

int main(){
	work();
	return 0;
}

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

bool tri(int a, int b, int c){
	return a < (b + c) && b < (a + c) && c < (a + b);
}

int main(){
	int a,c=0;
	cin >> a;
	int arr[a];
	for(int i=0;i<a;i++)cin >> arr[i];
	sort(arr,arr+a);
	for(int i=0;i<a-2;i++){
		for(int j=i+1;j<a-1;j++){
			for(int k=j+1;k<a;k++){
				if(arr[i] + arr[j] <= arr[k]){
					break;
				}else c++;
			}
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long a[2010],b[2010],ans,ret = 100000000000000;
int main(){
    long long i,j,n,x;
    cin >> n >> x;
    for(i=0;i<n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    for(i=0;i<n;i++){
        ans = i*x;
        for(j=0;j<n;j++){
            b[j] = min(b[j],a[(j-i+n)%n]);
            ans += b[j];
        }
        ret = min(ret,ans);
    }
    cout << ret << endl;
}

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

cnt = 0
for i in range(N):
    for j in range(N):
        k = i*2 - j
        if j < k < N and S[i] != S[j] and S[j] !=S[k] and S[i] != S[k]:
            cnt += 1

print(S.count("R")*S.count("G")*S.count("B")-cnt)

Measured memory_bytes: 68188
S = [input() for i in range(3)]

turn = 0
while 1:
    if len(S[turn]) == 0:
        players = ['A', 'B', 'C']
        print(players[turn])
        exit()
    card = S[turn][0]
    S[turn] = S[turn][1:]
    if card == 'a':
        turn = 0
    elif card == 'b':
        turn = 1
    else:
        turn = 2


Measured memory_bytes: 3060
def main():
    """
    1 <= i < j < k <= |T|
    Ti = A
    Tj = B
    Tk = C
    """
    S = input()
    ans3 = cumsum(S)
    print(ans3)


def cumsum(S):
    """
    考えたときに累積和が浮かんだ
    ABCとあるので
    i文字目までのA相当の数、つまり?も含んだ数
    これをBとCにも適用する
    Aを決め打ちで進めるとBも走査することになる
    Cは定数倍で求められるが、|S|^2: TLE で意味がない

    ここで断念していろいろ調べると
    Bを決め打ちすれば
    A: 0-(B-1)
    C: (B+1)-N
    なのでNでおｋ

    と、思ったがWAと同じ間違いをしている
    3^q パターンをきちんと考える
    """
    n = len(S)
    aa = [0 for _ in range(n+1)]
    cc = [0 for _ in range(n+1)]
    q = [0 for _ in range(n+1)]
    for i in range(n):
        aa[i+1] += aa[i] + int(S[i] == "A")
        cc[i+1] += cc[i] + int(S[i] == "C")
        q[i+1] += q[i] + int(S[i] == "?")

    ans = 0
    MOD = 10 ** 9 + 7
    for i in range(1, n-1):
        a = aa[i]
        c = cc[n] - cc[i+1]
        l = q[i]
        r = q[n] - q[i+1]
        # ABC の作り方
        # AB?: ? 1つをCに割り当てる
        # ?BC: ? 1つをAに割り当てる
        # ?B?: ? 2つをACに割り当てる
        if S[i] in ("B", "?"):
            ac = a * c * pow(3, l + r, MOD)
            aq, qc, qq = (0, 0, 0)
            if l + r - 1 >= 0:
                p = pow(3, l + r - 1, MOD)
                aq = a * r * p
                qc = l * c * p
            if l + r - 2 >= 0:
                qq = l * r * pow(3, l + r - 2, MOD)
            # print(a, c, l, r, ((l+r, l+r-1, l+r-2)), (ac, aq, qc, qq))
            # 3^x: xが負になるときに少数になってしまうので、float -> int にする必要がある
            # 上記が重いのでTLE: pow+mod引数で対応
            ans += ac + aq + qc + qq
            ans %= MOD

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 15000
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstdio>
#include <random>
#include <chrono>
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define int long long
using namespace std;

const int INF = 2e15;
const int MOD = 998244353;
int MB = 20;



void solve() {
	int n;
	cin >> n;
	vector<vector<int>> a(3, vector<int>(n)), dp(3, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[j][i];
		}
	}

	for (int i = 0; i < 3; i++) {
		dp[i][0] = a[i][0];
	}

	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int c = 1; c <= 2; c++) {
				dp[j][i] = max(dp[j][i], dp[(j + c) % 3][i - 1] + a[j][i]);
			}
		}
	}

	cout << max(max(dp[0][n - 1], dp[1][n - 1]), dp[2][n - 1]);
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 5752
K = int(input())
import sys

if K%2==0 or K%5==0:
	print(-1)
	sys.exit()

if K%7==0:
	K=K//7

i=1
j=1
while True:
	if i%K==0:
		print(j)
		break
	else:
		j+=1
		i=(i%K)*10+1

# 2darray [[0] * 4 for i in range(3)]
# import itertools

Measured memory_bytes: 9032
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    int score[] = new int[n];
    for(int i=0;i<n;i++){
		score[i] =  Integer.parseInt(sc.next());
    }
    
    //出力
	for(int r = k; r<n;r++){
      int l=r-k;
      if(score[l] < score[r]){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
}
}

Measured memory_bytes: 60892
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n, k;
	cin>>n>>k;
	long long a[n];
	for(long long i=0;i<n;i++)
	{
		cin>>a[i];
	}
	long long presum[n];
	presum[0]=a[0]+1;
	for(long long i=1;i<n;i++)
	{
		presum[i]=presum[i-1]+a[i]+1;	
	}
	long long val=presum[k-1];
	for(long long i=0;i<n-k;i++)
	{
		if(val<presum[i+k]-presum[i])
			val=presum[i+k]-presum[i];
	}
	double ans=(double)val/2;
	printf("%.12lf", ans);
	return 0;

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 3e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi m;
vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	m = vi(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

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

// ---- コーディングはここから！ ('-')7

void solve(){
 int n; cin>>n;
 vvi v(n,vi(n)); fore(i,0,n)fore(j,0,n)cin>>v[i][j];
 vvl dp(n,vl(1<<n,-1));
 auto f=[&](auto f, int x, int mask)->lli{
	 if(x==n)return mask==(1<<n)-1;
	 if(dp[x][mask]!=-1)return dp[x][mask];
	 lli res = 0;
	 fore(i,0,n)if(v[x][i] and ((1<<i)&mask)==0)res=SUM(res,f(f,x+1,mask|(1<<i)));
	 return dp[x][mask]=res;
 };
 cout<<f(f,0,0)<<ENDL;
}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


Measured memory_bytes: 363828
#include<iostream>
#include<string>
int e;
using namespace std;
int main() {
	string s;
	cin >> s;
	char a = s[0];
	char b = s[1];
	char c = s[2];
	char d = s[3];
	if (a == '+') {
		e++;
	}
	if (b == '+') {
		e++;
	}
	if (c == '+') {
		e++;
	}
	if (d == '+') {
		e++;
	}
	if (e == 0) {
		cout << "-4" << endl;
	}
	else if (e == 1) {
		cout << "-2" << endl;
	}
	else if (e == 2) {
		cout << "0" << endl;
	}
	else if (e == 3) {
		cout << "2" << endl;
	}
	else cout << "4" << 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 true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// Eratosthenesの篩
vector<bool> primeno(1000010, true);
void Eratosthenes(int n) {
    primeno.at(0) = primeno.at(1) = false;
    int limit = sqrt(n);
    for(int i = 2; i < limit; ++i) {
        if(primeno.at(i)) {
            for(int j = 0; i*(j+2) < n; ++j) {
                primeno.at(i*(j+2)) = false;
            }
        }
    }
}

vector<int> primecnt(1000010, 0);

int main() {
    Eratosthenes(1000000);
    ll n;
    for(int i = 0; i < 1000000; ++i) {
        if(primeno.at(i)) primecnt.at(i)++;
        primecnt.at(i+1) += primecnt.at(i);
    }
    while(cin >> n) {
        cout << primecnt.at(n) << endl;
    }
}


Measured memory_bytes: 6540
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC143C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int ans = S.Length;
            for (int i = 0; i < N - 1; i++)
            {
                if (S[i].ToString() == S[i + 1].ToString())
                {
                    ans -= 1;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 32384
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = map(int,input().split())
    mod = 10 ** 9 + 7
    ans = 0
    for i in range(K, N + 1 + 1):
        mi = int((i - 1) * i / 2)  #ma、miは i * (10 **100)を無視した上限下限
        ma = i * N - mi
        ans += ma - mi + 1
    print(ans % mod)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9192