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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



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

    vector<ll> h(n);
    rep(i,n) cin >> h[i];

    sort(h);
    ll ans = mod;

    for(int i=0;i<n-k+1;i++){
        ll mi = h[i];
        ll ma = h[i+k-1];
        ans = min(ans,ma-mi);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int x, y;
	cin >> x >> y;

	set<int> group1 = { 1,3,5,7,8,10,12 };
	set<int> group2 = { 4,6,9,11 };
	set<int> group3 = { 2 };

	if (group1.find(x) != group1.end() and group1.find(y) != group1.end()) {
		cout << "Yes" << endl;
		return 0;
	}
	if (group2.find(x) != group2.end() and group2.find(y) != group2.end()) {
		cout << "Yes" << endl;
		return 0;
	}
	if (group3.find(x) != group3.end() and group3.find(y) != group3.end()) {
		cout << "Yes" << endl;
		return 0;
	}


	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)
    power = [0] * N
    power[0] = 1
    for i in range(N - 1):
        power[i + 1] = 10 * power[i] % 13

    S = S[::-1]

    Q = []
    const = 0
    for i, c in enumerate(S):
        if c == '?':
            Q.append(i)
        else:
            const = (const + power[i] * int(c)) % 13

    dp = [0] * 13
    dp[const] = 1

    for i in range(len(Q)):
        dp, dp_prev = [0] * 13, dp
        p = power[Q[i]]
        for j in range(10):
            for k in range(13):
                idx = (p * j + k) % 13
                dp[idx] = (dp[idx] + dp_prev[k]) % MOD

    print(dp[5])
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 80368
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
typedef vector<int>		vi;
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;
lli a[1001],b[1001],n;
lli dp[1001][10001];
lli rec(lli i,lli j){
	if(j<0)return 0;
	if(i==n){
		if(j<=0)return 0;
		else return INT_MAX;
	}
	if(dp[i][j]!=-1)return dp[i][j];
	return dp[i][j]=min(rec(i,j-a[i])+b[i],min(rec(i+1,j),b[i]+rec(i+1,j-a[i])));
}

int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    
    lli h;
    cin>>h>>n;
    for(lli i=0;i<n;i++)cin>>a[i]>>b[i];
    for(lli i=0;i<=1000;i++)for(lli j=0;j<=10000;j++)dp[i][j]=-1;
    cout<<rec(0,h);

    /*
    lli h,n;
    lli maxi=INT_MAX;
    cin>>h>>n;
    lli a[n],b[n];
    for(lli i=0;i<n;i++)cin>>a[i]>>b[i];
    lli dp[h+1][n+1];
	for(lli i=0;i<=h;i++)for(lli j=0;j<=n;j++)dp[i][j]=maxi;
	for(lli i=1;i*a[0]<=h;i++)
	dp[i*a[0]][0]=i*b[0];
	
	for(lli i=0;i<n-1;i++){
		for(lli j=0;j<=h;j++){
			dp[j+1][j]=min(dp[i+1][j],dp[i][j]);
			if(j+a[i+1]<=h)dp[i+1][j+a[i+1]]=min(dp[i+1][j+a[i+1]],dp[i][j]+b[i+1]);
			else
			dp[i+1][h]=min(dp[i+1][h],dp[i][j]+b[i+1]);
		}
	}
	for(lli i=0;i<n;i++){
		for(lli j=0;j<=h;j++)cout<<dp[j][i]<<" ";
			cout<<endl;
	}	
*/

}

Measured memory_bytes: 78976
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N,M,X;
    cin>>N>>M>>X;
    vector<int> A(M);
    REP(i,M) cin>>A[i];
    int Left = 0;
    int Right = 0;
    REP(i,M){
        if(A[i]<X) Left ++;
        else Right ++;
    }
    cout<<min(Left,Right)<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
  int apart[4][3][10] = {0};
  int b, f, r, v;//?£??????????
  int n;
  int i, j, x;

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    apart[b-1][f-1][r-1] += v;
  }

  for(i = 0; i < 4; i++){ //?£??????????
    for(j =0; j < 3; j++){
      for(x = 0; x < 10; x++){
	cout << ' ' << apart[i][j][x];
      }
      cout << '\n';
    }
    if(i == 3) break;
    cout << "####################\n";
  }
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> food(m);
    int a,k;
    for (int i = 0;i < n;i++){
        cin >> k;
        for (int j = 0;j < k;j++){
            cin >> a;
            food.at(a-1) += 1;
        }
    }
    int ans = 0;

    for (int i = 0;i < m;i++){
        if (food.at(i) == n){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
  int a,b,i,n,j,k,ret,x;
  cin >> n;
  if(n<105){
    cout << 0 << endl;
    return 0;
  }else{
    ret = 1;
    for(i=107;i<=n;i+=2){
      j=i,k=0,a=1;
      x=3;
      //cout << j << endl;
      while(j!=1){
        k=1;
        while(j%x==0){
          j/=x;
          k++;
        }
        //cout << j << endl;
        a*=k;
        x+=2;
      }
      if(a==8)ret++;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
n,a,b=[int(i) for i in input().split()]

mod=10**9+7 
def nCr(n, r, mod=10**9+7):#mod=10**9+7
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def modpow(a,n,mod=10**9+7):
    res=1
    while(n>0):
        if (n&1):
            res = res*a%mod
        a = a*a%mod
        n>>=1
    return res


ans = (modpow(2,n)-nCr(n,a)-nCr(n,b)-1)%mod
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using ULL = int64_t;
const LL LLHUGE = numeric_limits<LL>::max() / 5; // for int64_t: 1.8 * 10^18
using P = pair<LL, LL>;
#define rep(i, n) for (LL i = 0; i < (n); ++i)
#define all(v) (v).begin(), (v).end()
//#define DEBUG

template <typename V>
void print_all(const V& v) {
  for (const auto e: v) {
    cout << e << "\t";
  }
  cout << endl;
}

int main() {
  ULL A;
  string bstr;
  cin >> A >> bstr;
  //ULL b100 = B * 100ull;
  
  string bstrint = "";
  for (auto e: bstr) {
    if (e != '.') {
      bstrint += e;
    }
  }
  ULL b100 = (ULL)stol(bstrint);

  cout << (A * b100) / 100ull << endl;
  

  #ifdef DEBUG
  cout << A << endl;
  cout << bstr << endl;
  cout << bstrint << endl;
  // cout << 123 << endl;
  #endif
}



Measured memory_bytes: 3624
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

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

        std::vector<std::vector<P>> s(n);
        rep(i, 0, m){
                int p, y;
                scanf("%d %d", &p, &y);
                s[p-1].emplace_back(y, i);
        }

        rep(i, 0, n) std::sort(be(s[i]), [](P x, P y){return x.fi < y.fi;});
        std::vector<V> ans;
        rep(i, 0, n){
                rep(j, 0, s[i].size()){
                         ans.push_back({i, j, s[i][j].se});
                }
        }
        std::sort(be(ans), [](V x, V y){return x[2] < y[2];});
        for(V vec: ans){
                printf("%06ld%06ld\n", vec[0]+1, vec[1]+1);
        }
        return 0;
}

Measured memory_bytes: 12720
#include<bits/stdc++.h>
using namespace std;
vector<int> fsize(0);
struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for(int i = 0; i < N; i++) par.at(i) = i, fsize.push_back(0);
  }
  int root(int x) {
    if(x == par.at(x)) return x;
    return par.at(x) = root(par.at(x));
  }
  void unite(int x, int y) {
    x = root(x), y = root(y);
    if(x == y) return;
    par.at(x) = y;
  }
  bool same(int x, int y) {
    x = root(x), y = root(y);
    return x == y;
  }
  void fsizeset(int x) {
    x = root(x);
    fsize.at(x)++;
  }
};

int main() {
  int N, M, K; cin >> N >> M >> K;
  UnionFind tree(N);
  vector<int> fp(N, 0);
  vector<vector<int>> forb(N, vector<int> (0));
  for(int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    fp.at(a)--; fp.at(b)--;
    tree.unite(a, b);
  }
  for(int i = 0; i < N; i++) {
    tree.fsizeset(i);
  }
  for(int i = 0; i < K; i++) {
    int c, d; cin >> c >> d; c--; d--;
    if(tree.same(c, d)) fp.at(c)--, fp.at(d)--;
  }
  for(int i = 0; i < N; i++) {
    cout << fp.at(i) + fsize.at(tree.root(i)) - 1 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int diff = 1<<30;
  for(int i = 0; i <= s.size() - 3; i++){
    int v = (s[i] - '0') * 100 + (s[i + 1] - '0')*10 + s[i + 2] - '0';
	diff = min(diff, abs(v - 753));
  }
  cout << diff << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
TList = list(map(int,input().split()))
Sum = sum(TList)

M = int(input())
Data = []
for _ in range(M):
    p,x = map(int,input().split())
    Data.append([p,x])

for i in range(M):
    problem = Data[i][0]
    diff = - TList[problem-1] + Data[i][1]
    print( Sum + diff)

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

# define FOR(i,a,b) for (int i=(a);i<(b);i++)
# define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
# define REP(i, n) for (int i = 0; i < (int)(n); i++)
# define RREP(i,n) for (int i=(n)-1;i>=0;i--)

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}

#define COLOR 8

int main() {
  int(n);
  vint(A,n);

  int cnt = 0;
  int B[COLOR] = {};

  REP(i,n){
    if (A[i] >= 3200){
      cnt++;
    }else{
      B[A[i]/400] = 1;
    }
  }
  int i_min = 0;
  int i_max = 0;
  REP(i,COLOR){
    if(B[i] == 1){
      i_min++;
    }
  }
  
  i_max = i_min;
  /*
  if(i_max < 8 && i_max+cnt <= 8)
    i_max += cnt;
  else
    i_max =8;
  */
  cout << max(i_min,1) << " " << i_max+cnt << endl;

}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
総投票数 = sum(a)
x = 総投票数 / (4 * m)
for i in range(m):
    if a[i] < x:
        flag = 0
        break
else:
    flag = 1
print(["No", "Yes"][flag])

Measured memory_bytes: 9016
#include<stdio.h>
#include<string.h>
int main(){
  char w[101];
  scanf("%s",w);
  int alpha[27],i;
  for(i=0;i<26;i++)
    alpha[i]=0;
  for(i=0;i<strlen(w);i++)
    alpha[w[i]-'a']++;
  for(i=0;i<26;i++)
    if(alpha[i]%2==1){
      puts("No");
      return 0;
    }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 1656
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int N,M,Q;

vector<vector<long long int> >A(550,vector<long long int>(550,0));

int main(void){
 int N,M,Q;
 int L,R;
 cin>>N>>M>>Q;

 for(int i=0; i<M; i++){
  cin>>L>>R;
  A[R][L]++;
 }
 
 //buildSumTable;
 for(int i=1; i<=N; i++)
  for(int j=1; j<=N; j++){
   A[i][j]+=A[i][j-1];
   A[i][j]+=A[i-1][j];
   A[i][j]-=A[i-1][j-1];
  }
  
  for(int i=0; i<Q; i++){
   cin>>L>>R;
   std::cout<<A[R][R]-A[R][L-1]-A[L-1][R]+A[L-1][L-1]<<std::endl;
  }
 return 0;
}

Measured memory_bytes: 3328
n=int(input())
s=list(input())	
s2 = s[:]

l=[0]
cnt1=0
for i in range(len(s)):
    if(s[i] == "#"):
        cnt1 +=1
    l.append(cnt1)
ansl=[]
for i in range(len(l)):
    ansl.append(n-i-cnt1+2*l[i])



print(min(ansl))

Measured memory_bytes: 22332
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf LLONG_MAX/10000000
#define INF LLONG_MAX/3
#define P pair<int,int>
#define EPS DBL_EPSILON
using namespace std;
int n,m;
string s,t;
int gcd(int a,int b){
	while(max(a,b)%min(a,b)){
		if(a<b)b%=a;
		else a%=b;
	}
	return min(a,b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
signed main(){
	cin>>n>>m>>s>>t;
	int l=lcm(n,m);
	for(int i=0;i<l;i+=l/n){
		if(i%(l/m)==0){
			if(s[i/(l/n)]!=t[i/(l/m)]){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	cout<<lcm(n,m)<<endl;
	return 0;
}

Measured memory_bytes: 512
import sys

def main():
    h = int(input().replace('\n','').split()[0])
    cnt=0
    res=0
    while(h>=1):
        h= h/2
        cnt+=1
    for i in range(cnt):
        res+=2**i
    print(res)
if __name__ == '__main__':
    input = sys.stdin.readline
    main()


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

bool f(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != s[s.size() - i - 1]) {
      return false;
    }
    return true;
  }
}

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

  int n = s.size();

  string s1 = s.substr(0, n / 2);
  string s2 = s.substr(n / 2 + 1, n / 2);

  if (s1 != s2) {
    cout << "No" << endl;
    return 0;
  }

  int m = n / 2;

  if (f(s1)) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;

        for(int i  = 1;i<=n;i++){
            if(String.valueOf(i).length()%2==1){
                cnt++;
               // System.out.println(i);
            }
        }
        System.out.println(cnt);


    }
}


Measured memory_bytes: 27732
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int H, W;
    std::cin >> H >> W;

    std::vector<std::string> b(H); 
    for (int i = 0; i < H; i++) {
        std::cin >> b[i];
        if (b[i].find('#') == std::string::npos) {
            b[i] = std::string(W, '*');
        }
    }

    for (int i = 0; i < W; i++) {
        bool del = true;
        for (int j = 0; j < H; j++) {
           if (b[j][i] == '#') {
               del = false;
               break;
           } 
        }

        if (del) {
            for (int j = 0; j < H; j++) {
                b[j][i] = '*';
            }   
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (b[i][j] != '*') {
                std::cout << b[i][j];
            }
        }
        std::cout << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int i,n,x;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    x=i;
    if(i%3==0){
      printf(" %d",i);
      continue;
    }
    while(x!=0){
      if(x%10==3){
	printf(" %d",i);
	break;
      }
      x=x/10;
    }
  }
  printf("\n");
  return 0;
} 

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;

    // 1st
    rep(i,dy) cout << 'U';
    rep(i,dx) cout << 'R';

    // 2nd
    rep(i,dy) cout << 'D';
    rep(i,dx) cout << 'L';

    // 3rd
    cout << 'L';
    rep(i,dy+1) cout << 'U';
    rep(i,dx+1) cout << 'R';
    cout << 'D';

    // 4th
    cout << 'R';
    rep(i,dy+1) cout << 'D';
    rep(i,dx+1) cout << 'L';
    cout << 'U';

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,k,n) for(int i=k;i<=n;++i)

int main(){
    int k,a,b;
    std::cin >> k >> a >> b;
    std::string s="NG";
    rep(i,a,b){
        if(i%k==0){
            s="OK";
            break;
        }
    }
    std::cout << s << std::endl;
    return 0;
}

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

using i64 = int64_t;

int main() {
  int n;
  i64 x;
  cin >> n >> x;
  vector<i64> a(n);
  for (i64& x : a) cin >> x;
  vector<i64> b(a);
  b[0] = min(b[0], x);
  for (int i = 1; i < n; i++) {
    b[i] = min(x - b[i - 1], b[i]);
  }
  i64 ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i] - b[i];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 4824
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int ans=0,n,k,a;
	cin>>n>>k;
	for (int i=1;i<=n;i++){
		cin>>a;
		ans+=2*min(a-0,k-a);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e10
#define mod 1000000007
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
#define lcm(x,y)  (x*y)/__gcd(x,y)
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int  fact(int n)
{
	if (n == 0 || n == 1)
		return 1;
	else
		return n * fact(n - 1);
}
int nCr(int n, int r)
{
	if (r == 0)
		return 1;
	else
		return fact(n) / (fact(n - r) * fact(r));
}
int floorRoot5(int n)
{
	// Base cases
	if (n == 0 || n == 1)
		return n;

	// Initialize result
	int res = 0;

	// Keep incrementing res while res^5 is
	// smaller than or equal to n
	while (res * res * res * res * res <= n)
		res++;

	// Return floor of 5'th root
	return res - 1;
}

int32_t main()
{
	//c_p_c();
	int a, b, c;
	cin >> a >> b >> c;
	int temp = b / a;
	if (temp >= c) cout << c;
	else cout << temp;

}



Measured memory_bytes: 256
n = int(input())

_list = []
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    _list.append([a, b, c])


for i in range(n - 1):
    num = i
    time = 0

    while num < n - 1:
        c, s, f = _list[num]

        if num == i:
            time += s + c
            num += 1
            continue

        while True:
            wait = s - time

            if wait >= 0:
                time += wait + c
                break

            test = (wait * -1) // f
            s += int(f * test)

            if s - time < 0:
                s += f

        num += 1

    print(time)


print(0)


Measured memory_bytes: 3188
#include<iostream>

using namespace std;

// 1?100までの整数データのみであるため、
// 配列に出現回数を記録してもっとも多いものを
// 出力する。

int main() {
	// データは1から100であるが、
	// インデックスでも1から100値をそのまま使用できるほうが
	// コードが煩雑にならないため、配列サイズを101にする。
	int a[101] = {};
	int n;
	while (cin >> n) {
		++a[n];
	}

	// 出現回数の最大値を求める。
	int max = 0;
	for (int i = 1; i <= 100; ++i) {
		if (max < a[i]) {
			max = a[i];
		}
	}

	// 出現回数が最大値と同じ値を出力する。
	for (int i = 1; i <= 100; ++i) {
		if (max == a[i]) {
			cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import math, cmath
 
def koch(v1, v2, n):
    if n == 0:
        return [v1, v2]
     
    rad60 = math.pi/3
    u1 = (v2 - v1)/3
    u2 = cmath.rect(abs(u1), cmath.phase(u1)+rad60)
    q1 = v1 + u1
    q2 = q1 + u2
    q3 = q1 + u1
    if n == 1:
        return [v1,q1,q2,q3,v2]
    else:
        x1 = koch(v1,q1,n-1)[:-1]
        x2 = koch(q1,q2,n-1)[:-1]
        x3 = koch(q2,q3,n-1)[:-1]
        x4 = koch(q3,v2,n-1)
        x = x1 + x2 + x3 + x4
    return x
 
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
 
for e in koch(p1,p2,n):
    print e.real,e.imag

Measured memory_bytes: 7056
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <array>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <map>
#include <utility>
using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while (1)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes";
            return 0;
        }
        a -= d;
        if (a <= 0)
        {
            cout << "No";
            return 0;
        }
    }
}

Measured memory_bytes: 3564
#include <iostream>
#define inf 1000000000

using namespace std;

int w, h;
int map[25][25];
int sx, sy, gx, gy;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int dfs(int map[25][25], int px, int py, int rem)
{
  if(px == gx && py == gy) return 0;
  if(rem == 0) return inf;
  int ret = inf;
  for(int d = 0; d < 4; d++){
    int map2[25][25];
    for(int x = 1; x <= w; x++){
      for(int y = 1; y <= h; y++){
        map2[x][y] = map[x][y];
      }
    }
    int x = px, y = py, nx, ny;
    while(1){
      nx = x + dx[d], ny = y + dy[d];
      if(nx <= 0 || nx > w || ny <= 0 || ny > h) break;
      if(nx == gx && ny == gy) return 1;
      if(map2[nx][ny] == 1){
        if(x == px && y == py) break;
        map2[nx][ny] = 0;
        ret = min(ret, dfs(map2, x, y, rem-1));
        break;
      }
      x = nx, y = ny;
    }
  }
  return ret + 1;
}

int main(void)
{
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0) break;

    for(int y = 1; y <= h; y++){
      for(int x = 1; x <= w; x++){
        cin >> map[x][y];
        if(map[x][y] == 2){
          sx = x, sy = y;
          map[x][y] = 0;
        }
        if(map[x][y] == 3){
          gx = x, gy = y;
          map[x][y] = 0;
        }
      }
    }

    int ans = dfs(map, sx, sy, 10);
    if(ans >= inf) ans = -1;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3108
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    H, W, K = iim()
    S  = [sys.stdin.readline().rstrip() for i in  range(H)]
    B = [1<<i for i in range(max(H,W))]

    k = "#"

    ans = 0
    for i in range(1<< H):
        for j in range(1 << W):
            x = 0
            for h in range(H):
                if i & B[h]: continue
                for w in range(W):
                    if j & B[w]: continue
                    if S[h][w] == k:
                        x += 1

            if x == K:
                ans += 1
    print(ans)





if __name__ == "__main__":
    resolve()


Measured memory_bytes: 74016
n,k  = map(int,input().split())
cnt = 0
m = 10**9+7
a = [o for o in range(n+1)]
b = sorted(a,reverse = True)
for i in range(k,n+2):
    t = int((n*(n+1))/2-((i-1)*i)/2+1)
    if i < n:
        t -= int(((n-i)*(n-i+1))/2)
    cnt += t
print(cnt%m)

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#define dprintf(...) printf(__VA_ARGS__)
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#define dprintf(...)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

template <class T>
vec2<T> vec2_init(int n0, int n1, T x = 0) {
    return vec2<T>(n0, vector<T>(n1, x));
}

template <class T>
vec3<T> vec3_init(int n0, int n1, int n2, T x = 0) {
    return vec3<T>(n0, vec2_init(n1, n2, x));
}

/*
 *           U P
 *           - x
 *            ^
 *            |
 * LEFT -y <--+--> +y RIGHT
 *            |
 *            v
 *           + x
 *         D O W N
 */

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

enum {
    DOWN,
    RIGHT,
    UP,
    LEFT,
};

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

    string S, T;
    cin >> S >> T;

    int N = S.size();
    int M = T.size();

    int result = N;
    REP(i, N - M + 1) {
        int cnt = 0;
        REP(j, M) {
            if (S[i + j] != T[j]) {
                ++cnt;
            }
        }
        amin(result, cnt);
    }
    cout << result << endl;
    return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    for(int i=0;i<m;i++)cin>>a[i];
    int sum=0;
    for(auto it:a)sum+=it;
    cout<<max(n-sum,-1)<<endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define MAX_N (10010)

static ll gcd(ll a, ll b)
{
	ll temp;

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

	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

static ll lcm(ll a, ll b)
{
	ll temp, _gcd;

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

	_gcd = gcd(a, b);

	ll sho_a = a / _gcd;
	ll sho_b = b / _gcd;
	return sho_a * sho_b * _gcd;
}
int main()
{
	int A, B;
	scanf("%d%d", &A, &B);
	printf("%lld\n", lcm(A, B));

	return 0;
}


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

way=[]

for i in range(n):
    way.append(list(map(int,input().split())))

city=[]
for j in range(1,m+1):
    city.append(j)

#print(way)
#print(city)

for k in city:
    cnt=0
    for l in way:
        for m in range(len(l)):
            if k==l[m]:
                cnt+=1
    print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main() {
    string O, E;
    cin >> O >> E;
    for (int i = 0; i < E.length(); i++) cout << O[i] << E[i];
    if (O.length() - E.length()) cout << O.back();
    cout << endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli k;
	cin>>k;

	vector<lli> d;

	/*init*/
	for(lli i=0;i<50;i++){
		lli num = i + k/50;
		d.push_back(num);
	}

	/*left action*/
	lli left = k%50;
	for(lli i=0;i<left;i++){
		for(lli j=0;j<50;j++){
			if(i==j)d[j]+=50;
			else d[j]--;
		}
	}

	cout<<50<<endl;
	REP(i,0,50){
		cout<<d[i]<<" ";
	}
	cout<<endl;

	return 0;
}

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

int main() {
  int n,b = 0,r = 0;
  string s;
  cin >> n >> s;
  rep(i,n){
    if(s[i] == 'B') b++;
    else r++;
  }
  if(b < r) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define forp(i,n) for(int i=n;i>0;i--)
#define fort(i,n) for(int i=n;i>=0;i--)
#define forn2(i,a,n) for(int i=a;i<n;i++)
#define fore2(i,a,n) for(int i=a;i<=n;i++)
#define forp2(i,a,n) for(int i=n;i>a;i--)
#define fort2(i,a,n) for(int i=n;i>=a;i--)
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	int x;
	cin>>x;
	cout<<(x+1)%2<<endl;
	return 0;
}

Measured memory_bytes: 3644
a,b=map(int,input().split())
ans=a
for i in range(a):
   x=i*b
   a2=a-i
   if a2*b%2==0:
     y=a2*b//2
   else:
     y=min(a2*(b+1)//2,(a2+1)*b//2)
   z=a2*b-y
   diff=max(x,y,z)-min(x,y,z)
   ans=min(ans,diff)
for i in range(b):
   x=i*a
   b2=b-i
   if b2*a%2==0:
     y=b2*a//2
   else:
     y=min(b2*(a+1)//2,(b2+1)*a//2)
   z=b2*a-y
   diff=max(x,y,z)-min(x,y,z)
   ans=min(ans,diff)
print(ans)

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

namespace ndifix{

}

int main(){
    int n;cin>>n;
    vector<int> h(n),acc(n);
    for(int i=0;i<n;i++)cin>>h[i];
    acc[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)acc[i]=min(acc[i-1]+abs(h[i]-h[i-1]), acc[i-2]+abs(h[i]-h[i-2]));

    cout<<acc[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 1024
H,W = gets.split.map(&:to_i)
org_map = []
H.times do |row|
  org_map << gets.split("")
end

max_len = 0

H.times do |i|
  W.times do |j|
    cur_map = Marshal.load(Marshal.dump(org_map))
    if cur_map[i][j] == '#'
      next
    end
    q = []
    q << {cy:i,cx:j}
    cur_map[i][j] = 0

    proc = Proc.new do |cy,cx,len|
      if org_map[cy][cx] == '.'
        cur_map[cy][cx] = len
        q << {cy: cy, cx:cx}
      end
    end

    while q.empty? != true
      pos = q.shift
      cx = pos[:cx]
      cy = pos[:cy]
      len = cur_map[cy][cx]
      #puts "cx:#{cx},cy:#{cy},len:#{len}"

      len += 1
      # 左
      if 0 < cx && cur_map[cy][cx-1] == '.'
        proc.call(cy, cx-1, len)
      end
    
      # 上
      if 0 < cy && cur_map[cy-1][cx] == '.'
        proc.call(cy-1, cx, len)
      end
    
      # 右
      if cx < W-1 && cur_map[cy][cx+1] == '.'
        proc.call(cy, cx+1, len)
      end
      # 下
      if cy < H-1 && cur_map[cy+1][cx] == '.'
        proc.call(cy+1, cx, len)
      end
    end
    H.times do |i|
      W.times do |j|
        if cur_map[i][j] != '#'
          max_len = cur_map[i][j] if max_len < cur_map[i][j]
        end
      end
    end
  end
end
puts max_len


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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int dp[2011][2021];

signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<ll, ll> P;
bool vis[400][400];
string S[400];
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
int H, W;
P dfs(int x, int y) {
	vis[y][x] = 1;
	P ret(0, 0);
	if (S[y][x] == '#') ret.first++;
	else ret.second++;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (0 > nx || nx >= W || 0 > ny || ny >= H || vis[ny][nx]) continue;
		if (S[y][x] == S[ny][nx]) continue;
		P p = dfs(nx, ny);
		ret.first += p.first;
		ret.second += p.second;
	}
	return ret;
}
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	ll ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (vis[i][j]) continue;
			P p = dfs(j, i);
			ans += p.first*p.second;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

#define fast_io ios::sync_with_stdio(false); cin.tie(NULL);

int main()
{
	fast_io;
	
	int n,k;
	cin >> n >> k;

	int array[n];
	int indexOne;
	for (int i = 0; i < n; ++i)
	{
		cin >> array[i];
		if (array[i] == 1)
			indexOne = i;
	}

	int answer = 0;
	int remainder = 0;
	answer += (indexOne/(k-1));
	if (indexOne%(k-1)) remainder += (indexOne%(k-1));

	answer += (n - indexOne-1)/(k-1);
	if ((n-indexOne-1)%(k-1)) remainder += ((n-indexOne-1)%(k-1));

	answer += remainder/k;
	remainder %= k;
	if (remainder) answer++;

	cout << answer << endl;
	
	return 0;
}


Measured memory_bytes: 640
H,W = list(map(int,input().split()))

coin=[[0]*(W+2)]
for h in range(H):
    c=[0]
    c.extend(list(map(int,input().split())))
    c.append(0)
    coin.append(c)
coin.append([0]*(W+2))
    
position=[]
for h in range(1,H+1):
    W_list=list(range(1,W+1))
    if h % 2 == 0:
        W_list.reverse()
    for w in W_list:
        position.append([h,w])
        
ans=[]
for p1,p2 in zip(position[:-1],position[1:]):
    if coin[p1[0]][p1[1]] % 2 != 0:
        coin[p1[0]][p1[1]] -= 1
        coin[p2[0]][p2[1]] += 1
        ans.append([p1[0],p1[1],p2[0],p2[1]])
        
print(len(ans))
for a in ans:
    print(' '.join(map(str,a)))

Measured memory_bytes: 124988
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(){

    string S;
    long long K;
    cin >> S;
    cin >> K;

    long long first;
    for(long long i = 0; i < S.length(); i++){
        if(S[i] != '1'){
            first = i;
            break;
        }
    }

    if(K <= first){
        cout << "1" << endl;
    }
    else{
        cout << S[first] << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    for(int i=L; i<=R; i++) {
        if(i%d == 0) ++ans;
    }

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


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;

#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--)

string alph = "abcdefghijklmnopqrstuvwxyz";
string s;

int main() {
  cin >> s;
  rep(i, alph.length()) {
    bool exists = false;
    rep(j, s.length()) {
      if (s[j] == alph[i]) {
        exists = true;
        break;
      }
    }
    if (!exists) {
      printf("%c\n", alph[i]);
      return 0;
    }
  }
  printf("None\n");
}


Measured memory_bytes: 512
//                                ** ALLAH **
//                        who is Hussain? -> whoishussain.org

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define int long long 
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1000000007;
const int N = 5e5 + 1000;
int a[N], sz, b, ans, h, last, is9 = 1;
int32_t main(){ 
        char c;
        while( scanf(" %c", &c) == 1 )   a[sz++] = c-'0';     

        reverse(a,a+sz);
        int i, c10 = 1; 
        for(i = 0;a[i]||b||i<sz;i++, c10*=10){
                int cc = (a[i] * 9 + b) / 10;
                a[i] = (a[i] * 9 + b) % 10;
                if( i <= 10 ) 
                        h = h + (9-a[i])*c10;
                else{
                        if( a[i] != 9 ) is9 = 0;
                        if( is9 ) last = i;
                }
                b = cc;
        }
        b = -1; 
        for(int j = i; j > 10; j--) {if( j <= last && ans >= h ) {b = ans-h;ans++; break;}  ans += a[j];} 
        
        if( b == -1 ){ 
                b = 0; 
                for(int i = 10;i >= 0; i--)
                        b = 1ll * b * 10 + a[i];
                b += ans;
        }
        int g = 9999999999;
        for(int i = 0; i < 10; i++){
               ans += b/g; 
               b%=g;
               g/=10;
        }
        cout << (int)ceil(1.0*ans / 9) << endl;


}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, r;
	cin >> a >> b;
	if (a > b){
		a--;
	}
	cout << a << "\n";	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
int main()
{
	char s[4]; 
	cin>>s;
	if(s[1]=='B') printf("ARC");
	else printf("ABC");
	return 0;
} 

Measured memory_bytes: 3684
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll; 
#define me(a,b) memset(a,b,sizeof(a))
char s[300];
int main()
{
	int a[4];
	for(int i=0;i<3;i++)
	cin>>a[i];
	sort(a,a+3);
	int sum=0;
	if(a[0]==a[1])sum++;
	if(a[1]==a[2])sum++;
	if(sum==1)cout<<"Yes";
	else cout<<"No";
	return 0;
	
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    rep(i, N) cin >> x[i];
    ll ans = 0;
    rep(i, N) {
        ans += min(x[i], (int)abs(x[i]-K))*2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
#endif
inline void Compile(R char *s){
	char com[111];
	sprintf(com,"g++ %s.cpp -lm -o %s",s,s);
	system(com);
}
inline void setfile(R char *s){
	char inname[111],outname[111];
	sprintf(inname,"%s.in",s);
	sprintf(outname,"%s.out",s);
	freopen(inname,"r",stdin);
	freopen(outname,"w",stdout);
}
#ifdef __DEBUG__
	#define setfile(__a) (1)
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	const int maxn = 100;
	int c[maxn],t[maxn],n,T;
	int ans=919260817;
	int main(){
		read(n);read(T);
		for(R int i=1;i<=n;++i){
			read(c[i]);
			read(t[i]);
		}
		for(R int i=1;i<=n;++i){
			if(t[i]<=T){
				cmin(ans,c[i]);
			}
		}
		if(ans<919260817){
			cout<<ans<<endl;
		}else puts("TLE");
		return 0;
	}
}
int main(){
	return Night::main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++) a[i] -= (i+1);
	sort(a.begin(),a.end());
	
	long long ans = 0;
	if(n %2 == 0){
		long long m1 = a[(n-1)/2];
		long long m2 = a[(n+1)/2];
		long long a1 = 0;
		long long a2 = 0;
		for(int i = 0;i < n;i++){
			a1 += abs(a[i] - m1);
			a2 += abs(a[i] - m2);
		}
		cout << min(a1,a2) << endl;
	}else{
		long long mo = a[(n-1)/2];
		long long ans = 0;
		for(int i = 0;i < n;i++) ans += abs(a[i] - mo);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>

int main(){
  int m;
  scanf( "%d", &m );
  for( int i = 0; i < m; i++ ) {
    int ini_fund;
    int y, n;
    int max_fund = 0;
    scanf( "%d%d%d", &ini_fund, &y, &n );
    for( int j = 0; j < n; j++ ) {
      int type;
      int a, b, cost;
      int sum = 0;
      double alpha;
      scanf( "%d%lf%d", &type, &alpha, &cost );
      a = ini_fund;
      for( int k = 0; k < y; k++ ){
        b = ( int )( a * alpha );
        if( type ) {
          a = a + b - cost;
        }else{
          sum += b;
          a -= cost;
        }
      }
      if( !type ){ a += sum; }
      max_fund = a > max_fund ? a : max_fund;
    }
    printf( "%d\n", max_fund );
  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1060