akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int in[128], out[128];

struct UnionFind {
  vector<int> data;
  UnionFind(int v) : data(v, -1) { }
  int root(int x) {
    // < ? = の順に優先順位が高い
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  void merge(int x, int y) {
    x = root(x), y = root(y);
    if(x != y) {
      if(size(y) > size(x)) swap(x, y); // 例のテク
      data[x] += data[y]; data[y] = x;
    }
  }
  int size(int x) {
    return -data[root(x)];
  }
  int count_union() {
    int res = 0;
    for(int i = 0; i < (int)data.size(); i++) res += (data[i] < 0);
    return res;
  }
};

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    fill(in, in + 128, 0);
    fill(out, out + 128, 0);
    UnionFind uf(128);
    char fst;
    for(int i = 0; i < N; ++i) {
      string s; cin >> s;
      in[s[0]]++; out[s[s.size()-1]]++;
      uf.merge(s[0], s[s.size()-1]);
      if(i == 0) fst = s[0];
    }
    bool ok = true;
    for(int i = 0; i < 128; ++i) {
      if(in[i] != out[i]) ok = false;
      if(in[i] > 0 && uf.same(fst, i) == false) ok = false;
    }
    cout << (ok ? "OK" : "NG") << endl;
  }
}

Measured memory_bytes: 1200
def candidates(n):
    m = [True for _ in range(n + 1)]
    m[0] = False
    m[1] = False

    for i in range(2, n + 1):
        if not m[i]:
            continue
        
        for j in range(i * 2, n + 1, i):
            m[j] = False

    c = []

    for i, x in enumerate(m):
        if x and i % 5 == 1:
            c.append(i)
    
    return c

def main():
    c = candidates(55555)
    n = int(input())
    print(*c[:n])

main()

Measured memory_bytes: 3608
n,k = gets.split.map(&:to_i)

ans = 0

#modKがk/2
if k%2==0
  cnt = 0
  (1..n).each{|i|
    if i%k==k/2
      cnt+=1
    end
  }
  ans += cnt*cnt*cnt
end

#modKが0
cnt = 0
(1..n).each{|i|
  if i%k==0
    cnt+=1
  end
}
ans += cnt*cnt*cnt

p ans

Measured memory_bytes: 1788
def resolve():
    a, b = map(int, input().split())
    if a == 1:
        a *= 100
    if b == 1:
        b *= 100
    if a < b:
        print("Bob")
    elif a > b:
        print("Alice")
    else:
        print("Draw")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cinit(N):
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

X,Y = map(int, input().split())
if (X+Y)%3==0and(X<Y*2 or Y<X*2):
    cinit((X+Y)//3)
    p = (min(X,Y)*2 - max(X,Y))//3
    print(cmb((X+Y)//3,p,mod))
else:
    print(0)

Measured memory_bytes: 82424
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))



a = cina()
a.sort()
if a[0]+a[1]==a[2]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
n = int(input())
summer = [list(map(int, input().split())) for _ in range(n)]
dp = [[summer[0][0], summer[0][1], summer[0][2]]]
for i in range(1,n):
    dp.append([summer[i][0] + max(dp[i-1][1], dp[i-1][2]), summer[i][1] + max(dp[i-1][0], dp[i-1][2]), summer[i][2] + max(dp[i-1][0], dp[i-1][1])])
print(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    S w;
    cin >> w;
    vc s;
    rp(i,w.size()){
        s.pb(w.at(i));
    }
    sort(all(s));
    rp(i,s.size()){
        int cnt=1;
        while(i<s.size()-1&&s.at(i)==s.at(i+1)){
            i++;
            cnt++;
        }
        if(cnt%2!=0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::string s;
  cin >> s;
  int64_t result = 0;
  std::stack<char> stack;
  for (int i = 0; i < s.size(); i++) {
    if (stack.empty()) {
      stack.push(s[i]);
    } else if (stack.top() == s[i]) {
      stack.push(s[i]);
    } else {
      stack.pop();
      result += 2;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

int main(){

	int Math,Greedy,Geo,DP,Graph,Oth,type_1,type_2,type_3,type_4,table[3],type_5;

	while(true){
		scanf("%d %d %d %d %d %d",&Math,&Greedy,&Geo,&DP,&Graph,&Oth);
		if(Math == 0 && Greedy == 0 && Geo == 0 && DP == 0 && Graph == 0 && Oth == 0)break;

		type_1 = Math+DP;
		type_2 = Greedy+Graph;
		type_3 = Geo+Oth;

		//????????±?????°????????????????????????
		type_4 = min(min(type_1,type_2),type_3);

		type_1 -= type_4;
		type_2 -= type_4;
		type_3 -= type_4;

		table[0] = type_1%3;
		table[1] = type_2%3;
		table[2] = type_3%3;

		for(int i = 1; i <= 2; i++){
			for(int k = 2; k >= i; k--){
				if(table[k] < table[k-1])swap(table[k],table[k-1]);
			}
		}

		if(table[0] == 0 && table[1] == 2 && table[2] == 2 && type_4 > 0){
			type_5 = type_4 + (type_1/3 + type_2/3 + type_3/3 + 1);
		}else{
			type_5 = type_4 + (type_1/3 + type_2/3 + type_3/3);
		}

		printf("%d\n",type_5);
	}
    return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
	FIO;
	int t = 1;
	//cin >> t;
	while (t--) {
		string s;
		cin >> s;
		ll a = (s[0]-'0')*10 + s[1]-'0';
		ll b = (s[2]-'0')*10 + s[3]-'0';
		if(a <= 12 && a > 0 && b <= 12 && b > 0){
			cout << "AMBIGUOUS\n";
		}else if(a <= 12 && a > 0){
			cout << "MMYY\n";
		}else if(b <= 12 && b > 0){
			cout << "YYMM\n";
		}else cout << "NA\n";
	}


	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);

using namespace std;

// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// print vector
template <typename T> 
inline ostream &operator<<(ostream &out, vector<T> &a) {
    for(auto &x : a) out << x <<" ";
    return out;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}
#define MOD 1000000007
vector<string> grid;
vector<vector<int> > dp;

int solve(int h, int w)
{
    if(h<0 || w<0)
        return -1;
    if(h==0 && w==0)
    {
        dp[h][w]=1;
        return 1;
    }
    if(dp[h][w]!=0)
        return dp[h][w];
    if(grid[h][w]=='#')
        return -1;
    int fst=solve(h-1,w);
    int lst=solve(h,w-1);
    if(fst==-1 && lst==-1)
        dp[h][w]=-1;
    else if(fst==-1 || lst==-1)
        dp[h][w]=max(lst,fst);
    else
        dp[h][w]=(lst+fst)%MOD;
    return dp[h][w];
}

int main()    
{
    #ifdef SANS
        freopen("ongoingin.txt","r",stdin);
        freopen("ongoingout.txt","w",stdout);
    #endif
    fast
    int t=1;
    // cin>>t;
    while(t--)
    {
        int h,w;
        cin>>h>>w;
        grid.resize(h);
        dp.resize(h);
        for(int i=0; i<h; i++)
        {
            dp[i].resize(w,0);
            cin>>grid[i];
        }
        int ans=solve(h-1,w-1);
        cout<<max(ans,0);
    }
    #ifdef SANS
        cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
    #endif
}

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

long long H, W, N, x[100], y[100], ID, mod = 1000000009;
long long pre[64][80][80]; vector<long long>A, P;

void precount() {
	for (int i = 0; i < 64; i++) { for (int j = 0; j < 80; j++) { for (int k = 0; k < 80; k++) pre[i][j][k] = 0; } }
	for (int i = 0; i < H; i++) {
		if (i - 1 >= 0) pre[0][i][i - 1] = 1;
		pre[0][i][i] = 1;
		if (i + 1 < H) pre[0][i][i + 1] = 1;
	}
	for (int t = 0; t < 63; t++) {
		for (int i = 0; i < H; i++) {
			for (int k = 0; k < H; k++) {
				for (int l = 0; l < H; l++) { pre[t + 1][i][l] += pre[t][i][k] * pre[t][k][l]; pre[t + 1][i][l] %= mod; }
			}
		}
	}
}
void solve(long long rep) {
	for (int i = 0; i < 62; i++) {
		if ((rep / (1LL << i)) % 2 == 0) continue;
		vector<long long>B; B.resize(H, 0);
		for (int j = 0; j < H; j++) {
			for (int k = 0; k < H; k++) { B[k] += P[j] * pre[i][j][k]; B[k] %= mod; }
		}
		P = B;
	}
}

int main() {
	while (true) {
		ID++; cin >> H >> W >> N; A.clear(); P.clear(); if (H == 0)break;
		for (int i = 1; i <= N; i++) { cin >> x[i] >> y[i]; x[i]--; A.push_back(y[i]); }
		A.push_back(W); sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end());
		precount();
		P.resize(H, 0); P[0] = 1; long long cx = 1;
		for (int i = 0; i < A.size(); i++) {
			solve(A[i] - cx); cx = A[i];
			for (int j = 1; j <= N; j++) { if (y[j] == A[i]) P[x[j]] = 0; }
		}
		cout << "Case " << ID << ": " << P[H - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 6352
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

const ll MOD = 998244353;


vector<ll> factorials;
void init_factorial(int N)
{
    factorials.assign(N+1, 1);
    rep(i, 2, N+1)
    {
        factorials[i] = factorials[i-1] *i;
        factorials[i] %= MOD;
    }
}

ll power_mod(ll n, ll m)
{
    ll res = 1;
    ll base = n;
    while (m > 0)
    {
        if (m&1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        m >>= 1;
    }
    return res;
}

ll inv_mod(ll n)
{
    return power_mod(n, MOD-2);
}

ll comb(ll n, ll m)
{
    m = min(m, n-m);
    ll res = factorials[n];
    res *= inv_mod(factorials[n-m]);
    res %= MOD;
    res *= inv_mod(factorials[m]);
    res %= MOD;
    return res;
}

ll dup_comb(ll n, ll m)
{
    return comb(n+m-1, n-1);
}

int main()
{
    init_factorial(1000000);

    ll N, M, K;
    cin >> N >> M >> K;

    ll res = 0;
    rep(i, 0, K+1)
    {
        if (N-i-1<0) break;
        ll now = M * power_mod(M-1, N-i-1);
        now %= MOD;
        now *= comb(N-1, i);
        now %= MOD;
        // cout << i << ' ' << now << ' ' << comb(N, i) << endl;
        res += now;
        res %= MOD;
    }
    printf("%lld\n", res);
    return 0;
}


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

int kmp[1000010];
char s1[1000010], s2[1000010];

int main() {
    scanf( "%s" , s1 + 1 );
    s2[1] = 'A';
    s2[2] = 'C';
    int len1 = strlen( s1 + 1 );
    int len2 = strlen( s2 + 1 );
    for( int i = 2 ; i <= len2 ; i++ ) {
        int j = kmp[i-1];
        while ( j && s2[j+1] != s2[i] ) j = kmp[j];
        kmp[i] = j + ( s2[j+1] == s2[i] );
    }
    for( int i = 1 , j = 0 ; i <= len1 + 1 ; i++ ) {
        if ( j == len2 ){ printf("Yes\n"); return 0; }
        while ( j && s2[j+1] != s1[i] ) j = kmp[j];
        j += ( s2[j+1] == s1[i] );
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 1000

int main() {
  int i,minj,A[N],a,cnt=0,j;
  scanf("%d",&a);
  for(i=0;i<a;i++)scanf("%d",&A[i]);
  for(i=0;i<a;i++){
    minj=i;
    for(j=i;j<a;j++)if(A[j]<A[minj])minj=j;
    if(minj!=i){
      int b=A[i];
      A[i]=A[minj];
      A[minj]=b;
      cnt++;
    }
  }
  for(i=0;i<a;i++){
    if(i==a-1)printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",cnt);
  return 0;
}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vll a(n+1), b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    rep(i, n) {
        int left = min(a[i], b[i]);
        ans += left;
        a[i] -= left;
        b[i] -= left;
        int right = min(a[i+1], b[i]);
        ans += right;
        a[i+1] -= right;
        b[i] -= right;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<vector>
#include<algorithm>
int main(){
    int n,m,a,b;
    std::vector<std::pair<int,int>> v;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        v.push_back({b,a});
    }
    std::sort(v.begin(),v.end());
    int i=0,ans=0;
    while(i<m){
        b=v[i].first;
        a=v[i].second;
        ans++;
        while(i<m&&v[i].second<b)i++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int k,n;
int a[211111];
signed main(){
	
	cin>>k>>n;
	rep(i,n)cin>>a[i];
	a[n]=a[0]+k;
	int ans=0;
	rep(i,n){
		ans=max(a[i+1]-a[i],ans);
	}
	cout<<k-ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 5005
#define M 20
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
string s;
int dp[N][N];
ll power(ll x,ll y)
{
    ll ret = 1;
    while(y)
    {
        if(y&1)ret = ret*x%MOD;
        x = x*x%MOD;
        y>>=1;
    }
    return ret;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        cin>>s;
        int m = s.length();
        MST(dp,0);
        dp[0][0] = 1;
        FOR(i,0,n-1)
        {
            FOR(j,0,n)
            {
                dp[i+1][j+1] = (dp[i+1][j+1]+2*dp[i][j]%MOD)%MOD;
                dp[i+1][max(0,j-1)] = (dp[i+1][max(0,j-1)]+dp[i][j])%MOD;
            }
        }
        ll ans = dp[n][m];
        ll rev = power(2LL,MOD-2LL);
        FOR(i,1,m)ans = ans*rev%MOD;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
const int N=10000;
int n,a[N],b[N],c[N],cnt,p[N],prime[N],tot;
ll num[505][505];
void shai()
{
	for (int i=2;i<N;i++)
	{
		if (!p[i]) prime[++tot]=i;
		for (int j=1;j<=tot&&prime[j]*i<N;j++)
		{
			p[prime[j]*i]=1;
			if (i%prime[j]==0) break;
		}
	}
}
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll calc(int x,int y)
{
	ll Lcm=0;
	for (int i=0;i<4;i++)
	{
		int xx=x+dx[i],yy=y+dy[i];
		if (xx<1||yy<1||xx>n||yy>n) continue;
		if (!Lcm) Lcm=num[xx][yy];else Lcm=lcm(num[xx][yy],Lcm);
	}
	return Lcm+1;
}
int main()
{
	shai();
	scanf("%d",&n);
	if (n==2){
		printf("4 7\n23 10\n");
		return 0;
	}
	for (int i=2;i<=2*n;i+=2) a[i]=prime[++cnt];
	for (int i=0;i<=n-1;i+=2) b[i]=prime[++cnt];
	for (int i=2;i<=n-1;i+=2) c[i]=prime[++cnt];
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=n;j++)
	  if ((i+j)%2==0)
	  {
	  	  if (i<=j) num[i][j]=(ll)a[i+j]*b[j-i];
	  	  else num[i][j]=(ll)a[i+j]*c[i-j];
	  }
	for (int i=1;i<=n;i++)
	{
	   for (int j=1;j<=n;j++)
	   {
	  	 if (num[i][j]) printf("%lld ",num[i][j]);
	  	 else printf("%lld ",calc(i,j));
	   }
	   puts("");	
	}
	return 0;
}

Measured memory_bytes: 5120
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

alias sread = () => readln.chomp();
enum MOD = 10 ^^ 9 + 7;

void main()
{
    long N,K;
    scan(N,K);
    char[] S = sread().dup;
    S[K-1] -= 'A' - 'a';
    writeln(S);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#include<string>
using namespace std;

#define ll long long
typedef pair<ll , ll > pii;
const int MOD = 998244353;
const int N=500004;

vector<int> BIT;

void update(int i, int add)
{
    while (i > 0 && i < BIT.size())
    {
        BIT[i] += add;
        i = i + (i & (-i));
    }
}

int sum(int i)
{
    int ans = 0;
    while (i > 0)
    {
        ans += BIT[i];
        i = i - (i & (-i));
    }

    return ans;
}
int findKthSmallest(int k)
{
    int l = 0;
    int h = BIT.size();
    while (l < h)
    {
        int mid = (l + h) / 2;
        if (k <= sum(mid))
            h = mid;
        else
            l = mid+1;
    }

    return l;
}

void insertElement(int x)
{
    update(x, 1);
}

void deleteElement(int x)
{
    update(x, -1);
}

int findRank(int x)
{
    return sum(x);
}

///


void min_self(int &a , int b){
    a=min(a,b);
}

int add(int x, int y)
{
    return (x + y) % MOD;
}

int sub(int x, int y)
{
    return add(x, MOD - y);
}

int mul(int x, int y)
{
    return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
    int z = 1;
    while(y > 0)
    {
        if(y % 2 == 1)
            z = mul(z, x);
        x = mul(x, x);
        y /= 2;
    }
    return z;
}

int inv(int x)
{
    return binpow(x, MOD - 2);
}

int fact[N];

int C(int n, int k)
{
    return mul(fact[n], inv(mul(fact[k], fact[n - k])));
}
/////-----//////
int calc(int e){
    if( e == 0) return 0;
    int ans=0;
    for(int i=1; i<=100; i++){
        if(e>=i){
            ans++;
            e-=i;
        }
        else{
            break;
        }
    }
    return ans;
}




int  main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   //freopen("input.txt", "r", stdin);
   ll n ; cin>>n;
   ll ans=0;
   for(ll p=2; p*p<=n; p++){
       int e=0;
       while(n%p == 0){
           e++;
           n/=p;
       }
       ans+=calc(e);
   }
   if(n>1){
       ans+=1;
   }
   cout<<ans;
   return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define D isdigit(c=getchar())
inline int getint(){
    int c,l=0,x;
    for (;!D;l=c)if(c==EOF)return 1<<31;
    for (x=c-'0';D;x=x*10+c-'0')if(c==EOF) break;
    return l=='-'?-x:x;
}
int dist[16][16],f[1<<16],dp[16][1<<16],g[1<<16][16],n,m;
int main(){
	n=getint();m=getint();
	for(int i=1;i<=m;i++){
		int x=getint(),y=getint();
		dist[x][y]=dist[y][x]=getint();
	}
	for(int i=0;i<(1<<n);i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				if((i&(1<<j-1))&&(!(i&(1<<k-1))))f[i]+=dist[j][k];
	memset(dp,0x3f,sizeof(dp));
	for(int i=0;i<(1<<n);i++)
		if(i&1){
			dp[1][i]=f[i];
			for(int j=1;j<=n;j++)if(dist[1][j])g[i][j]=1;
		}
	for(int i=1;i<(1<<n);i++)if(i&1){
		for(int k=2;k<=n;k++)if(i&(1<<k-1)){
			for(int j=i-(1<<k-1);j;j=j-1&i-(1<<k-1))if(j&1){
				int l=g[j][k];if(!l)continue;
				dp[k][i]=min(dp[k][i],dp[l][j]-2*dist[l][k]+f[i-j]);
			}
		//	printf("dp[%d][%d]=%d\n",k,i,dp[k][i]);
		}
		for(int k=1;k<=n;k++){
			int mx=0x3f3f3f3f;g[i][k]=0;
			for(int l=1;l<=n;l++)if(i&(1<<l-1)&&dist[l][k]&&dp[l][i]-2*dist[l][k]<mx){
				mx=dp[l][i]-2*dist[l][k];g[i][k]=l;
			}
		}
	}
	printf("%d\n",dp[n][(1<<n)-1]/2);
	return 0;
}
//MainFunction


Measured memory_bytes: 8576
#include<stdio.h>

int main()
{
  int N,c=0,A[100],i,j,X,flag=1;
 
  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
      scanf("%d",&A[i]);
    }

  while(flag){
    flag=0;

    for(j=N-1;j>=1;j--)
      {
	if(A[j]<A[j-1])
	  {
	    X=A[j];
	    A[j]=A[j-1];
	    A[j-1]=X;
	    flag=1;
	    c++;
	  }
      }
  }


  for(i=0;i<N-1;i++)
    {
      printf("%d ",A[i]);
    }

  printf("%d\n",A[N-1]);
  printf("%d\n",c);
  return 0;
}

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int h,a;
    cin>>h>>a;
    int t = 0;
    for(int i = 0 ; i < a ; i++)
    {
        int A;
        cin>>A;
        t+=A;
    }
    if(t>=h)
        cout<<"Yes\n";
    else
        cout<<"No\n";

}

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

namespace ConsoleApp15
{
    class Class402
    {
        static void Main()
        {
            var AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = AB[0], B = AB[1];
            Console.WriteLine(Math.Max(A+B,Math.Max(A-B,A*B)));
        }
    }
}


Measured memory_bytes: 28196
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  int n, m;
  cin >> n >> m;
  vi s(n), t(m);
  rep(i, n) cin >> s[i];
  rep(j, m) cin >> t[j];
  vector<vector<ll> > data(n, vector<ll>(m, 0));
  vector<vector<ll> > sum(n, vector<ll>(m, 0));
  if (s[0] == t[0]) {
    data[0][0] = 1;
  } else {
    data[0][0] = 0;
  }
  sum[0][0] = data[0][0];
  REP(i, 1, n) {
    if (s[i] == t[0]) {
      data[i][0] = 1;
    } else {
      data[i][0] = 0;
    }
    sum[i][0] = (sum[i - 1][0] + data[i][0]) % MOD;
  }
  REP(j, 1, m) {
    if (t[j] == s[0]) {
      data[0][j] = 1;
    } else {
      data[0][j] = 0;
    }
    sum[0][j] = (sum[0][j - 1] + data[0][j]) % MOD;
  }
  REP(i, 1, n) {
    REP(j, 1, m) {
      if (s[i] == t[j]) {
        data[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
      } else {
        data[i][j] = 0;
      }
      sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] + MOD - sum[i - 1][j - 1] +
                   data[i][j]) %
                  MOD;
    }
  }

  cout << (sum[n - 1][m - 1] + 1) % MOD << endl;
  return 0;
}


Measured memory_bytes: 62976
#include<bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define loop(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define br                break
#define con               continue

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
 
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

priority_queue<pii, vector<pii>, greater<pii> >q;
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output1.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int sum=0;
    int a[n+1];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum=(sum+a[i])%M;
    }
    int ans =0;

    loop(i,0,n){
        sum = (sum-a[i]+M)%M;
        ans = (ans+ sum*a[i])%M;
    }
    cout<<ans<<endl;
    
 
}

Measured memory_bytes: 5188
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

template<typename Monoid> class SegTree {
  using T = typename Monoid::value_type;

  Monoid m;
  std::vector<T> tree; // 1-indexed
  int size = 1;

public:
  SegTree(const int n = 0) {
    while (size < n) size *= 2;
    tree.assign(size * 2, m.id());
  }

  template<typename InputIterator> SegTree(InputIterator first, InputIterator last) {
    int n = std::distance(first, last);
    while (size < n) size *= 2;
    tree.resize(size * 2, m.id());
    std::copy(first, last, tree.begin() + size);
    for (int i = size - 1; i >= 1; i--) tree[i] = m(tree[i * 2], tree[i * 2 + 1]);
  }

  T fold(int l, int r) { // [l, r)
    T accl = m.id(), accr = m.id();
    for (l += size, r += size; l < r; l /= 2, r /= 2) {
      if (l & 1) accl = m(accl, tree[l++]);
      if (r & 1) accr = m(tree[--r], accr);
    }
    return m(accl, accr);
  }

  void update(int i, const T &x) {
    tree[i += size] = x;
    while (i /= 2) tree[i] = m(tree[i * 2], tree[i * 2 + 1]);
  }

  const T &operator[](int i) const { return tree[i + size]; }
};

template<typename T, T upperInf = std::numeric_limits<T>::max()> struct minMonoid {
  using value_type = T;
  constexpr value_type id() { return upperInf; }
  constexpr value_type operator()(const value_type &a, const value_type &b) { return a < b ? a : b; }
};

main {
  int n, q;
  cin >> n >> q;
  SegTree<minMonoid<int, 2147483647>> t(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com) {
      cout << t.fold(x, y + 1) << endl;
    } else {
      t.update(x, y);
    }
  }
}

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

int main(int argc, char const *argv[])
{
	string n; cin >> n;
	for (auto u : n) cout << ((u == '1') ? "9" : "1");
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var s = sc.next();
		sc.close();

		var r = 0;
		var g = 0;
		var b = 0;
		var rc = new int[n];
		var gc = new int[n];
		var bc = new int[n];
		for (var i = n - 1; i >= 0; i--) {
			if (s.substring(i, i + 1).equals("R")) {
				r++;
			} else if (s.substring(i, i + 1).equals("G")) {
				g++;
			} else {
				b++;
			}
			rc[i] = r;
			gc[i] = g;
			bc[i] = b;
		}

		var sum = 0L;
		for (var i = 0; i < n - 2; i++) {
			var s1 = s.substring(i, i + 1);
			for (var j = i + 1; j < n - 1; j++) {
				var s2 = s.substring(j, j + 1);
				if (!s1.equals(s2)) {
					var s3 = "RGB".replace(s1, "").replace(s2, "");
					if (s3.equals("R")) {
						sum += rc[j + 1];
					} else if (s3.equals("G")) {
						sum += gc[j + 1];
					} else {
						sum += bc[j + 1];
					}
					var k = j + (j - i);
					if (k < n) {
						var s4 = s.substring(k, k + 1);
						if (s3.equals(s4)) {
							sum--;
						}
					}
				}
			}
		}

		System.out.println(sum);
	}
}

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

int mod = 1e9 + 7;

ll modinv(ll a, ll m) {
  ll b = m;
  ll u = 1;
  ll v = 0;
  
  while (b > 0) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  
  u %= m;
  if (u < 0) u += m;
  return u;
}

int main() {
  int X, Y;
  cin >> X >> Y;
  
  if (X * 2 - Y < 0 || Y * 2 - X < 0 || (2 * X - Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  
  ll a = (2 * Y - X) / 3;
  ll b = (2 * X - Y) / 3;
  
  ll ans = 1;
  for (int i = 0; i < a; i++) {
    ans = ((ans % mod) * ((a + b - i) % mod)) % mod;
  }
  
  for (int i = 1; i <= a; i++) {
    ans = ((ans % mod) * (modinv(i, mod) % mod)) % mod;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#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()
{
    int n, k;
    cin >> n >> k;
    if (n % k == 0)
        cout << 0 << endl;
    else
        cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3616
N,M = map(int,input().split())
H = list(map(int,input().split()))
HH = [set() for x in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    A -= 1
    B -= 1
    HH[A].add(B)
    HH[B].add(A)

a = 0
for i in range(N):
    iH = H[i]
    h = 1
    for b in HH[i]:
        bH = H[b]
        if bH >= iH:
            h = 0
    a += h

print(a)

Measured memory_bytes: 106608
'use strict'


const check = (n) => {
  if (n < 2) return false
  let sqrt = Math.floor(Math.sqrt(n))
  for(var i = 2; i <= sqrt; ++i) {
    if(n % i === 0) return false
  }
  return true
}  

function Main(input) {
  input = parseInt(input.trim())

  while(true) {
    if(check(input)) {
      console.log(input)
      return
    }
    input += 1
  }

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main() {
	int n,m;
	cin>>n>>m;
	int a[n];
	int s=0;
	for(int i=0;i<n;i++){
	    cin>>a[i];
	    s=s+a[i];
	}
	
	int z=s/(4*m);
    if(s%2!=0){
        z=z+1;
    }
	int cnt=0;
	for(int i=0;i<n;i++){
	    if(a[i]>=z){
	        cnt++;
	    }
	}
	if(cnt>=m){
	    cout<<"Yes"<<endl;
	}else{
	    cout<<"No"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
ss = input()
ll = ss.split()
s = ll[0]
t = ll[1]
aa = input()
lll = aa.split()
a = int(lll[0])
b = int(lll[1])
uu = input()
if uu == s:
    a = a-1
else:
    b = b-1
print(a,end = " ")
print(b)


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


signed main(){
    gearup;
    string s,t; cin >> s >> t;
    int a,b; cin >> a >> b;
    string u;cin>>u;
    if(u == s)a = max(a-1,0);
    else b = max(b-1,0);
    cout << a << " " << b << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

string A, B;
int main() {
  while (cin >> A >> B) {
	if (A.size() < B.size()) puts("LESS");
	else if (A.size() > B.size()) puts("GREATER");
	else if (A < B) puts("LESS");
	else if (A > B) puts("GREATER");
	else puts("EQUAL");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

int H,W,K;
pair<int,int> st,ter;
vector<vector<char>> c;
vector<vector<int>> d;
queue<pair<long long,long long>> q;
vector<pair<int,int>> direction={{1,0},{0,1},{-1,0},{0,-1}};

long long bfs(){
    pair<long long,long long> node;
    q.push(st);
    d[st.first][st.second]=0;
    while(!q.empty()){
        int size=q.size();
        for(int i=0;i<size;i++){
            node=q.front();
            //cout<<node.first<<" "<<node.second<<endl;
            q.pop();
            for(int j=0;j<4;j++){
                for(long long k=1;k<=K;k++){
                    long long a=node.first+k*direction[j].first;
                    long long b=node.second+k*direction[j].second;
                    if(a<0||a>=H||b<0||b>=W||c[a][b]=='@'||d[a][b]<=d[node.first][node.second]){
                        break;
                    }else{
                        if(d[a][b]>d[node.first][node.second]+1){
                            q.push({a,b});
                            d[a][b]=d[node.first][node.second]+1;
                            if(a==ter.first && b==ter.second){
                                return d[a][b];
                            }
                        }
                    }
                }
            }
        }
    }
    return -1;
    
}

int main(){
    cin>>H>>W>>K;
    cin>>st.first>>st.second>>ter.first>>ter.second;
    st.first--;st.second--;ter.first--;ter.second--;

    c.assign(H,vector<char>(W));
    d.assign(H,vector<int>(W,H*W+1));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>c[i][j];
        }
    }
    cout<<bfs()<<endl;

    return 0;
}

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

long long gcd(long long a, long long b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

const int N = 100007;
long long v[N];

int main(){
	long long n, m;
	scanf("%lld %lld", &n, &m);
	long long mmc = 1LL;
	long long mx = 0;
	for (int i=0; i<n; i++){
		scanf("%lld", &v[i]);
		v[i] /= 2;
		mmc = (mmc * v[i]/gcd(mmc, v[i]));
		if(mmc > m) {
			printf("0\n");
			return 0;
		}
	}

	for(int i = 0; i < n; ++i) {
		long long p2 = mmc/v[i];
		// p2 so pode ser impar
		if(p2%2 == 0) {
			printf("0\n");
			return 0;
		} 
	}

	
	printf("%lld\n", (m/mmc + 1)/2);

}

Measured memory_bytes: 1024
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  long long int n,a,b;
  cin>>n>>a>>b;
  if(a+b==0){
    cout<<0<<"\n";  
  } 
  else if(a==0){
    cout<<0<<"\n";  
  }
  else if(b==0){
    cout<<n<<"\n";  
  }
  else{
    long long int t = (n/(a+b))*a;
    long long int p =min(a,(n%(a+b)));
    cout<<t+p<<"\n"; 
  }
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int a,b;cin>>a>>b;

    int c = a+b;
    if(c>=10){
      cout<<"error"<<endl;
    }else{
      cout<<c<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;
const int MOD = 1000000007;

ll dp[100100];

int main()
{

    int N, M;
    cin >> N >> M;

    int prev = -1;
    for (int i = 0; i < M; i++)
    {
        int a;
        cin >> a;
        if (prev == a)
        {
            cout << "0" << endl;
            return 0;
        }
        dp[a++] = -1;

        prev = a;
    }

    if (dp[1] == 0 && dp[2] == 0)
    {
        dp[1] = 1;
        dp[2] = 2;
    }

    if (dp[1] == -1 && dp[2] == 0)
    {
        dp[1] = -1;
        dp[2] = 1;
    }

    if (dp[1] == 0 && dp[2] == -1)
    {
        dp[1] = 1;
        dp[2] = -1;
    }

    for (int i = 3; i <= N; i++)
    {

        if (dp[i] == -1)
        {
            continue;
        }
        else if (dp[i - 1] == -1)
        {
            dp[i] = dp[i - 2] % MOD;
        }
        else if (dp[i - 2] == -1)
        {
            dp[i] = dp[i - 1] % MOD;
        }
        else
        {
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        }
    }

    cout << dp[N] << endl;
    // cout << dp << endl;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = float("inf")

for i in range(K, N+1):
  if x[i-K] * x[i-1] >= 0:
    ans = min(ans, max(abs(x[i-K]), abs(x[i-1])))
  else:
    ans = min(ans, x[i-1] - x[i-K] + min(abs(x[i-K]), abs(x[i-1])))

print(ans)

Measured memory_bytes: 14228
from collections import deque
n = int(input())

A = []
for _ in range(n):
    a = int(input())
    A.append(a)
A_ = deque()

l = 0
r = len(A)-1

A = sorted(A)

for _ in range(n):
    if len(A_) == 0:
        A_.append(A[r])
        r-=1
        continue

    todo = "ll"
    bestVal = abs(A[l]-A_[0])
    if(abs(A[l]-A_[-1]) > bestVal):
        bestVal = abs(A[l]-A_[-1])
        todo = "lr"
    if(abs(A[r]-A_[-1]) > bestVal):
        bestVal = abs(A[r]-A_[-1])
        todo = "rr"
    if(abs(A[r]-A_[0]) > bestVal):
        bestVal = abs(A[r]-A_[0])
        todo = "rl"

    if todo == "ll":
        A_.appendleft(A[l])
        l+=1
    if todo == "lr":
        A_.append(A[l])
        l+=1
    if todo == "rr":
        A_.append(A[r])
        r-=1
    if todo == "rl":
        A_.appendleft(A[r])
        r-=1
ans = 0
for i in range(len(A_)-1):
    ans += abs(A_[i+1]-A_[i])
print(ans)


Measured memory_bytes: 8592
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

vector<ll> getDivisor(ll n)
{
    vector<ll> ret;

    for (ll i = 1; i <= (int)(sqrt(n) + 0.5); i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (n != i * i) ret.push_back(n / i);
        }
    }
    return ret;
}
int main(int, char**)
{
    ll n;

    cin >> n;

    vector<ll> divisors1 = getDivisor(n);
    vector<ll> divisors2 = getDivisor(n-1);

    ll ans = divisors2.size() - 1;
    ll tmp;
    for (auto x : divisors1) {
        if (x == 1) continue;
        tmp = n;
        while (tmp % x == 0) tmp /= x;
        if (tmp % x == 1) ans++;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

int b[100001],a[100001];
int main(){
	int n;
	ri(n);
	FOR(i,0,n){
		ri(a[i]);
	}
	sort(a,a+n);
	reverse(a,a+n);
	int maxi=a[0];
	vector<ii> v;
	FOR(i,1,n){
		v.pb({a[i],maxi-a[i]});
	}
	int ans=v[0].F;
	FOR(i,0,n-1){
		int lo=i,hi=v.size()-1;
		while(lo<hi){
			int mid=(lo+hi+1)/2;
			if(v[mid].S>=v[i].F) hi=mid-1;
			else lo=mid;
		}
		if(lo==i){
			ans=v[i].F;
			break;
		}
	}
	printf("%d %d\n",maxi,ans);

}

Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    ll N,K,X[100007],ans=MOD;cin >> N >> K;
    rep(i,N){
        cin >> X[i];
    }
    rep(i,N-K+1){
        ans=min(ans,X[i+K-1]-X[i]+min(abs(X[i]),abs(X[i+K-1])));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int n;
	cin >> n;
	VI a(n), ans(n);
	REP(i, n) {
		cin >> a[i];
	}
	int m = 0, p = 0;
	for (int i = n; i > 0; i--) {
		for(int j = 1;1;j++) {
			if (i * j > n)
				break;
			p += a[i * j - 1];
		}
		p %= 2;
		a[i - 1] = p;
		if (a[i - 1]) {
			ans[m] = i;
			m++;
		}
		p = 0;
	}
	cout << m << '\n';
	REP(i, m)
		cout << ans[i] << '\n';
}

Measured memory_bytes: 2432