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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

struct UnionFind{
    vector<ll> par;
    vector<ll> rank;

    UnionFind(ll N):par(N),rank(N){
        for(int i = 0;i < N;i++){
          par[i] = i;
          rank[i] = 0;
        }
    }

    ll root(ll x){
       while(x != par[x]){
        x =  par[x] = par[par[x]];
       }
       return x;
    }

    void unite(ll x,ll y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry)return;
        if(rank[x] > rank[y]){
          par[y] = rx;
        }
        if(rank[x] < rank[y]){
          par[rx] = ry;
        }else{
          par[ry] = rx;
          if(rank[x] == rank[y]){
            rank[rx]++;
          }
        }
    }

    bool same(ll x,ll y){
      return root(x) == root(y);
    }
};


int main(){
    ll N,M;cin >> N >> M;
    vector<ll> ans(M+1);
    ans[M] = N * (N-1) / 2;
    vector<pair<ll,ll>> B(M);
    for(int i = 0;i < M;i++){
        cin >> B[i].first >> B[i].second;
    }
    UnionFind IS(N);
    vector<ll> cnt(N,0);
    for(int i = M-1;i >= 0;i--){
        int a = B[i].first,b = B[i].second;
        a--;b--;
        ll A = 0,B = 0;
        /*for(int j = 0;j < N;j++){
          cout << cnt[j] <<  ' ';
        }
        cout << endl;*/
        if(!IS.same(a,b)){
          A += cnt[IS.root(b)] + 1;
          B += cnt[IS.root(a)] + 1;
          ll c = cnt[IS.root(a)];
          cnt[IS.root(a)] += cnt[IS.root(b)] + 1;
          cnt[IS.root(b)] += c + 1;        
        }
        ans[i] = ans[i+1] - A * B;
        //cout << A << ' ' << B << ' ' <<  ans[i] <<  endl;
        IS.unite(a,b);
        //cout << i << endl;
    }
    for(int i = 1;i <= M;i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 6016
def prime(X):
    if X<2:
        return False
    if X==2:
        True
    for i in range(2,X):
        if X%i==0:
            return False
    return True
X=int(input())
p=False
while p==False:
    p=prime(X)
    X+=1
print(X-1)
            
    

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while(true)
		{
			String word=input.nextLine();
			if(word.equals("-"))
				break;
			int wrapTime=input.nextInt();
			for(int i=0;i<wrapTime;i++)
			{
				int index=input.nextInt();
				String move=word.substring(0,index);
				String left=word.substring(index);
				word=left+move;
				
			}
			input.nextLine();
			System.out.println(word);
		}
	}

}



Measured memory_bytes: 26760
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  ll sumA = 0, sumB = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    sumA += w[i];
  }
  ll ans = 1e9;
  ans = min(ans, abs(sumA - sumB));
  for (int i = 0; i < n; i++) {
    ans = min(ans, abs(sumA - sumB));
    sumA -= w[i];
    sumB += w[i];
  }
  ans = min(ans, abs(sumA - sumB));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

class BIT { // index starts at 1.
public:
  int N;
  ll* data;

  BIT(int n) : N(n) {
    data = new ll[N+1];
  }

  ~BIT() {
    delete[] data;
  }

  ll sum(int i) { // [1, i]
    ll s = 0;
    while (i > 0) {
      s += data[i];
      i -= i & -i;
    }
    return s;
  }

  ll sum(int a, int b) { // [a, b)
    return sum(b - 1) - sum(a - 1);
  }

  void add(int i, int x) {
    while (i <= N) {
      data[i] += x;
      i += i & -i;
    }
  }
  
};

int main () {
  int n, q;
  cin >> n >> q;
  BIT bit(n);
  for (auto i = 0; i < q; ++i) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      bit.add(x, y);
    } else {
      cout << bit.sum(x, y+1) << endl;
    }
  }
}

Measured memory_bytes: 3752
n = input()
A = list(map(int, input().split()))
print(*A)
for i in range(1, len(A)):
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    print(*A)



Measured memory_bytes: 5980
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long ans = 1;
    int n = sc.nextInt();

    for (int i = 0; i < n; i++) {
      long next = sc.nextLong();

      if (ans != -1) {
        if (1000000000000000000L / next < ans) {
          ans = -1;
        } else {
          ans *= next;
        }
      } else {
        if (next == 0) {
          ans = 0;
          break;
        }
      }
    }

    System.out.println(ans);
  }
}


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

int c[26];

int main(){
int n;
cin >> n;
for(int i = 0; i < n; i++) {
  char s;
  cin >> s;
  c[s - 'A']++;
}
int ans = 0;
for(int i = 0; i < 26; i++) {
  if(c[i])ans++;
}
if(ans == 3) cout << "Three" << endl;
else cout << "Four" << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()

l = len(S)
if l % 2 == 0:
    res = 0
    h = l // 2
    p = S[:h]
    q = S[h:]
    for i in range(h):
        if not p[i] == q[(i + 1) * -1]:
            res += 1
    print(res)
else:
    res = 0
    h = l // 2
    p = S[:h]
    q = S[h+1:]
    for i in range(h):
        if not p[i] == q[(i + 1) * -1]:
            res += 1
    print(res)


Measured memory_bytes: 38492
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v) {os << " [" << i++ << "]" << x; if (i % 10 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp) {os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N = 4;
  std::string vc;
  for (ll i = 0; i < N; i++) {
    char c;
    std::cin >> c;
    vc += c;
  }

  std::sort(vc.begin(), vc.end());

  bool judge = (vc == "1479");
  if (judge) print("YES");
  else print("NO");

  return 0;
}



Measured memory_bytes: 256
/*
  GOOD is not Enough
  You've got to be GREAT.
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve()
{
  int n;
  cin >> n;
  int a[n+1],b[n+1];
  fp(i,1,n)
    cin >> a[i] >> b[i];
  sort(a+1,a+n+1);
  sort(b+1,b+n+1);
  if(n&1)
  {
    cout << (b[(n+1)/2]-a[(n+1)/2]+1) << '\n';
  }
  else
  {
    cout << (b[n/2]-a[n/2]+1)+(b[(n/2) +1]-a[(n/2) +1]) << '\n';
  }

  return;
} 

signed main()
{
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    ll k;
    cin >> s;
    cin >> k;
    for(ll i=0;i<min(k,(ll)s.size());i++){
        char ans = (char)s[i];
        if(s[i]!='1'){cout << ans << endl;return 0;}
    }
    cout << 1 << endl;
    return 0;
}

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



int main(){
    
    ll N,a[200010],t[200010],MIN=9999999999999999,tm;
    cin>>N;
    rep(i,0,N)cin>>a[i];
    t[0]=a[0];
    rep(i,1,N)t[i]=t[i-1]+a[i];
    rep(i,0,N-1){
        tm=t[i]-(t[N-1]-t[i]);
        if(tm<0)tm=-tm;
        MIN=min(MIN,tm);
    }
    cout<<MIN<<endl;
    
}






Measured memory_bytes: 3328
#include<stdio.h>
#include<iostream>
using namespace std;

int A,B,X;
int main (){
    cin >> A >> B >> X;
    for(int i=0; i<B+1; i++){
        if ( A + i == X ) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>

using ll = long long;

int main() {
    int N, K;
    std::cin >> N >> K;
    std::string S;
    std::cin >> S;
    K--;
    char c = S[K];
    if (c == 'A') {
        c = 'a';
    }
    else if (c == 'B') {
        c = 'b';
    }
    else {
        c = 'c';
    }
    S[K] = c;
    std::cout << S << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

ll a[1010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n; cin >> n;
    REP(i, n) cin >> a[i];
    int q; cin >> q;
    
    REP(i, q){
        int com, b, e; cin >> com >> b >> e;
        if(!com){
            ll minV=1000000000;
            for(int j=b; j<e; ++j) minV = min(minV, a[j]);
            cout << minV << endl;
        }else{
            ll maxV=-1000000000;
            for(int j=b; j<e; ++j) maxV = max(maxV, a[j]);
            cout << maxV << endl;
        }
        
    }
	return 0;
}


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

using namespace std;
int A,B;

int main()
{
    cin >> A >> B;
    int x = 1 , Ans = 0;
    while(x < B){
        x--;
        x+=A;
        Ans++;
    }
    cout << Ans;
    return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->second++;

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  string s,t;cin>>s>>t;
  for(i=0;i<n;i++){
    if(s.substr(i,n-i)==t.substr(0,n-i)){
      res=n-i;
      break;
    }
  }
  cout<<n+(n-res)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,a,b,c;
    int cal[10000]={0};
    int i,j;
    int x,z;
    int rui=0,masa = 0;
 
    scanf("%d%d%d%d",&n,&a,&b,&c);
    for(i = 0;i < n; i++) {
scanf("%d",&cal[i]);
		}
 
    for(i = 0;i < n; i++){
        for(j = 0;j < n; j++){
            if(cal[i] > cal[j]){
                x = cal[i];
                cal[i] = cal[j];
                cal[j] = x;
            }
        }
    }
    z = c;
    rui = c/a;
    for(i = 1;i <= n; i++){
        z += cal[i-1];
        masa = z / ((b*i)+a);
        if(rui <=masa){
        rui = masa;
        }
        else{
        break;
        }
    }
    printf("%d\n",rui);
    return 0;
}

Measured memory_bytes: 2768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

ll sum[1010];

int main(){
  int N,K; cin>>N>>K;
  rep(i,N){
    ll A; cin>>A;
    sum[i+1]=sum[i]+A;
  }
  vector<ll> V;
  for(int i=1;i<=N;i++) for(int j=i;j<=N;j++){
    V.push_back(sum[j]-sum[i-1]);
  }
  for(int i=45;i>=0;i--){
    vector<ll> tmp;
    for(ll v:V){
      if((1LL<<i)&v) tmp.push_back(v);
    }
    if(tmp.size()>=K) V=tmp;
  }
  ll ans=V[0];
  rep(i,K-1) ans=ans&V[i+1];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9008
#include<stdio.h>
int main(){
	int n;
	int a[100];
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=n-1;i>=0;i--){
		printf("%d",a[i]);
		if(i)printf(" ");
	}
	printf("\n");
	return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int q=0;
    int i,p=s.size();
    for(i=0;i<p;i++){
    if(i%2==0&&s[i]!='L')q=q+1;
    else if(i%2!=0&&s[i]!='R')q=q+1;
    
    }
    if(q==p)cout<<"Yes";
    else {cout<<"No";}

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int n, t;
    cin >> n >> t;
    vi a(n);
    rep(i, n) cin >> a[i];

    int mi = a[0];
    int ma_diff = 0;
    int cnt = 0;
    rep2(i, 1, n) {
        if (a[i] - mi > ma_diff) {
            ma_diff = a[i] - mi;
            cnt = 1;
        } else if (a[i] - mi == ma_diff) {
            cnt++;
        }
        mi = min(a[i], mi);
    }

    cout << cnt << endl;

}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){


	int H, W; cin >> H >> W;
	char s[H][W];

	REP(i,H){
		REP(j,W){
			cin >> s[i][j];
		}
	}

	bool ans = true;
	//上下左右
	int x[4] = {0, 0, -1 , 1};
	int y[4] = {1, -1, 0, 0};
	REP(i,H){
		REP(j,W){
			if(s[i][j] == '.') continue;
			int cnt = 0;
			REP(k,4){
				int a = i + y[k];
				int b = j + x[k];
				if(a > -1 and a < H and b > -1 and b < W){
					if(s[a][b] == '#') cnt++;
				}
			}
		if(cnt == 0) ans = false;
		}
	}

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}


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

    int a, b, c;
    cin >> a >> b >> c;

    int t = 0;
    int ans = -1;
    REP(i, 60) {
        if (t % 60 < (t + a) % 60) {
            if (t % 60 <= c and c <= (t + a) % 60) {
                ans = t - t % 60 + c;
                break;
            }
        }
        else {
            if (c <= (t + a) % 60) {
                ans = t + a - (t + a) % 60 + c;
                break;
            } else if (t % 60 <= c) {
                ans = t - t % 60 + c;
                break;
            }
        }
        t += a + b;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3216
include Math
define_method :max, 		-> (a,b) { a > b ? a : b }
define_method :min, 		-> (a,b) { a < b ?  a : b }
define_method :swap, 		-> (a,b) { a, b = b, a }
define_method :gi, 			-> () { gets.split.map(&:to_i) }
define_method :gs, 			-> () { gets.chomp }
define_method :getc,		-> () { gets.chomp.split('') }
define_method :fi, 			-> () {first}
define_method :darray,	-> (size1, size2, init = nil) { Array.new(size1){Array.new(size2){init}} }
define_method :array,		-> (size,init = nil) { Array.new(size){init} }
define_method :putall, 	-> (obj) { obj.each { |o| puts o } }
define_method :repl, 		-> (st,en, &block) { st.upto en-1 do |i| block.call(i) end }
define_method :rep, 		-> (num, &block) { num.times do |i| block.call(i) end }

	n = gi[0]
	str = getc
	ans = 0
	data = 0
	str.each do |obj|
		case obj
		when 'D'
			data -= 1
		when 'I'
			data += 1
		end
		ans = data if ans < data
	end

	puts ans


Measured memory_bytes: 1916
""" スコア計算機 """

contest_types = 26
days = int(input())
cs = list(map(int, input().strip().split()))
ss = [list(map(int, input().strip().split())) for _ in range(days)]
ts = [int(input()) - 1 for _ in range(days)]

# 満足度
satisfaction = 0

last_days = [-1] * contest_types

for d in range(days):
    # d日目の満足度の増加
    c_type = ts[d]
    increase = ss[d][c_type]
    satisfaction += increase

    # 開催日の更新
    last_days[c_type] = d

    # d日目の満足度の減少
    for i in range(contest_types):
        last = last_days[i]
        decrease = cs[i] * (d - last)
        satisfaction -= decrease

    print(satisfaction)


Measured memory_bytes: 9396
N = int(input())
a_list = []
a_list.append(list(map(int,input().split(" "))))
a_list.append(list(map(int,input().split(" "))))

dp = [[0]*(N+1)]*2

for i in range(2):
    for j in range(1,N+1):
        if i == 0:
            dp[i][j] = dp[i][j-1] + a_list[i][j-1]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + a_list[i][j-1]
print(dp[1][N])


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#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++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n,m;
  cin >> n >> m;
  vector<set<int>> g(n);
  vpii s(m);
  rep(i,m){
    int p,q;
    cin>>p>>q;p--;q--;
    s[i] = make_pair(p,q);
    g[p].insert(q);
    g[q].insert(p);
  }
  int cnt = 0;
  rep(i,m){
    auto gd = g;
    int fr = s[i].first;
    int to = s[i].second;
    gd[fr].erase(to);
    gd[to].erase(fr);
    vb seen(n,false);
    queue<int> q;
    q.push(0);
    seen[0] = true;
    while(!q.empty()){
      int p = q.front();
      q.pop();
      for(auto value:gd[p]){
        if(seen[value])continue;
        seen[value] = true;
        q.push(value);
      }
    }
    bool ok = true;
    rep(i,n){
      if(!seen[i])ok = false;
    }
    if(!ok)cnt++;
  }
  cout << cnt << endl;
    
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main(){
    string S, ans;
    int l, i, n=0, tmp=0;
    cin >> S;

    l = S.length();

    for (i=0; i<l; i++){
        if (S[i]=='A' or S[i]=='G' or S[i]=='C' or S[i]=='T'){
            tmp++;
            if (tmp > n) n = tmp;
        }
        else {
            tmp = 0;
        }
    }
    cout << n << '\n';
}

   

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define rep(i,n) for(int i=0;i<(int)(n);++i)
    #define repone(i,n) for(int i=1;i<(int)(n);++i)

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

    #define int long long

    using namespace std;

    signed main()
    {
        int x,y=0,z,w,i,j;
        cin>>x;
        int Size[x];
            rep(i,x){
            cin>>Size[i];
            }
             std::sort(Size,Size+x);


        cout<<Size[(x/2)]-Size[(x/2)-1]<<endl;
        return 0;
    }


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int a[100];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int m=n;
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            m=m-1;
        }
    }
    cout<<m;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>


int main(){

  int n, m, l, i, j, k, a[110][110], b[110][110];
  long int c[110][110]={}; 
  

  scanf("%d %d %d", &n, &m ,&l);
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      scanf("%d", &a[i][j]);
    }
  }
  for(i=1;i<=m;i++){
    for(j=1;j<=l;j++){
      scanf("%d", &b[i][j]);
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=l;j++){
      for(k=1;k<=m;k++){
	c[i][j]+=a[i][k]*b[k][j];
      }
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=l;j++){
      printf("%ld", c[i][j]);
      if(j==l) printf("\n");
      else printf(" ");
    }
  }

  return 0;
  
}

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



int main() {
    string S, Sr, S1, S1r, S2, S2r;
    cin >> S;

    Sr=S;
    reverse(Sr.begin(), Sr.end());

    for (int i = 0; i < S.size()/2; ++i) {
        if (S[i]!=Sr[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    S1 = S.substr(0, (S.size()-1)/2);

    S1r=S1;
    reverse(S1r.begin(), S1r.end());

    for (int i = 0; i < S1.size()/2; ++i) {
        if (S1[i]!=S1r[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    S2 = S.substr((S.size()+3)/2-1,S.size());

    S2r=S2;
    reverse(S2r.begin(), S2r.end());

    for (int i = 0; i < S2.size()/2; ++i) {
        if (S2[i]!=S2r[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int tim[10000][750];
int cnt[10000][750];
int main(){
  int N,M;
  while(cin>>N>>M,N+M){
    int r;
    cin>>r;
    memset(tim,0,sizeof(tim));
    for(int i=0;i<r;i++){
      int t,n,m,s;
      cin>>t>>n>>m>>s;
      t-=540,m--;
      tim[m][t+1]+=s?1:-1;
    }
    for(int i=0;i<M;i++){
      int sum=0;
      for(int j=0;j<740;j++){
	tim[i][j+1]+=tim[i][j];
	sum+=!!tim[i][j];
	cnt[i][j]=sum;
      }
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
      int s,e,m;
      cin>>s>>e>>m;
      s-=540,e-=540,m--;
      cout<<cnt[m][e]-cnt[m][s]<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 60748
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1e16;
//using Graph = vector<vector<int>>;

void dijkstra( vector<vector<pair<int, int>>> &G, int s, vector<int> &dist ){ //スタート地点を指定
  //コスト、向かう頂点でpair(コストが小さい順に並ぶ)
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
  dist.at(s) = 0;
  que.push(make_pair(0, s));
  while( !que.empty() ){
    pair<int, int> P = que.top();
    que.pop();
    int v = P.second;
    if( dist.at(v) < P.first ) continue;
    for( auto &next : G.at(v) ){
      if( dist.at(next.first) > dist.at(v) + next.second ){
        dist.at(next.first) = dist.at(v) + next.second;
        que.push({dist.at(next.first), next.first});
      }
    }
  }
}

signed main(){
  int V, E, r;
  cin >> V >> E >> r;

  //向かう先の頂点番号、コスト
  vector<vector<pair<int, int>>> G(V);
  vector<int> dist(V, INF);
  for( int i = 0; i < E; i++ ){
    int S, T, D;
    cin >> S >> T >> D;
    G.at(S).push_back({T,D});
  }
  dijkstra(G, r, dist);

  for( int i = 0; i < V; i++ ){
    if( dist.at(i) == INF ) cout << "INF" << endl;
    else cout << dist.at(i) << endl;
  }

 }


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, svi=-1;
	cin >>n;
	VI x(n), y(n), h(n);
	rep(i, n){
		cin >>x[i] >>y[i] >>h[i];
		if(h[i] !=0) svi=i;
	}

	rep(i, 101) rep(j, 101){
		int dx=abs(i-x[svi]), dy=abs(j-y[svi]);
		int dh = h[svi]+dy+dx;
		bool ng =0;
		rep(k, n){
			if( h[k] != max(dh - abs(i-x[k]) - abs(j-y[k]), 0) ){ng =1; break;}
		}
		if(!ng){
			cout << i <<" "<< j <<" "<< dh <<"\n";
			return 0;
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
  int a,b;
  cin>>a>>b;
  
  if(a%3==0){cout<<"Possible"<<endl;return 0;}
  if(b%3==0){cout<<"Possible"<<endl;return 0;}
  if((a+b)%3==0){cout<<"Possible"<<endl;}
  else{cout<<"Impossible"<<endl;}
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define MAX 20
#define TEST 0
int dist[MAX][MAX];

void fw(int n)
{
    for(int k=0;k<n;k++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if((dist[i][k]!=-1 && dist[k][j]!=-1)&& (dist[i][j]==-1|| (dist[i][k]!=-1 && dist[i][j]>dist[i][k]+dist[k][j])))
                {
                    dist[i][j]=dist[i][k]+dist[k][j];
                }
            }
        }
    }
    return;
}


int main(void)
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            dist[i][j]=-1;
        }
    }
    for(int i=0;i<m;i++)
    {
        int a,b,c,d;
        scanf("%d,%d,%d,%d",&a,&b,&c,&d);
        dist[a-1][b-1]=c;
        dist[b-1][a-1]=d;
    }
    int x1,x2,y1,y2;
    scanf("%d,%d,%d,%d",&x1,&x2,&y1,&y2);
    fw(n);
    if(TEST)
    {
        printf("(x1,x2,y1,y2)=(%d,%d,%d,%d)\n",x1,x2,y1,y2);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                printf("%d ",dist[i][j]);
            }
            puts("");
        }
    }
    printf("%d\n",y1-y2-dist[x1-1][x2-1]-dist[x2-1][x1-1]);
    return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>

int main(void){
 int x,y,a,b;
 scanf("%d %d",&x,&y);
 if(y%2!=0){
   printf("No");
 }else{
  a = (y-2*x)/2;
  b = (4*x-y)/2;
  if(a>=0 && b>=0){
    printf("Yes");
  }else{
    printf("No");
  } 
 }
 return 0; 
}

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

int main() {
 int N,X,T;
 int T2;
 cin >> N >> X >> T;
 if (N%X!=0){
   T2=T*(N/X+1);
 }
 else {
   T2=T*(N/X);
 }
 cout << T2 << endl;
}

Measured memory_bytes: 3600
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

//二次元平面を探索しよう
template <typename T,typename U>                                                   
pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.first+r.first,l.second+r.second};                                    
} 

vector<pair<int, int>> nei;
void nei_init(){
	nei.push_back(make_pair(-1,0));nei.push_back(make_pair(1,0));nei.push_back(make_pair(0,-1));nei.push_back(make_pair(0,1));
	//4近傍ならコメントアウト
	//nei.push_back(make_pair(-1,-1));nei.push_back(make_pair(1,-1));nei.push_back(make_pair(1,1));nei.push_back(make_pair(-1,1));
}

bool is_safe(pair<int, int> p, int h, int w){
	if(p.first < 0 || p.second < 0) return false;
	else if(p.first >=h || p.second >=w) return false;
	else return true;
}
//

int main() {
	ll ans = 0;
	ll tmp;
	int n; cin >> n;
	int h[n][n] = {};
	REP(i, n){
		REP(j, n){
			h[i][j] = min({i, j, n-1-i, n-1-j});
		}
	}
	int p[n][n];
	REP(i, n) REP(j, n) p[i][j] = 1;
	nei_init();
	REP(co, n*n){
		cin >> tmp;
		int x = (tmp-1) / n;
		int y = (tmp-1) % n;
		ans += h[x][y];
		queue<pair<int, int>> q;
		q.push(make_pair(x, y));
		p[x][y] = 0;
		while(!q.empty()){
			pair<int, int> now = q.front();
			q.pop();
			//cout << co << " " << now.first << " " << now.second << " " << h[now.first][now.second] << endl;
			REP(fo, 4){
				//cout << (now+nei[fo]).first << " " << (now+nei[fo]).second << endl;
				if(is_safe(now + nei[fo], n, n) && h[(now+nei[fo]).first][(now+nei[fo]).second] > h[now.first][now.second] + p[now.first][now.second]){
					h[(now+nei[fo]).first][(now+nei[fo]).second] = h[now.first][now.second] + p[now.first][now.second];
					q.push(now+nei[fo]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5532
n = int(input())
F = []
for i in range(n):
  f = list(map(int,input().split()))
  shop = []
  for j in range(5):
    shop.append([f[2*j],f[2*j+1]])
  F.append(shop)
P = [list(map(int,input().split())) for _ in range(n)]

import numpy as np
ans = -float('inf')
for i in range(1,2**10):
  index =format(i,'b').zfill(10)
  open_j = [int(j) for j in index]
  open_j = np.array(open_j).reshape(5,2)
  score = 0
  for j in range(n):
    count = 0
    for k in range(5):
      for l in range(2):
        if F[j][k][l] and open_j[k][l]:
          count += 1
    score += P[j][count]
  ans = max(ans,score)
print(ans)

Measured memory_bytes: 14068
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const long long MOD = 998244353;

long long inq(long long x, long long y)
{
    if (y == 0) return 1;
    long long l = inq(x, y / 2);
    if (y % 2) return l * l % MOD * x % MOD;
    return l * l % MOD;
}

int n, l, t, a, b;
vector<int> x;
long long times = 0;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> l >> t;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        if (b == 1) a += t;
        else a -= t;
        long long L = -1e9, R = 1e9;
        while (L + 1 < R)
        {
            long long mid = (L + R) / 2;
            if (mid * l <= a) L = mid;
            else R = mid;
        }
        times += L;
        a = (a % l + l) % l;
        x.push_back(a);
    }
    sort(all(x));
    times = (times % n + n) % n;
    for (int i = times; i < x.size(); i++) cout << x[i] << "\n";
    for (int i = 0; i < times; i++) cout << x[i] << "\n";
}


Measured memory_bytes: 1784
N,M=gets.split.map(&:to_i)

all_likes = Array.new(M+1, true)
all_likes[0] = false

N.times do
  one_likes = gets.split.map(&:to_i)
  k = one_likes.delete_at(0)

  for i in 1..M do
    if !one_likes.include?(i)
      all_likes[i] = false
    end
  end
end

puts all_likes.select{|e| e == true}.length


Measured memory_bytes: 1788
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = collections.Counter([int(input().rstrip('\n')) for _ in range(n)])
    cnt = 0
    for k, v in a.items():
        if v % 2 != 0:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 56156
A, B, C = list(map(int, input().split()))
K = int(input())

for _ in range(K):
    maxN = max(A, B, C)
    if maxN == A:
        A *= 2
    elif maxN == B:
        B *= 2
    else:
        C *= 2

print(A + B + C)

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

int main(){
  int x,y;
  cin >> x >> y;
  bool frag =false;
  for(int i=0;i<=x;i++){
    if((x-i)*2+4*i==y){
      frag=true;
    }
  }
  if(frag==true){   
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
	string S;
	cin >> S;
	int ans=0;
	for(int i=0;i<(S.size()/2);i++)if(S[i]!=S[S.size()-i-1])ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int x = A + B;
        int y = A - B;
        int z = A * B;
        
        int ans = Math.max(x, Math.max(y, z));
        System.out.println(ans);
    }
}


Measured memory_bytes: 35796
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ll long long
int c[10][10];
int hw[40000];
int main(){
    int h,w; cin >> h >> w;
    REP(i,10){
        REP(j,10){
            cin >> c[i][j];
        }
    }
    REP(i,h*w){
        cin >> hw[i];
    }
    vector<int> p;
    REP(i,10){
        p.push_back(i);
    }
    int mi[10];
    REP(i,10){
        mi[i] = 100000000;
    }
    mi[1] = 0;
    do{
       int first = p[0];
       if(first == 1){
           continue;
       }
       vector<int>::iterator it = p.begin();
       int tmp = 0;
       while(it+1!=p.end()&&*it!=1){
           tmp += c[*it][*(it+1)];
           it++;
       } 
       mi[first] = min(mi[first], tmp);

    }while(next_permutation(p.begin(), p.end()));
    int ans=0;
    REP(i,h*w){
        if(hw[i]!=-1){
            ans += mi[hw[i]];
        }
    }
    cout << ans << endl;

}

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

int main()
{
  int n;
  cin >> n;
  for (int a = 1; a < 10; a++)
    for (int b = 1; b < 10; b++)
      if (a * b == n) {
        cout << "Yes" << endl;
          return 0;
      }
  cout << "No" << endl;
        
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int w = Integer.parseInt(sc.next());
        int h = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());

        double area = (long) w * (long) h / 2.0;
        int root = (w / 2.0 == (double) x && h / 2.0 == (double) y) ? 1 : 0;

        System.out.println(area + " " + root);
    }
}


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

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long  ll;

int main()
{
    run;
    ll n,k;
    cin>>n>>k;
    fr(i,1,100)
    {
        if(pow(k,i)==n)
        {
            cout<<i+1;
            return 0;
        }
        if(pow(k,i)>n)
        {
            cout<<i;
            return 0;
        }
    }


}


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

int main(){
  int X,N;
  cin >> X >> N;
  int minP = 0;
  vector<bool> ped(100);
  for(int i = 0; i < N; i++){
    int p;
    cin >> p;
    ped[p-1] = true;
  }
  for(int i = -1; i < 101; i++){
    if(i >= 0){
      if(ped[i]) continue;
    }
    if(abs(minP-X) > abs(i+1-X)) minP = i+1;
  }
  cout << minP << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
int n;
int A[100032], B[100032], C[100032];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, n) cin >> A[i];
  rep(i, n) cin >> B[i];
  rep(i, n) cin >> C[i];
  sort(A, A + n); sort(B, B + n); sort(C, C + n);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int x = lower_bound(A, A+n, B[i]) - A;
    int y = (upper_bound(C, C+n, B[i])-C);
    y = n - y;
    ans += (lint)x * y ;
  }
  cout << ans << '\n';
}



Measured memory_bytes: 1408
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 ll a[n+10];
 ll mn;
 ll sm=0;
 ll cnt=0;
 rep(i,0,n){
  sc(a[i]);
  sm+=abs(a[i]);
  if(a[i]<0)cnt++;
  if(i==0)mn=abs(a[i]);
  else mn=min(mn,abs(a[i]));
  //cout<<sm<<" "<<mn<<endl;
 }

 //負の要素が偶数個だと全てを+にできる
 ans=0;
 rep(i,0,n-1){
  if(cnt%2==0){
   pr(sm);return 0;
  }
 }

 pr(sm-mn*2);
 return 0;}

Measured memory_bytes: 4328
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(1){
    if(x->left == NIL)break;
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(1){
    if(x->right == NIL)break;
    x = x->right;
  }
  return x;


}

Node treeSearch(Node u, int k){
  while(1){
    if(u == NIL || k == u->key)break;
    if(k < u->key){
      u = u->left;
    } else {
      u = u->right;
    }
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(1){
    if(y == NIL || x != y->right)break;
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL){
    y = z;
  } else {
    y = treeSuccessor(z);
  }

  if(y->left != NIL){
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  } else {
    if(y == y->parent->left){
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(1){
    if(x == NIL)break;
    y=x;
    if(z->key < x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  } else {
    if(z->key < y->key){
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20608
/**akshaykumar99**/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e6+1;
 
typedef long long ll;
typedef long double ld;
 
int main()
{
    IOS();
   
    ll i,a,b,c;
    string s,t,r="";
    cin>>a;
    cin>>s>>t;
    f(i,0,a)
    {
    	r+=s[i];
    	r+=t[i];
    }
    cout<<r<<'\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long n,a,b,c=0,d,e;
    cin>>n>>a>>b>>d;
    for(int i=1;i<n;i++){
        cin>>e;
        
        if((e-d)*a>b){
            c+=b;
        }else{
            c+=(e-d)*a;
        }
        
        d=e;
    }
    
    cout<<c<<endl;
    
}


Measured memory_bytes: 256
n,m=gets.split.map(&:to_i)
all=gets.split.map(&:to_i)
i=all.length-1

result=m
for i in 0..all.length-2
    if all[i+1]-all[i]<m
        result+=all[i+1]-all[i]
    else
        result+=m
  
  
    end

    
end
p result

Measured memory_bytes: 16004
def check_4(i,j):
    hi = [1,0,-1,0]
    wi = [0,-1,0,1] #↓←↑→
    for p in range(4):
        if 0 <= i+hi[p] < H and 0 <= j+wi[p] < W:
            if cambus[i+hi[p]][j+wi[p]] == '#':
                return True
    return False

H,W = map(int,input().split())
cambus = [input() for i in range(H)]

for i in range(H):
    for j in range(W):
        if cambus[i][j] == '#':
            if not check_4(i,j):
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064