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

int main() {

	int n, l;
	cin >> n >> l;

	vector<int> x(n + 1);

	int ans = 1e9;
	int flug = 0;
	for(int i = 1; i <= n; i++){
		x[i] = l + i - 1;
		if(ans > min(ans, abs(x[i]))){
			ans = min(ans, abs(x[i]));
			flug = i;
		}
	}

	int sum = 0;
	for(int i = 1; i <= n; i++){
		if(i != flug){
			sum += x[i];
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    int  ans = 1;
    while(ans*2 <= n) ans *= 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using state= pair<int, bool>;

int64_t dp(state idx, string &N){ 
  int id= idx.first;
  bool carry_in= idx.second;
  bool carry_out;
  int Nmod10pluscarry= N.at(id)- '0';
  if(carry_in) Nmod10pluscarry++;

  if(id==0) return min(Nmod10pluscarry, 1+(10- Nmod10pluscarry));  
  else{
    if(Nmod10pluscarry > 5) return dp(make_pair(id-1, true) , N)+ 10- Nmod10pluscarry;
    if(Nmod10pluscarry < 5) return dp(make_pair(id-1, false), N)+ Nmod10pluscarry;
    else{
      int n_judge= N.at(id-1)- '0';
      if(n_judge < 5) return dp(make_pair(id-1, false), N)+ 5;
      if(n_judge >=5) return dp(make_pair(id-1, true) , N)+ 5;
    }
  }
}

int main() {
  string N;
  cin >> N;
  
  cout << dp(make_pair(N.size()-1, false), N) << endl;
}

Measured memory_bytes: 48260
#include<bits/stdc++.h>
using namespace std;
struct edge
{
	int u,v,w;
	edge(int u=0,int v=0,int w=0):u(u),v(v),w(w){}
}e[100005];
int main()
{
//	freopen("f.in","r",stdin);
//	freopen("f.out","w",stdout);
	int l,jl1,jl2;
	cin>>l;
	for(int i=2;(1<<i-1)<=l;i++)
	{
		jl1=i,jl2=l-(1<<i-1);
	}
	int n=jl1;
	cout<<n<<" ";
	int m=0;
	for(int i=1;i<jl1;i++)
	{
		e[++m]=edge(i,i+1,0);
		e[++m]=edge(i,i+1,(1<<i-1));
	}
	int tt=(1<<jl1-1);
	for(int i=20;i>=0;i--)if(jl2&(1<<i))
	{
		jl2^=(1<<i);
		e[++m]=edge(i+1,n,tt);
		tt+=1<<i;
	}
	cout<<m<<endl;
	for(int i=1;i<=m;i++)
	{
		printf("%d %d %d\n",e[i].u,e[i].v,e[i].w);
	}
	return 0;
}

Measured memory_bytes: 4900
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a, b = readmi()
print((a * 3 + b) // 2)




Measured memory_bytes: 7880
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    double d, t, s;
    cin >> d >> t >> s;
    double t1 = d/s;
    if(t >= t1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3720
def p_s(x, y):
    for i in range(x):
        str = ''
        for j in range(y):
            str += '#'
        print(str)

    print()


while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    p_s(H, W)



Measured memory_bytes: 5620
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){
    
    int h,w,a,b;
    int matrix[1000][1000]={1};

    cin >> h >> w >> a >> b;

    for(int i=0;i < h;i++){
        
        for(int j=0;j < w;j++){
                if(j < a && i < b) matrix[i][j] = 0;
            else if(a <= j && i < b) matrix[i][j] = 1;
            else if(j < a && i >= b) matrix[i][j] = 1;
            else if(a <= j && i>= b) matrix[i][j] = 0;

        }
    }

    for(int i=0;i < h;i++){
        for(int j =0;j < w;j++){
            cout << matrix[i][j];

        }
        cout << endl;
        
            
        
    }



    
    
    return 0;
}

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

int main()
{
ll n , a , b ;
cin >> n >> a >> b ;
if((b-a)%2){
  ans=min(a+(b-a-1)/2,n-b+1+(b-a-1)/2);
}
else ans=(b-a)/2;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(M=1<<31,i=s=0;i<n;s+=a[i],k<++i&&(s-=a[i-k-1])&&M<s&&(M=s))std::cin>>a[i];}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, k);

  int ans = k;
  for (int i = 0; i < n - 1; ++i) {
    ans *= k - 1;
  }
  cout << ans << endl;

  return 0;
}

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

int main(){

    int n;
    cin >> n;
    vector<long int> a(n);
    long long int half=0;
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        a.at(i)*=2;
        half+=a.at(i);
    }
    half/=2;
    long long int cut=1e18;
    long long int c=0;
    for(int i=0; i<n-1; i++){
        c+=a.at(i);
        cut=min(cut,abs(half-c));
    }
    cout << cut << endl;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}


int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h+2,vector<char>(w+2,'#'));
    vector<vector<int>> v(h+2, vector<int>(w+2,0));
    queue<pair<int,int>> q;
    queue<int> p;
    REP(i,h){
        REP(j,w){
            cin >> a[i+1][j+1];
            if(a[i+1][j+1]=='#'){
                q.push(make_pair(i+1,j+1));
                p.push(0);
            }
        }
    }
    while(!q.empty()){
        int x=q.front().first;
        int y=q.front().second;
        q.pop();
        v[x][y]=p.front();
        p.pop();
        if(a[x-1][y]=='.'){
            a[x - 1][y] = '#';
            q.push(make_pair(x-1,y));
            p.push(v[x][y]+1);
        }
        if (a[x][y - 1] == '.')
        {
            a[x][y - 1] = '#';
            q.push(make_pair(x, y-1));
            p.push(v[x][y] + 1);
        }
        if (a[x + 1][y] == '.')
        {
            a[x + 1][y] = '#';
            q.push(make_pair(x+1, y));
            p.push(v[x][y] + 1);
        }
        if (a[x][y + 1] == '.')
        {
            a[x][y + 1] = '#';
            q.push(make_pair(x, y+1));
            p.push(v[x][y] + 1);
        }
    }
    int ans=0;
    REP(i, h)
    {
        REP(j, w)
        {
            ans=max(ans,v[i+1][j+1]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 17552
#include "bits/stdc++.h"
using namespace std;

// #define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  // array<int, 1000000> A;
  // string S;
  // string T;

  int A, B;

  cin >> A >> B;

  // cout << (log10(B) + 1) << endl;
  
  N = A * pow(10, (int)(log10(B) + 1)) + B;

  // cout << N << endl;

  for (int i = 0; i <= sqrt(N); i++) {
    if (i * i == N) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  
  // if (N / sqrt(N) == sqrt(N)) cout << "Yes" << endl;
  // // if (sqrt(N) * sqrt(N) == N) cout << "Yes" << endl;
  // else
    cout << "No" << endl;
  
  
  // cin >> N;
  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   cin >> *it;
  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   if (*it % 2 == 0) ++num;
  // cout << num << endl;
  
  return 0;
}


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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
#define double long double
	while (t--) {
		double n;
		cin >> n;
		double sum = 0;
		for (double i = 1; i <= n; i++) {
			sum = sum + ((i / 2.0) * (floor(n / i)) * (floor(1.0 + n / i)));
		}
		int k = sum;
		cout << fixed<<setprecision(0)<<sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3804
#include<map>
#include<iostream>
#include<string>

int main(){
	int num;
	std::cin >> num;
	
	std::map<std::string,int> dic;
	
	for(int i=0;i<num;i++){
		std::string process,key;
		
		std::cin >> process >> key;
		
		if(process[0]=='i'){
			dic[key]=1;
		}else{
			if(dic[key]==0){
				std::cout << "no" << std::endl;
			}else{
				std::cout << "yes" << std::endl;
			}
		}
	}
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  for(int i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  
  long long ans = 0;
  for(int i = 0; i < n; i++)
  {
    long long aa = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    long long cc = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
    ans += aa * (n - cc);
  }
  cout << ans << endl;
}

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

int main() {
	int room[4][3][10]={0};
	
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int b,f,r,v;
		cin >> b >> f >> r >> v;
		room[b-1][f-1][r-1]+=v;
	}
	
	for(int i=0; i<4; i++){
		for(int j=0; j<3; j++){
			for(int k=0; k<10; k++){
				cout << " " << room[i][j][k];
				
				
			}
			cout << endl;
		}
		
		if(i!=3)cout << "####################" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) { cin >> s[i]; }
  set<int> eli_h, eli_w;
  REP(j, w) {
    bool f = true;
    REP(i, h) {
      if (s[i][j] == '#') f = false;
    }
    if (f) eli_w.insert(j);
  }
  REP(i, h) {
    bool f = true;
    REP(j, w) {
      if (s[i][j] == '#') f = false;
    }
    if (f) eli_h.insert(i);
  }
  REP(i, h) {
    bool f = false;
    REP(j, w) {
      if (!eli_h.count(i) && !eli_w.count(j)) {
        cout << s[i][j];
        f = true;
      }
    }
    if (f) cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main()
{  
   	int n;
	cin>>n;
	int x=n;
	int digit=n%10;
	if(digit==2||digit==4||digit==9||digit==5||digit==7)
	cout<<"hon";
	else if(digit==0||digit ==1||digit==6||digit==8)
	cout<<"pon";
	else
	cout<<"bon";  
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

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

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    int res = 0;
    string s;
    cin >> s;

    for(int i = 0; i < N - 2; ++i)
    {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            ++res;
        }
    }


    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n;
    map<int,int> cnt;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        cnt[a]++;
    }
    bool ok = true;
    if(cnt.size() > 3) ok = false;
    else if(cnt.size() > 1){
        if(n%3 != 0) ok = false;
        int a = 1, b = 2;
        for(auto p : cnt){
            for(auto q : cnt){
                if(cnt.count(p.first^q.first) && p.first != q.first){
                    a = p.first;
                    b = q.first;
                    break;
                }
            }
        }
        if(ok){
            for(int i=0;i<n;i++){
                int c = a^b;
                cnt[c]--;
                if(cnt[c] < 0){
                    ok = false;
                }
                a = b;
                b = c;
            }
        }
    }
    else{
        if(cnt.begin()->first != 0) ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < x.size(); i++) {
    cin >> x[i];
  }

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

  int ans = abs(X - x[0]);

  for (int i = 1; i < x.size(); i++) {
    ans = __gcd(ans, abs(X - x[i]));
  }

  cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<ll,ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll H,W,N;
  cin >> W >> H >> N;
  vector<vector<ll>> A(W,vector<ll>(H,0));
  rep(k,N){
    ll x,y,a;
    cin >> x >> y >> a;
    if(a==1){
      rep(i,x){
        rep(j,H){
          A.at(i).at(j)=1;
        }
      }
    }
    if(a==2){
      for(ll i=x;i<W;i++){
        rep(j,H){
          A.at(i).at(j)=1;
        }
      }
    }
    if(a==3){
      rep(i,W){
        rep(j,y){
          A.at(i).at(j)=1;
        }
      }
    }
    if(a==4){
      rep(i,W){
        for(ll j=y;j<H;j++){
          A.at(i).at(j)=1;
        }
      }
    }
  }
  ll ans=0;
  rep(i,W)rep(j,H){
    if(A.at(i).at(j)==0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
S = input()

YYMM = 1
MMYY = 1

if int(S[0] + S[1]) == 0 or int(S[0] + S[1]) > 12:
    MMYY = 0
    if int(S[2] + S[3]) == 0 or int(S[2] + S[3]) > 12:
        YYMM = 0

if int(S[2] + S[3]) == 0 or int(S[2] + S[3]) > 12:
    YYMM = 0
    if int(S[0] + S[1]) == 0 or int(S[0] + S[1]) > 12:
        MMYY = 0

if YYMM and MMYY:
    print("AMBIGUOUS")
elif YYMM:
    print("YYMM")
elif MMYY:
    print("MMYY")
else:
    print("NA")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int N;
int A[1010];
int solve(int x)
{
    int ans = 0;
    for(int i=0; i<N; ++i)
        ans += (A[i] - x)*(A[i]-x);
    return ans;
}
int main()
{
    scanf("%d", &N);
    int sum = 0;
    
    for(int i=0; i<N; ++i)
    {
        scanf("%d", A+i);
        sum += A[i];
    }
    sum /= N;
    printf("%d\n", min({solve(sum-1), solve(sum), solve(sum+1)}));
    return 0;  
}

Measured memory_bytes: 256
#!/usr/bin/env python
import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)


def main():
    N, M = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])

    ans = 0
    i = 0
    while True:
        a = AB[i][0]
        b = AB[i][1]
        logging.debug('a: %d, b: %d' % (a, b))
        while b > 0 and M > 0:
            b -= 1
            M -= 1
            ans += a
            logging.debug('b: %d, M: %d, ans: %d' % (b, M, ans))
        if M == 0:
            break
        else:
            i += 1
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 30244
#include <cstdio>
#include <queue>

#define int long long
#define dotimes(i, n) for (int i : range(n))

using namespace std;

class range {
  class iterator {
    int i, s;
  public:
    iterator(int i, int s): i(i), s(s) {}
    int& operator*() {
      return i;
    }
    void operator++() {
      i += s;
    }
    bool operator!=(iterator const& that) {
      return i < that.i;
    }
  };
  iterator b, e;
public:
  range(int e): b({0, 1}), e({e, 1}) {}
  range(int b, int e): b({b, 1}), e({e, 1}) {}
  range(int b, int e, int s): b({b, s}), e({e, s}) {}
  iterator begin() {
    return b;
  }
  iterator end() {
    return e;
  }
};

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

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

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

signed main() {
  for (;;) {
    const int w = rint();
    const int h = rint();
    if (!w && !h)
      break;
    bool walls[2*h+1][w+1];
    dotimes(i, w) {
      walls[0][i] = 1;
      walls[2*h][i] = 1;
    }
    walls[0][0] = 0;
    walls[2*h][w-1] = 0;
    dotimes(j, 2 * h - 1)
      if (j % 2) {
        dotimes(i, w)
          walls[j+1][i] = rint();
      } else {
        walls[j+1][0] = 1;
        dotimes(i, w-1)
          walls[j+1][i+1] = rint();
        walls[j+1][w] = 1;
      }
    int sp[h][w] = {};
    queue<pair<int, int>> q;
    q.emplace(0, 0);
    sp[0][0] = 1;
    while (!q.empty()) {
      auto p = q.front();
      q.pop();
      int j = p.first, i = p.second, d = sp[j][i] + 1;
      int ks[4] = {}, dy[4] = {-1, 1, 0, 0}, dx[4] = {0, 0, -1, 1};
      if (!walls[2*j][i])
        ks[0] = 1;
      if (!walls[2*(j+1)][i])
        ks[1] = 1;
      if (!walls[2*j+1][i])
        ks[2] = 1;
      if (!walls[2*j+1][i+1])
        ks[3] = 1;
      dotimes(k, 4)
        if (ks[k]) {
          int y = j + dy[k], x = i + dx[k];
          if (!sp[y][x]) {
            sp[y][x] = d;
            q.emplace(y, x);
          }
        }
    }
    wint(sp[h-1][w-1]);
  }
  return 0;
}



Measured memory_bytes: 2660
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e3 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[1005][1005];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll n;
    cin >> n;
    cout << n / 3;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<string.h>
struct Node{
  int key;
  struct Node *right,*left,*parent;
};
  
struct Node *root,*NIL;
typedef struct Node * node;

struct Node * treeMinimum(struct Node *x){
  while(x->left != NIL)x=x->left;
  return x;
}

struct Node * find(struct Node *u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u -> left;
    }
    else {
      u = u -> right;
    }
  }
  return u;
}
struct Node * treeSuccessor(struct Node *x){
  if(x->right != NIL)return treeMinimum(x->right);
  struct Node *y=x->parent;
  while(y != NIL && x==y->right){
    x = y;
    y = y ->parent;
}
  return y;
}

void treeDelete(struct Node *z){
  struct Node *y;
  struct Node *x;

  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){
  struct Node *x=root;
  struct Node *y=NIL;
  struct Node *z;
  z=malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while( x!=NIL){
    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(struct Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
  
void preorder(struct Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
int main(){
  int n,i,x;
  int a=0,b=0;
  char com[10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      struct Node *t=find(root,x);
      if(t != NIL)printf("yes\n");
	else printf("no\n");
    }
      if(strcmp(com,"insert")==0){
	scanf("%d",&x);
	insert(x);
      }
      if(strcmp(com,"print")==0){
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
      }else if(strcmp(com,"delete")==0){
	scanf("%d",&x);
	treeDelete(find(root,x));
    }
  }
  return 0;
}

Measured memory_bytes: 19360
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	
	public static void Main(string[] args)
	{
		string[] w = Input();
		int a = int.Parse(w[0]);
		int b = int.Parse(w[1]);
		if(b==1)
		{
			Console.WriteLine(0);
			return;
		}
		int r = a;
		int cnt = 1;
		while(r < b)
		{
			r += a;
			r -=1;
			cnt++;
		}
		
		Console.WriteLine(cnt);
	}
	
	
	public static long GCD(long a, long b)
	{
		if(b == 1)
			return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	public static string[] Input()
	{
		return Console.ReadLine().Split(' ');
	}

	
	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}

}



Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll  long long
const ll mod = 1e9 + 7;

ll solve(ll N, const std::map<ll, ll>& A)
{
    ll a = 1;
    for (ll i = (0 == N % 2 ? 1 : 0); i < N; i += 2)
    {
        if (!A.count(i))
        {
            return 0;
        }
        if (0 == i && 1 != A.at(i))
        {
            return 0;
        }
        if (0 != i && 2 != A.at(i))
        {
            return 0;
        }

        if (0 == i)
        {
            continue;
        }
        (a *= 2) %= mod;
    }
    return a;
}

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

    std::map<ll, ll> A;
    for (ll n = 0; n < N; n++)
    {
        ll a;
        std::cin >> a;
        A[a]++;
    }

    std::cout << solve(N, A) << std::endl;
    return 0;
}

Measured memory_bytes: 4224
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=1e9+7;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n;
ll jc[N],inv[N],sz[N],f[N],ans[N],g[N];
struct edge{int y,next;}a[N<<1];int len,last[N];
void ins(int x,int y) {a[++len]=(edge){y,last[x]};last[x]=len;}

void dfs1(int x,int fa) {
	sz[x]=f[x]=1;
	for(int k=last[x],y;k;k=a[k].next)
		if((y=a[k].y)^fa) {
			dfs1(y,x);
			sz[x]+=sz[y];
			f[x]=f[x]*inv[sz[y]]%mod*f[y]%mod;
		}
	f[x]=f[x]*jc[sz[x]-1]%mod;
}

ll power(ll a,ll b) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		a=a*a%mod; b=b>>1;
	}
	return c;
}
			
void dfs2(int x,int fa) {
	ans[x]=f[x]*inv[sz[x]-1]%mod*jc[n-1]%mod*inv[n-sz[x]]%mod*g[fa]%mod;
	for(int k=last[x],y;k;k=a[k].next)
		if((y=a[k].y)^fa) {
			g[x]=f[x]*inv[sz[x]-1]%mod*jc[n-sz[y]-1]%mod*jc[sz[y]]%mod*power(f[y],mod-2)%mod*g[fa]%mod*inv[n-sz[x]]%mod;
			dfs2(y,x);
		}
}

int main() {
	qr(n);for(int i=jc[0]=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
	inv[n]=power(jc[n],mod-2);
	for(int i=n; i;i--) inv[i-1]=inv[i]*i%mod;
	for(int i=1,x,y;i<n;i++) 
		qr(x),qr(y),ins(x,y),ins(y,x);
	dfs1(1,0);
	g[0]=1;dfs2(1,0);
	for(int i=1;i<=n;i++) pr2(ans[i]);	
	return 0;
}



Measured memory_bytes: 15872
from collections import Counter as ct

n = int(input())
a = list(map(int, input().split()))
s = sum(a)
a = ct(a)
q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    s -= a[b] * b
    s += a[b] * c
    a[c], a[b] = a[c] + a[b], 0
    print(s)

Measured memory_bytes: 23348
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <cstdlib>

int main() {
    while(true) {
        int n{};
        std::cin >> n;
        if(!n) break;
        std::vector<int> s(n, 0);
        for(auto i=0; i<n; i++) { std::cin >> s[i]; }
        const double m{ std::accumulate(s.begin(), s.end(), 0) / double(n) };
        double sum{};
        for(auto x : s) { sum += pow(x-m, 2.0); }
        printf("%.8lf\n", pow(sum/n, 0.5));
    }
}



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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  ll n,a,b;
  cin >> n >> a >> b;
  ll left = 0,right = 10000000000;
  priority_queue<ll,vector<ll>,less<ll>> que;
  REP(i,n){
    ll x;cin >> x;
    que.push(x);
  }
  auto search = [&](ll mid)-> bool{
    priority_queue<ll,vector<ll>,less<ll>> qu;
    qu = que;
    ll hp = mid*b,many = mid;
    while(many >= 0){
      if(qu.empty())break;
      ll mhp = qu.top();qu.pop();
      if(mhp-hp <= 0)break;
      many -= (mhp-hp+a-b-1)/(a-b);
    }
    return many >= 0 ? true : false;
  };
  while(right-left > 1){
    ll mid = (left+right)/2;
    if(search(mid))right = mid;
    else left = mid;
  }
  cout << right << endl;








  return 0;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >>H >> W;
  vector<char> vec (W+2,'#');
  for (int i=0; i<W+2; i++){
    cout<<vec.at(i);
  }
  cout<<endl;
  for(int i=0; i< H ; i++){
    string S;
    cin >>S;
    cout << '#' << S << '#';
    cout<<endl;
  }
  for (int i=0; i<W+2; i++){
    cout<<vec.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 100005;
typedef long long ll;
char s[N];
int frt[N], bhd[N], qes_f[N], qes_b[N], Pow[N];
int main(){
    Pow[0] = 1;
    for(int i = 1; i < N; ++i) Pow[i] = 1ll * Pow[i-1] * 3 % mod;
    scanf("%s", s+1);
    ll ans = 0;
    int n = strlen(s+1);
    for(int i = 1; i <= n; ++i){
        frt[i] = frt[i-1]; qes_f[i] = qes_f[i-1];
        if(s[i] == 'A'){
            frt[i] += 1;
        }else if(s[i] == '?') qes_f[i] += 1;
    }
    for(int i = n; i >= 1; --i){
        bhd[i] = bhd[i+1]; qes_b[i] = qes_b[i+1];
        if(s[i] == 'C') bhd[i] += 1;
        else if(s[i] == '?') qes_b[i] += 1;
    }
    for(int i = 1; i <= n; ++i){
        if(s[i] == 'B' || s[i] == '?'){
            ans = (ans + (1ll * frt[i] * bhd[i] * Pow[qes_f[i-1]+qes_b[i+1]] % mod)
                + (1ll * frt[i] * qes_b[i+1] * Pow[qes_f[i-1]+qes_b[i+1]-1] % mod)
                + (1ll * bhd[i] * qes_f[i-1] * Pow[qes_f[i-1]+qes_b[i+1]-1] % mod)
                + (1ll * qes_b[i+1] * qes_f[i-1] * Pow[qes_f[i-1]+qes_b[i+1]-2] % mod)) % mod;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll d,c[26],s[365][26];

void input() { 
  cin >> d;
  rep(i,26){
    cin >> c[i];
  }
  rep(i,d){
    rep(j,26){
      cin >> s[i][j];
    }
  }
}

void solve() {
  // とりあえず日ごとに満足度が一番でかいコンテストを開催してみる
  rep(i,d){
    ll maxS=s[i][0],maxC=0;
    rep1(j,25){
      if (maxS<s[i][j]){
        maxS=s[i][j];
        maxC=j;
      }
    }
    cout << maxC+1 << endl;
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

const ll nmax=200005;

void solve(){
 ll n;
 cin >> n;
 vll c(n);
 vvll color(nmax);
  rep(i,0,n) {
    cin >> c[i];
    color[c[i]].eb(i);
  }
  
  vll dp(nmax,0);
  dp[0]=1;
  
  rep(i,1,n+1){
   dp[i]+=dp[i-1]; 
   ll x=c[i-1];
   auto it =lower_bound(all(color[x]),i-1)-color[x].begin();
   if(it>0){
    ll j=color[x][it-1];
    if((i-1)-j>1) dp[i]+=dp[j+1]; 
   }
   dp[i]%=mod; 
  }
  cout << dp[n] << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 14336
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

struct SegmentTree {
private:
    int n;
    vector <ll> node;

public:
    SegmentTree(int sz) {
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1, 0);
    }

    void update(int x, ll val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    ll getmax(int a, int b, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        ll vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};

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

    int n, h;
    cin >> n;

    vector <P> flower(n);
    for (int i = 0; i < n; i++) {
        cin >> h;
        flower[i] = P(h, i);
    }

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

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

    SegmentTree seg(n);
    for (int i = 0; i < n; i++) {
        int idx = flower[i].second;
        seg.update(idx, A[idx] + seg.getmax(0, idx));
    }

    cout << seg.getmax(0, n) << "\n";
    return 0;
}

Measured memory_bytes: 7424
#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(){
    VL arr = {
        1,1,1,2,1,2,
        1,5,2,2,1,
        5,1,2,1,14,
        1,5,1,5,2,
        2,1,15,2,2,
        5,4,1,4,1,
        51
    };
    int k;
    cin >> k;
    cout << arr[k-1] << endl;
    return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N;
	
	cin >> N;
	
	double A[N], ans = 0;
	
	rep(i, N){
		cin >> A[i];
		A[i] = 1 / A[i];
		ans += A[i];
	}
	
	cout << 1 / ans;
	
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    B=[0]*n
    B[0]=sum(A)-sum(A[1::2])*2
    for i in range(1,n):
        B[i]=(A[i-1]-B[i-1]//2)*2
    print(*B)
    
if __name__=='__main__':
    main()

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



int main(){
  int n,i,j;
  int F[44];
  scanf("%d",&n);
  F[0]=1;
  F[1]=1;
  
  for(i=2;i<=n;i++){
    F[i]=F[i-1]+F[i-2];
  }
  printf("%d\n",F[n]);
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct r{
	int love;
};

int main(){
	int n;
	cin >> n;
	r a[n];
	for(int i = 0; i < n ; i++){
		r b;
		cin >> b.love;
		b.love--;
		a[i] = b;
	}
	int count = 0;
	for(int i = 0; i < n; i++){
		if(a[a[i].love].love == i){
			count++;
		}
	}
	cout << count / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
const int N=1e9+7;
#define int long long
#define double long double
#define pb push_back
#define vi vector<int>
#define rep(i,n) for(int i=1;i<=n;i++)
vi ar[100001];
int vis[100001];
void dfs(int node)
{
	vis[node]=1;
	for(int child:ar[node])
	{
		if(!vis[child])
			dfs(child);
	}
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 IOS;
int n,m,a,b;
cin>>n>>m;
while(m--)
{
cin>>a>>b;
ar[a].pb(b),ar[b].pb(a);
}
int cc=0;
for(int i=1;i<=n;i++)
{
	if(!vis[i])
	{
		cc++;
		dfs(i);
	}
}
cout<<cc-1;
 
 	
 	
 	
 		
 	 
 	 	
 	 
 

 	



  
 




  
return 0;
}


Measured memory_bytes: 11084
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>pos[21];
ll inp[100];
map<ll,ll>mp;
vector<ll>triangle;
vector<ll>::iterator upper1, upper2;
int main()
{
  ll i,j,k,l,t,n,x=0,y=0,p,q,z=0;
  cin>>n;
  string str;
  cin>>str;
  char temp='0';
  for(i=0;i<n;i++)
  {
    if(str[i]!=temp)
    {
      x++;
      temp=str[i];	
    }	
  }
  cout<<x;
  
     
     
     	
  	
}

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

int n, m, q;
int a[510][510];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m >> q;
	for(int i=0; i<m; ++i){
		int l, r;
		cin >> l >> r;
		++a[l][r];
	}
	for(int i=1; i<=n; ++i){
		for(int j=2; j<=n; ++j){
			a[i][j] += a[i][j-1];
		}
	}
	for(int i=1; i<=n; ++i){
		for(int j=n-1; j>=1; --j){
			a[j][i] += a[j+1][i];
		}
	}
	for(int i=0; i<q; ++i){
		int x, y;
		cin >> x >> y;
		cout << a[x][y] << "\n";
	}
}

Measured memory_bytes: 1920
/*input
1
11 11
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	int k, a, b;
	cin >> k >> a >> b;
	if(a > b) swap(a, b);
	for(; a<=b; a++) {
		if(a % k == 0) {
			cout << "OK" << endl;
			return;
		}
	}
	cout <<"NG" << endl;
}

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


Measured memory_bytes: 3652
//This code was made by Chinese_zjc_
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3ffffffffffffff
using namespace std;
int sl,tl,ans[100001],cnt[26],c[26][100001],v[100001],times,now;
bool need[26];
string s,t;
int min(int A,int B)
{
	return A<B?A:B;
}
int ser(int a,int b)
{//a=1,b=n
	if(c[b][cnt[b]]<=a)
	{
		return c[b][1]+sl;
	}
	int l=1,r=cnt[b];
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(c[b][mid]<=a)
		{
			l=mid+1;
		}
		if(c[b][mid]>a)
		{
			r=mid;
		}
	}
	return c[b][r];
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>s>>t;
	sl=s.length();
	tl=t.length();
	for(int i=0,x=t[i]-'a';i<tl;++i,x=t[i]-'a')
	{
		need[x]=true;
	}
	for(int i=0,x=s[i]-'a';i<sl;++i,x=s[i]-'a')
	{
		if(need[x])
		{
			c[x][++cnt[x]]=i;
		}
	}
	for(int i=0;i<26;++i)
	{
		if(need[i]&&(!cnt[i]))
		{
			cout<<"-1";
			return 0;
		}
	}
	ans[0]=c[t[0]-'a'][1];
	for(int i=1,x=t[i]-'a';i<tl;++i,x=t[i]-'a')
	{
		ans[i]=ser(ans[i-1]%sl,x)+ans[i-1]-ans[i-1]%sl;
	}
	cout<<ans[tl-1]+1;
	return 0;
}


Measured memory_bytes: 19920
#include <iostream>
using namespace std;
long n, m, l, a[100][100], b, c[100][100];
int main () {
	cin >> n >> m >> l;
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	
	for (int i = 0; i < m; i++)
		for (int j = 0; j < l; j++) {
			cin >> b;
			for (int k = 0; k < n; k++)
				c[k][j] += a[k][i] * b;
		}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l - 1; j++)
			cout << c[i][j] << " ";
		cout << c[i][l -1] << "\n";
	}
}


Measured memory_bytes: 3252
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val s = sc.next()
    val t = sc.next()


    var best = ""
    for (i in 0..s.length - t.length) {
        if (test(i, s, t)) {
            val res = construct(i, s, t)
            if (best == "" || best > res) best = res
        }
    }
    println(if (best == "") "UNRESTORABLE" else best)

}

fun construct(i: Int, s: String, t: String): String {
    val sb = StringBuilder()
    for (j in 0 until i) {
        if (s[j] == '?') sb.append('a')
        else sb.append(s[j])
    }

    for (j in 0 until t.length) {
        sb.append(t[j])
    }
    for (j in i + t.length until s.length) {
        if (s[j] == '?') sb.append('a')
        else sb.append(s[j])
    }
    return sb.toString()
}

fun test(i: Int, s: String, t: String): Boolean {
    if (i + t.length > s.length) return false
    for (j in 0 until t.length) {
        if (s[i + j] != '?' && s[i + j] != t[j]) return false
    }
    return true
}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}




Measured memory_bytes: 29352
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int a[MAXN],b[MAXN],numa=0,numb=0,num=0;
PR Ans[MAXN];
int main()
{
    int n=read();
    for (int i=1;i<=n;i++) 
    {
    	int x=read();
    	if (x>0) a[++numa]=x;
    	else b[++numb]=x;
	}
	sort(a+1,a+numa+1);
	sort(b+1,b+numb+1);
	
	if (numa==0) 
	{
		for (int i=1;i<numb;i++) 
		    Ans[++num]=MP(b[numb],b[i]),b[numb]-=b[i];
		printf("%d\n",b[numb]);
	}
	else if (numb==0)
	{
		for (int i=2;i<numa;i++) 
		    Ans[++num]=MP(a[1],a[i]),a[1]-=a[i];
		Ans[++num]=MP(a[numa],a[1]),a[numa]-=a[1];
		printf("%d\n",a[numa]);
	}
	else 
	{
		for (int i=2;i<=numa;i++) 
		    Ans[++num]=MP(b[1],a[i]),b[1]-=a[i]; 
		for (int i=1;i<=numb;i++)
		    Ans[++num]=MP(a[1],b[i]),a[1]-=b[i];
		printf("%d\n",a[1]);
	}
	for (int i=1;i<=num;i++) printf("%d %d\n",Ans[i].fi,Ans[i].se);
	return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int main(){
    char x, y;
    cin >> x >> y;
    if(x < y){
        cout << "<" << endl;
    }else if(x == y){
        cout << "=" << endl;
    }else{
        cout << ">" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
N, K = map(int, input().split())

MINL = [0]
for i in range(1, N+1):
    MINL.append(i + MINL[i-1])

MAXL = [N]
j = 1
for i in range(N-1, -1, -1):
    MAXL.append(i + MAXL[j-1])
    j += 1

ans = 0
for i in range(K-1, N+1):
    ans += MAXL[i] - MINL[i] + 1
    ans = ans % (10 ** 9 + 7)
print(ans)

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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  ll a=0;
  ll tmp=n;
  while(tmp>0){
    if(tmp/10==0) a+=tmp%10-1;
    else a+=9;
    tmp/=10;
  }
  ll b=0;
  tmp=n;
  while(tmp>0){
    b+=tmp%10;
    tmp/=10;
  }
  cout<<max(a,b)<<endl;
}

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

int gcd(int x, int y) {
    if (x%y == 0) return y;
    return gcd(y, x%y);
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    printf("%d\n", n+m-gcd(n, m)+1);
}


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


using namespace std;


// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
  void solve(std::istream& in, std::ostream& out)
  {
    int n;
    in >> n;
    vector<int> a(n);
    for(auto&& i : a) {
      in >> i;
      i--;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (i < a[i]) {
        ans += i == a[a[i]];
      }
    }
    out << ans << "\n";
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}




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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll ans=0;
  for(ll i=1;i<=1100000;i++){
    if(n%i==0){
      ll k=n/i-1;
      if(k>i) ans+=k;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)
	fmt.Println(solve(A, B, C))
}

func solve(A, B, C int) int {
	d := C - (A - B)
	if d < 0 {
		return 0
	} else {
		return d
	}
}

Measured memory_bytes: 512