akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  ll ans = INF;
  for (int i = 0; i <= max(x, y) * 2; i += 2) {
    ll total = 0;
    total += i * c;
    if (x - i / 2 >= 0) total += a * (x - i / 2);
    if (y - i / 2 >= 0) total += b * (y - i / 2);
    ans = min(ans, total);
  }

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


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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  ll s = 0;
  ll t = 1e18;
  for(int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    if(a > b) t = min(t, b);
    s += a;
  }
  cout << max(0ll, s - t) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int,int>
#define all(xs) (xs).begin(),(xs).end()
#define F first
#define S second
#define PB push_back

using namespace std;

const int INF = 1e9 + 7, N = 4010;



int a[N],b[N],c[N],d[N],e[N],f[N];
bool u[N][N],dd[N][N],l[N][N],r[N][N];
bool vis[N][N];

int dir[][2]={{0,1},{0,-1},{1,0},{-1,0}};

vector<int> xs({-INF,INF}),ys({-INF,INF});
queue<pi> q;

void BFS(int x,int y){
    q.push({x,y});
    vis[x][y]=1;
    while(!q.empty()){
       int xi=q.front().F,yi=q.front().S;
       q.pop();
       for(int i=0;i<4;i++){
          if(i==0 and u[xi][yi]) continue;
          if(i==1 and dd[xi][yi]) continue;
          if(i==2 and r[xi][yi]) continue;
          if(i==3 and l[xi][yi]) continue;
          int xii=xi+dir[i][0],yii=yi+dir[i][1];
          if(xii<0 or yii<0 or xii>=xs.size()-1 or yii>=ys.size()-1) continue;
          if(vis[xii][yii]) continue;
          vis[xii][yii]=1;
          q.push({xii,yii});
       }
    }
}



int main(){
   int n,m;
   cin>>n>>m;
   for(int i=0;i<n;i++){
       cin>>a[i]>>b[i]>>c[i];
       xs.PB(a[i]);
       xs.PB(b[i]);
       ys.PB(c[i]);    
   }	
   for(int i=0;i<m;i++){
       cin>>d[i]>>e[i]>>f[i];
       xs.PB(d[i]);
       ys.PB(e[i]);
       ys.PB(f[i]);
   } 

   sort(all(xs));
   sort(all(ys));
   xs.resize(unique(all(xs))-xs.begin());
   ys.resize(unique(all(ys))-ys.begin());
   int x=lower_bound(all(xs),0)-xs.begin(),y;
   y=lower_bound(all(ys),0)-ys.begin();
   x--,y--;
   for(int i=0;i<n;i++){
      int ai=lower_bound(all(xs),a[i])-xs.begin(),bi,ci;
      bi=lower_bound(all(xs),b[i])-xs.begin();
      ci=lower_bound(all(ys),c[i])-ys.begin();
      for(int j=ai;j<bi;j++){
          u[j][ci-1]=1;
          dd[j][ci]=1;
      }
   }   
   for(int i=0;i<m;i++){
      int di=lower_bound(all(xs),d[i])-xs.begin(),ei,fi;
      ei=lower_bound(all(ys),e[i])-ys.begin();
      fi=lower_bound(all(ys),f[i])-ys.begin();
      for(int j=ei;j<fi;j++){
          r[di-1][j]=1;
          l[di][j]=1;
      }
   }
   BFS(x,y);
   if(vis[0][0] or vis[xs.size()-1][ys.size()-1]){cout<<"INF"<<"\n"; return 0;}
   ll ans=0;
   for(int i=0;i<xs.size()-1;i++){
      for(int j=0;j<ys.size()-1;j++)
         if(vis[i][j])
            ans=(ans+(xs[i+1]-xs[i])*1LL*(ys[j+1]-ys[j]));
   }
   cout<<ans<<"\n";
   return 0;
} 


Measured memory_bytes: 49884
from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([tuple(_ab) for _ab in chunked(ab, 2)])
    cl = cr = None
    ans = 0
    for a, b in ab:
        if cr is None or cr <= a:
            cl, cr = a, b
            ans += 1
            continue
        cl = a if cl < a else cl
        cr = cr if cr < b else b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m)])))


Measured memory_bytes: 26536
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n, L;
  cin >> n >> L;
  int minx = 101;
  rep(i, n) if(abs(minx) > abs(L + i)) minx = L + i;
  int ans = 0;
  rep(i, n) ans += (L + i);
  ans -= minx;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5e5+5;
long long dp[MAXN];
long long dp2[MAXN];
long long ans;
int main() {
    long long n;
    cin>>n;
    if(n==2){
        cout<<1<<endl;
        return 0;
    }
    for(long long i=2;i*i<=n;i++){
        if(n%i == 0){
            
            long long curr = n;
            while(curr%i ==0){
                curr/=i;
            }

            if(curr%i == 1){
                ans++;
               
            }
            
            curr = n;
            long long fact = n/i;
            if(fact == i){
                continue;
            }
            while(curr%fact ==0){
                curr/=fact;
            }

            if(curr%fact == 1){
                ans++;
            }
        }
    }
    //cout<<ans<<endl;
    n--;
    for(long long i=2;i*i<=n;i++){
        if(n%i == 0){
            if(i*i ==n){
                ans++;
            }else{
                ans+=2;
            }
        }
    }
    ans+=2;
    cout<<ans<<endl;
    //cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int i,n,s[110],c=1,ans=0;
	scanf("%d",&n);
	s[0]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&(s[i]));
		if(s[i]==s[i-1])c++;
		else c=1;
		if(c%2==0)ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
n,t = map(int,input().split())
t_list = list(map(int,input().split()))

count = 0

for i,time in enumerate(t_list):
    if i == len(t_list)-1 or time + t <= t_list[i+1]:
        count += t
    else:
        count += t_list[i+1]-time

print(count)


Measured memory_bytes: 26836
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
int main(){
FASTIO;
int a[5];
int i;
for(i=0;i<5;i++){
    cin>>a[i];
    if(!a[i]){
        cout<<i+1<<endl;
        return 0;
    }
}
}


Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef string s;
map<string, int> mp;

int main() {
    s s;
    cin >> s;
    int c = 0;
    for (int i = s.length() / 2 - 1; i >= 0; i--) {
        rep(k, i) {
            if (s[k] == s[k + i]) {
                c++;
            }
        }
        if (c == i) {
            cout << i * 2 << endl;
            break;
        }
        c = 0;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define MI          map<int, int>
#define PI          pair<int, int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
ll dp[N], a[N];
int main(){
    int n;sc(n);
    fr(i, 1, n) lsc(a[i]);
    fr(i, 2, n){
        if (i==2) dp[i]=abs(a[i]-a[i-1]);
        else{
            dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2]+ abs(a[i]-a[i-2]));
        }
    }
    lpr(dp[n]);n_l;
    return 0;
}



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

const int DIM = 500005;

int arr1[DIM], arr2[DIM], aux[DIM], fth[DIM];

int getroot(int x)
{
    return fth[x] > 0 ? getroot(fth[x]) : x;
}

void unite(int p1, int p2, int &ans)
{
    p1 = getroot(p1),
    p2 = getroot(p2);
    
    if (fth[p1] > fth[p2])
        swap(p1, p2);
    if (p1 != p2)
        fth[p1] += fth[p2], fth[p2] = p1, --ans;
}

int main(void)
{
    int n, k = 0; cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> arr1[i], arr1[0] ^= arr1[i];
    for (int i = 1; i <= n; ++i)
        cin >> arr2[i], arr2[0] ^= arr2[i];
    
    aux[++k] = arr1[0]; aux[++k] = arr2[0];
    for (int i = 1; i <= n; ++i) if (arr1[i] != arr2[i])
        aux[++k] = arr1[i], aux[++k] = arr2[i];
    
    sort(aux + 1, aux + k + 1);
    k = (int) (unique(aux + 1, aux + k + 1) - (aux + 1));
    
    for (int i = 1; i <= k; ++i)
        fth[i] = -1;
    
    int ans = k - 1;
    for (int i = 1; i <= n; ++i) {
        int p1 = (int) (lower_bound(aux + 1, aux + k + 1, arr1[i]) - aux),
            p2 = (int) (lower_bound(aux + 1, aux + k + 1, arr2[i]) - aux);
        
        if (p1 != p2)
            ++ans, unite(p1, p2, ans);
    }
    
    sort(arr1, arr1 + n + 1);
    sort(arr2, arr2 + n + 1);
    
    for (int i = 0; i <= n; ++i)
        if (arr1[i] != arr2[i]) ans = -1;
    
    cout << ans << endl;
    return 0;
}

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

int main(){
      string A,B;

      cin >> A >> B;
      
      if(A.size() > B.size()){
            cout << "GREATER" << endl;
      }else if(A.size() < B.size()){
            cout << "LESS" << endl;
      }else{
            if(A == B){
                  cout << "EQUAL" << endl;
            }else{
                  cout << (A > B ? "GREATER":"LESS") << endl;
            }
      } 
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
vector<pair<char,int> >a[5];
int main(){
	for(int i=0;i<3;i++){
		while(true){
			char C;int P;
			cin>>C;if(C=='$')break;
			cin>>P;a[i].push_back(make_pair(C,P));
		}
	}
	int cnt=0;
	for(int i=0;i<=(int)a[0].size()-(int)a[1].size();i++){
		if(a[0][i].first!=a[1][0].first)continue;
		if(a[0][i].second<a[1][0].second)continue;
		int OK=0;
		for(int j=1;j<a[1].size();j++){
			if(j!=a[1].size()-1){
				if(a[0][i+j].first!=a[1][j].first)OK=1;
				if(a[0][i+j].second!=a[1][j].second)OK=1;
			}
			if(j==a[1].size()-1){
				if(a[0][i+j].first!=a[1][j].first)OK=1;
				if(a[0][i+j].second<a[1][j].second)OK=1;
			}
		}
		if(OK==0){
			//start
			for(int j=0;j<i;j++)a[3].push_back(a[0][j]);
			//second
			if(a[1].size()>=2){
				a[3].push_back(make_pair(a[0][i].first,a[0][i].second-a[1][0].second));
			}
			//third
			for(int j=0;j<a[2].size();j++)a[3].push_back(a[2][j]);
			//fourth
			int num=a[0][i+a[1].size()-1].second-a[1][a[1].size()-1].second;
			a[3].push_back(make_pair(a[1][a[1].size()-1].first,num));
			//fifth
			for(int j=i+a[1].size();j<a[0].size();j++)a[3].push_back(a[0][j]);
			cnt=1;break;
		}
	}
	for(int i=0;i<a[3].size();i++){
		if(a[3][i].second==0)continue;
		if(a[4].size()==0)a[4].push_back(a[3][i]);
		else{
			if(a[3][i].second==0)continue;
			if(a[4][a[4].size()-1].first==a[3][i].first){
				a[4][a[4].size()-1].second+=a[3][i].second;
			}
			else{a[4].push_back(a[3][i]);}
		}
	}
	if(cnt==1){
		for(int i=0;i<a[4].size();i++){
			cout<<a[4][i].first<<' '<<a[4][i].second<<' ';
		}
	}
	if(cnt==0){
		for(int i=0;i<a[0].size();i++){
			cout<<a[0][i].first<<' '<<a[0][i].second<<' ';
		}
	}
	cout<<"$"<<endl;
	return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll n, x, p[1010][1001], f[1010][1001];

ll calc(vector <int> &t){
    ll cnt[101];
    for(int i = 0 ; i < 101 ; i++) cnt[i] = 0;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < 10 ; j++)
            if(f[i][j] && t[j]) cnt[i]++;
    ll ret = 0;
    for(int i = 0 ; i < n ; i++)
        ret += p[i][cnt[i]];
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < 10 ; j++)
            cin >> f[i][j];
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < 11 ; j++)
            cin >> p[i][j];
    ll ans = -1000000000000000;
    for(ll i = 1 ; i < (1LL<<10) ; i++){
        vector <int> tmp(11);
        for(int j = 0 ; j < 10 ; j++)
            if(i&(1<<j)) tmp[j] = 1;
        ans = max(ans, calc(tmp));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        int num = 0;
        int diff = 11111;
        int abs = 0;
        int tmpDiff = 0;
        for (int i = 0; i < S.length() - 2; i++) {
            num = Integer.valueOf(S.substring(i, i + 3));
            tmpDiff = Math.max(num, 753) - Math.min(num, 753);
            diff = Math.min(diff, tmpDiff);
        }

        System.out.println(diff);
    }
}




Measured memory_bytes: 21716
#include<bits/stdc++.h>;
using namespace std;
#define ll long long
int main(){
  ll a, b,k;
  cin>>a>> b;
  k=(a+b);
  if(k%2==0){
  	cout<<k/2;
  }
  else 
  	cout<<"IMPOSSIBLE";
 return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl;
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<endl;
#define pi M_PI
int main()
{
	fastio();
	int n,l;cin>>n>>l;
	int arr[n];
	int sum=0;
	int flag=0;
	loop(i,0,n)
	{
		arr[i] = l+i;
		if(arr[i]==0)
			flag=1;
		sum+=arr[i];
	}
	// oa(arr,n);
	if(flag==1)
		cout<<sum<<endl;
	else
	{
		if(l>=0)
			cout<<sum-arr[0];
		else
			cout<<sum-arr[n-1];
	}	
	return 0;
}	

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define mod 1000000007
#define int long long int
bool palindrome(string str)
{
	int i,l=str.size();
	for(i=0;i<l/2;i++)
	{
		if(str[i]!=str[l-i-1])
		   return false;
	}
	return true;
	
}
int32_t main()
{
     string str;
     cin>>str;
     int l=str.size();
     string str1="";
     int j;
     for(j=0;j<l/2;j++)
     {
		 str1+=str[j];
	 }
	 string str2="";
	 for(j=l/2+1;j<l;j++)
	 {
		 str2+=str[j];
	 }
	 if(palindrome(str1)&&palindrome(str2)&&palindrome(str))
	      cout<<"Yes"<<endl;
	 else
	     cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if(a[sz(a)-1]==b[0]&&b[sz(b)-1]==c[0]){
    print("YES");
  }
  else{
    print("NO");
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll n; cin >> n;
    if(n==2) {
        cout << 1 << endl;
        return 0;
    }
    set<ll> s;
    for(ll i=2; i*i<=n; i++) {
        ll n2 = n;
        while(n2 % i == 0) {
            n2 /= i;
        }
        if(n2 % i == 1) s.insert(i);
    }
    n--;
    for(ll i=2; i*i<=n; i++) {
        if(n % i == 0) {
            s.insert(i); s.insert(n/i);
        }
    }
    s.insert(n);
    s.insert(n+1);
    cout << s.size() << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
 
using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
 
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;
 
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
 
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int a,b;
    cin >> a >> b;
    if(a%3==0||b%3==0||(a+b)%3==0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 3652
from collections import deque,Counter

n,m,k = map(int,input().split())
frd = [[] for _ in range(n)]
blk = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    frd[a].append(b)
    frd[b].append(a)
for _ in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    blk[c].append(d)
    blk[d].append(c)

ucnt = 0
uni = [-1]*n
stk = deque()
for i in range(n):
    if uni[i] != -1: continue
    stk.append((i,-1))
    while stk:
        cur,prev = stk.pop()
        uni[cur] = ucnt
        for nxt in frd[cur]:
            if nxt == prev: continue
            if uni[nxt] != -1: continue
            stk.append((nxt,cur))
    ucnt += 1
cnt = Counter(uni)

for i in range(n):
    ans = cnt[uni[i]] - len(frd[i]) - 1
    for b in blk[i]:
        if uni[i] == uni[b]: ans -= 1
    print(ans,end=" ")

Measured memory_bytes: 109344
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	if(a == f && b == e && c == d)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int N;
	int R;
	scanf("%d %d",&N,&R);
  	if ((N >= 1 && N < 10) && (R <= 4111 && R >= 0))
    {
      printf("%d",R + (100 * (10 - N)));
    }
  	else if ((N >= 10 && N <= 100) && (R <= 4111 && R >= 0))
    {
      printf("%d",R);
    }
  	return (0);
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
int n, q;
int a[600005], l[600005], fen[600005], ans[600005];
void update(int i,int k){
	for(int j=i;j<600000;j+=j&(-j)) fen[j]+=k;
}
int query(int i){
	int ans=0;
	for(int j=i;j>0;j-=j&(-j)) ans+=fen[j];
	return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>q;
	memset(fen, 0, sizeof fen);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		l[i]=-1;
	}
	vector<pair<pair<int, int>, int>>queries;
	for(int i=0;i<q;i++){
		int l, r;
		cin>>l>>r;
		queries.push_back({{r, l}, i});
	}
	sort(queries.begin(), queries.end());
	int idx=0;
	for(int i=1;i<=n;i++){
		if(l[a[i]] != -1) update(l[a[i]], -1);
		l[a[i]]=i;
		update(i, 1);
		while(idx<q && queries[idx].F.F==i){
			ans[queries[idx].S]=query(queries[idx].F.F)-query(queries[idx].F.S-1);
			idx++;
		}
	}
	for(int i=0;i<q;i++){
		cout<<ans[i]<<"\n";
	}
}

Measured memory_bytes: 18028
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}
use input::*;

fn main() {
    let v = input_vector::<usize>();
    if (v[0] * 100 + v[1] * 10 + v[2]) % 4 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
N = int(input())
S = input()
Min = N
siro = S.count(".")
kuro = S.count("#")
Min = min([siro, kuro])
siro_now = 0
for i in range(N):
    if S[i] == ".":
        siro_now += 1
    cnt = (((i+1)-siro_now) + (siro - siro_now))
    if Min > cnt:
        Min = cnt
print(Min)

Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>

using namespace std;

#define mp make_pair
#define int long long

vector<int> g;
vector<bool> u;

int mod = 1000000007;

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	if (abs(n - m) > 1)
	{
		cout << 0;
		return 0;
	}
	if (n == m)
	{
		int res = 1;
		for (int i = 1; i <= n; i++)
		{
			res = ((res * i) % mod) * i % mod;
		}
		cout << (res * 2) % mod;
		return 0;
	}
	int res = max(n, m);
	for (int i = 1; i <= min(n, m); i++)
	{
		res = ((res * i) % mod) * i % mod;
	}
	cout << res;
}

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

int main(){
  	long long a=2,b=1,c=0;
  int N;
  cin >> N;
  int count = 2;
  if(N == 1){
  cout << "1" << endl;
  return 0;
  }
    while(count <= N){
    c = a+b;
    a = b;
    b = c;
    count++;  
    }
  cout << c << endl;
}


Measured memory_bytes: 256
N,T = map(int, input().split())
min_cost = 1001

for i in range(N):
    c,t = map(int, (input().split()))
    if t <= T:
        if c < min_cost:
            min_cost = c

if min_cost == 1001:
    print('TLE')
else:
    print(min_cost)


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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, M; cin >> N >> M;
    ll sum = 0;
    REP(i, M) {
        ll tmp; cin >> tmp;
        sum += tmp;
    }
    cout << max(-1LL, N - sum) << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=10010,D=110,mod=1e9+7;
int n,d;
string k;
ll dp[N][D][2];
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>k>>d;
	n=k.size();
	dp[0][0][1]=1;
	for(int i=0;i<n;++i)
		for(int j=0;j<d;++j){
			for(int l=0;l<10;++l)
				dp[i+1][(j+l)%d][0]=(dp[i+1][(j+l)%d][0]+dp[i][j][0]+(l+'0'<k[i])*dp[i][j][1])%mod;
			dp[i+1][(j+k[i]-'0')%d][1]=dp[i][j][1];
		}
	cout<<(dp[n][0][0]+dp[n][0][1]-1+mod)%mod<<endl;		
}


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

struct Line {
	double a, b;
};

bool operator==(const Line &a1, const Line &a2) {
	if (abs(a1.a - a2.a) <= 1e-10 && abs(a1.b - a2.b) <= 1e-10) return true;
	return false;
}

bool operator<(const Line &a1, const Line &a2) {
	if (a1.a < a2.a) return true;
	if (a1.a > a2.a) return false;
	if (a1.b < a2.b) return true;
	return false;
}

long long N, K, A[1 << 18], B[1 << 18];
vector<Line> I;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			long long p = A[i], q = B[i], r = A[j], s = B[j];
			if (p == r || q == s) continue;
			double katamuki = 1.0L * (1.0L * s - 1.0L * q) / (1.0L * r - 1.0L * p);
			double seppen = 1.0L * q - 1.0L * katamuki * p;
			I.push_back(Line{ katamuki, seppen });
		}
	}
	sort(I.begin(), I.end());

	int cnt = 1; bool flag = false;
	for (int i = 1; i < I.size(); i++) {
		if (I[i - 1] == I[i]) cnt++;
		else cnt = 1;
		if (cnt >= K * (K - 1) / 2) flag = true;
	}

	for (int i = 0; i < N; i++) {
		int cnt = 0;
		for (int j = 0; j < N; j++) {
			if (A[i] == A[j]) cnt++;
		}
		if (cnt >= K) flag = true;
	}

	for (int i = 0; i < N; i++) {
		int cnt = 0;
		for (int j = 0; j < N; j++) {
			if (B[i] == B[j]) cnt++;
		}
		if (cnt >= K) flag = true;
	}

	if (flag == true) cout << "1" << endl;
	else cout << "0" << endl;
	return 0;
}


Measured memory_bytes: 134124
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

bool check(int n){
  int x = n%10;
  while(n){
    if(x!= n%10)return 0;
    n/=10;
  }

  return 1;
}
int main(){

    int n;
    cin>>n;

    for(int i = n;;i++){
      if(check(i)){
        cout<<i<<endl;
        return 0;
      }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool check(string s, string t, int size);
int main(){
  string s, t;
  cin >> s >> t;
  int slen=s.length(), tlen=t.length();

  int pos=-1;
  for(int i=0; i<slen-tlen+1; i++){
    if(check(s.substr(i, tlen), t, tlen)) {
      pos=max(pos, i);
    }
  }

  string ans = "UNRESTORABLE";
  if(pos!=-1){
    for(int i=0; i<pos; i++){
      if(s[i]=='?') s[i]='a';
    }
    for(int i=0; i<t.length(); i++){
      s[pos+i] = t[i];
    }
    for(int i=pos+t.length(); i<s.length(); i++){
      if(s[i]=='?') s[i]='a';
    }
    ans = s;
  }

  cout << ans << endl;

  return 0;
}

bool check(string s, string t, int size){
  int i;
  for(i=0; i<size; i++){
    if(s[i]!=t[i] && s[i]!='?') return false;
  }
  return true;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
 
using namespace std;
 
#define inf (1<<27)

struct State {
    int x,y,l,r,o,c;
    State(int xx,int yy,int ll,int rr,int oo,int cc) {
        x=xx,y=yy,l=ll,r=rr,o=oo,c=cc;
    }
};
 
bool operator > (const State &left,const State &right) {
	return left.c>right.c;
}

int map[10][10];
int cost[10][10][10][10][51];

int main() {
	int W,H,f,m,o;
	while(scanf("%d %d",&W,&H),W) {
		memset(cost,0x10,sizeof(cost));
		scanf("%d %d %d",&f,&m,&o);
		for(int j=0;j<H;j++)for(int i=0;i<W;i++) {
			scanf("%d",&map[i][j]);
		}
		if(o<=1){printf("NA\n");continue;}
		priority_queue<State,vector<State>,greater<State> > que;
		for(int i=0;i<W;i++) {
			int oo=o-1,cc=0;
			if(map[i][0]<0) {
				cc-=map[i][0];
			}else {
				oo+=map[i][0];
				if(oo>m)oo=m;
			}
			que.push(State(i,0,i,i,oo,cc));
		}
		int res=inf;
		while(!que.empty()) {
			State s=que.top();
			que.pop();
			s.o--;
			if(s.y==(H-1)){res=s.c;break;}
			if(s.o==0){continue;}
			if(cost[s.x][s.y][s.l][s.r][s.o+1]<s.c){continue;}
			State ns=s;
			ns.y++;ns.l=ns.r=ns.x;
			if(ns.y<H) {
				if(map[ns.x][ns.y]>0) {
					ns.o+=map[ns.x][ns.y];
					if(ns.o>m)ns.o=m;
				}else {
					ns.c-=map[ns.x][ns.y];
				}
				if(cost[ns.x][ns.y][ns.l][ns.r][ns.o]>ns.c) {
					cost[ns.x][ns.y][ns.l][ns.r][ns.o]=ns.c;
					que.push(ns);
				}
			}
			ns=s;
			ns.x++;
			if(ns.x<W) {
				if(ns.x>ns.r) {
					ns.r=ns.x;
					if(map[ns.x][ns.y]>0) {
						ns.o+=map[ns.x][ns.y];
						if(ns.o>m)ns.o=m;
					}else {
						ns.c-=map[ns.x][ns.y];
					}
				}
				if(cost[ns.x][ns.y][ns.l][ns.r][ns.o]>ns.c) {
					cost[ns.x][ns.y][ns.l][ns.r][ns.o]=ns.c;
					que.push(ns);
				}
			}
			ns=s;
			ns.x--;
			if(ns.x>=0) {
				if(ns.l>ns.x) {
					ns.l=ns.x;
					if(map[ns.x][ns.y]>0) {
						ns.o+=map[ns.x][ns.y];
						if(ns.o>m)ns.o=m;
					}else {
						ns.c-=map[ns.x][ns.y];
					}
				}
				if(cost[ns.x][ns.y][ns.l][ns.r][ns.o]>ns.c) {
					cost[ns.x][ns.y][ns.l][ns.r][ns.o]=ns.c;
					que.push(ns);
				}
			}
		}
		if(res<=f)printf("%d\n",res);
		else printf("NA\n");
	}
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int a;
    string s;
    cin >> a >> s;
    int ans;
    FOR(i,0,a-2){
        if(s.substr(i,3) == "ABC") ++ans; 
    }
    cout << ans << endl;
    


  

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

typedef tuple<int,int,int> T;

int main(){
    int N, Q;  cin >> N >> Q;
    vector<T> A(N);
    for(int i=0; i<N; i++){
        int S, T, X;  cin >> S >> T >> X;
        A[i] = make_tuple(X, S-X, T-X);
    }
    sort(A.begin(), A.end());

    set<pair<int,int>> D;
    for(int i=0; i<Q; i++){
        int d;  cin >> d;
        D.insert({d,i});
    }

    vector<int> ans(Q,-1);
    for(int i=0; i<N; i++){
        int L, R, X;
        tie(X,L,R) = A[i];
        auto itr = D.lower_bound({L, -1});
        while(itr != D.end()){
            if(itr->first >= R) break;
            ans[itr->second] = X;
            itr = D.erase(itr);
        }
    }

    for(int i=0; i<Q; i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 14336
n = int(input())
h = list(map(int,input().split()))
ans = 0
kar = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        kar += 1
    else:
        if kar >= ans:
            ans = kar
        kar = 0
if kar >= ans:
    ans = kar
print(ans)

Measured memory_bytes: 14224
import java.util.Scanner;

public class Main{
   public static void main(String [] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a<b)
         System.out.println("a < b");
      else if(a>b)
         System.out.println("a > b");
      else
         System.out.println("a == b");
              
      sc.close();

   }
}


Measured memory_bytes: 26208
# 高速素因数分解
# """2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n=int(input())

count=[0]*(n+1)
for i in range(1,n+1):
    if i==1:
        pass
    else:
        soinsuu_list=factorization(i)
        for soinsu,jisu in soinsuu_list:
            count[soinsu]+=jisu
ans=1
mod=10**9+7
for i in count:
    ans*=(i+1)
    ans=ans%mod
print(ans)


Measured memory_bytes: 9364
#[test]
fn test_solve() {
    assert_eq!(solve("3 3\n.#.\n..#\n#..\n"), "10\n");
    assert_eq!(solve("2 4\n....\n....\n"), "0\n");
    assert_eq!(solve("4 3\n###\n###\n...\n###\n"), "6\n");
    assert_eq!(solve("3 3 ### ### ###"), "0\n");
    assert_eq!(solve("3 3 #.# .#. #.#"), "20\n");
    assert_eq!(solve("3 3 ### #.# ###"), "4\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let h: usize = sc.read();
    let w: usize = sc.read();
    let mas: Vec<Vec<char>> = (0..h).map(|_| sc.get().chars().collect()).collect();

    let mut vsd = vec![vec![false; w]; h];
    let mut cnt: usize = 0;
    for i in 0..h {
        for j in 0..w {
            if !vsd[i][j] {
                vsd[i][j] = true;
                let mut bct = 0;
                let mut wct = 0;
                let mut stk = vec![(i, j)];
                while let Some((i, j)) = stk.pop() {
                    let c = mas[i][j];
                    if c == '#' {
                        bct += 1;
                    } else {
                        wct += 1;
                    }
                    let mut chk = |i: usize, j: usize| {
                        if !vsd[i][j] && mas[i][j] != c {
                            vsd[i][j] = true;
                            stk.push((i, j))
                        }
                    };
                    if i > 0 {
                        chk(i - 1, j)
                    }
                    if i < h - 1 {
                        chk(i + 1, j)
                    }
                    if j > 0 {
                        chk(i, j - 1)
                    }
                    if j < w - 1 {
                        chk(i, j + 1)
                    }
                }
                cnt += bct * wct;
            }
        }
    }
    
    format!("{}\n", cnt)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    ll n,k;cin >> n >> k;
    ll ans=0;
    if(k==0){
        cout << n*n <<endl;
        return 0;
    }
    for(int i=k;i<n;i++){
        ll p=n-i;
        ans+=p;
        ll x=1;
        while(p/x>=i+1){
            ans+=p/x-i;
            x++;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool f[241514];
int main(){
	ll n,x;
	cin>>n>>x;
	if(x==1||x==2*n-1)cout<<"No\n";
	else{
		cout<<"Yes\n";
		f[x]=f[x-1]=f[x+1]=1;
		ll cnt=n-2;
		ll now=1;
		while(cnt){
			if(!f[now]){
				cout<<now<<endl;
				cnt--;
			}
			now++;
		}
		cout<<x-1<<endl<<x<<endl<<x+1<<endl;
		cnt=n-2;
		while(cnt){
			if(!f[now]){
				cout<<now<<endl;
				cnt--;
			}
			now++;
		}
	}
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <ctime>     //実行時間を測る
#define ll long long
#define vecvec(h, w, name) vector<vector<ll>> name(h, vector<ll>(w));
#define rep(init, i, n) for (ll i = init; i < (n); i++)
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end()) //昇順
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
//変数名一括置換　command+fn+f2 @vscode
using namespace std;
using vec = vector<ll>;
//function
ll facctorialMethod(ll k);     //階乗を出力する
ll modpow(ll a, ll n, ll mod); // a^n mod を計算する
ll gcd(ll a, ll b);            //最大公約数
ll lcm(ll a, ll b);            //最小公倍数
ll vecmax(vector<ll> v);       //１次元配列の最大値を返すO(NlogN)
ll vecmin(vector<ll> v);       //１次元配列の最小値を返すO(NlogN)
//

//struct
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind
{
  vector<ll> d;
  UnionFind(ll n = 0) : d(n, -1) {}
  ll find(ll x)
  { //根っこを返す
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]); //根っこの場所を貼り付ける
  }
  bool unite(ll x, ll y)
  { //くっつける操作、連結成分の情報整理 ABC177,157D参照
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y); //dはマイナスをかけたサイズだからxの方がサイズ小さいようにする
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  //find(i)でi番目の属しているグループ番号を出力
  bool same(ll x, ll y) { return find(x) == find(y); } //同じ集合に属しているかを判定
  ll size(ll x) { return -d[find(x)]; }                //あるID、xが所属するグループに所属するIDの数を得る ABC177,157D参照
};
//

/////main/////
int main()
{
  int clock_on = 0; //提出時は0!!!!!!!!!!!!!!!!!
  int time_clock = clock();
  //
  string S,T;
  cin>>S>>T;
  rep(0,i,(ll) S.size()){
   if(S.at(i)!=T.at(i)) {cout<<"No"<<endl;return 0;}
  }
cout<<"Yes"<<endl;


  //
  if (clock_on == 1)
    printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - time_clock) / CLOCKS_PER_SEC);
  return 0;
}
/////main/////

/////function/////
//階乗を出力する
ll facctorialMethod(ll k)
{
  ll sum = 1;
  for (ll i = 1; i <= k; ++i)
  {
    sum *= i;
  }
  return sum;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

//最大公約数
ll gcd(ll a, ll b)
{
  if (a % b == 0)
  {
    return b;
  }
  else
  {
    return gcd(b, a % b);
  }
}

//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}

//１次元配列の最大値を返すO(NlogN)
ll vecmax(vector<ll> v)
{
  sor(v);
  return v.at(v.size() - 1);
}

//１次元配列の最小値を返すO(NlogN)
ll vecmin(vector<ll> v)
{
  sor(v);
  return v.at(0);
}

Measured memory_bytes: 3588
import java.util.*

fun main(args: Array<String>) {
    val(n,m) = readLine()!!.split(" ").map(String::toInt)
    val a = readLine()!!.split(" ").map(String::toLong)
    val pq = PriorityQueue<Long>(n, Comparator { o1, o2 -> o2.compareTo(o1) })
    a.forEach{ i -> pq.add(i) }
    repeat (m) {
        pq.add(pq.poll()/ 2)
    }
    println(pq.sum())
}

Measured memory_bytes: 71948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

bool solve(vector<ll> A) {
    ll n = A.size();
    // ΣA[i] を求める
    ll sum = 0;
    REP(i, n) {
        sum += A[i];
    }
    // 1回の操作で取り除く個数
    ll K = n * (n+1) / 2;
    // 必要条件
    if (sum % K != 0) {
        return false;
    }
    // 合計操作回数
    ll T = sum / K;
    REP(i, n) {
        // 隣との差を埋められるか
        ll d = T + A[i] - A[(i+1)%n];
        if (d < 0 || d % n != 0) {
            return false;
        }
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // メインプログラムここから
    ll n; cin >> n;
    vector<ll> A(n);
    REP(i, n) {
        cin >> A[i];
    }
    if (solve(A)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 1792