akhauriyash/Code-Regression huggingface dataset:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    S = [list(input().rstrip()) for _ in range(N)]

    uf = UnionFindTree(N*2)
    for i in range(N):
        for j in range(i+1,N):
            if S[i][j] == '1':
                uf.union(i, j+N)
                uf.union(i+N, j)
    
    for i in range(N):
        if uf.same(i, i+N):
            print(-1)
            exit()

    D = [[10**9] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if i == j: D[i][j] = 0
            elif S[i][j] == '1': D[i][j] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                D[i][j] = min(D[i][j], D[i][k] + D[k][j])
    d_max = max(max(s) for s in D)
    print(d_max+1)

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x

    def same(self, x, y): return self.find(x) == self.find(y)
    def size(self, x): return -self.parent[self.find(x)]

if __name__ == '__main__':
    main()

Measured memory_bytes: 44892
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
long long ans[100005],s[100005];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&s[i]);
        if(i%2) ans[1]+=s[i];
        else ans[1]-=s[i];
    }
    ans[1]/=2;
    for(int i=2;i<=n;i++) ans[i]=s[i-1]-ans[i-1];
    for(int i=1;i<=n;i++) printf("%lld ",ans[i]*2);
    printf("\n");
}


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

using namespace std;

long long dp[110][5][2];

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

  string s;
  int k;
  cin >> s >> k;
  dp[0][0][1] = 1;
  for (int i = 1; i <= s.size(); ++i) {
    for (int j = 0; j <= k; ++j) {
      int x = s[i - 1] - '0';
      if (x == 0) {
        dp[i][j][1] = dp[i - 1][j][1];
        dp[i][j][0] = dp[i - 1][j][0];
      } else {
        dp[i][j][0] = dp[i - 1][j][0] + dp[i - 1][j][1];
      }
      if (j) {
        dp[i][j][0] += 9 * dp[i - 1][j - 1][0];
        if (x != 0) {
          dp[i][j][0] += (x - 1) * dp[i - 1][j - 1][1];
          dp[i][j][1] += dp[i - 1][j - 1][1];
        }
      }
    }
  }
  cout << dp[s.size()][k][0] + dp[s.size()][k][1];

  return 0;
}

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

int main(int argc, const char * argv[]) {
    int P, Q, R;
    
    cin >> P >> Q >> R;
    
    int ABC = P + Q;
    int ACD = R + Q;
    int BAC = P + R;
    int BCA = Q + R;
    int CBA = Q + P;
    
    int minv = min({ABC, ACD, BAC, BCA, CBA});
    
    cout << minv << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;
 
int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;
 
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N;
	vector<int>x(N);
	vector<int>y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	int ans = MOD;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j)continue;
			int cx = x[j] - x[i];
			int cy = y[j] - y[i];
			int cnt = 0;
			for (int k = 0; k < N; k++) {
				for (int l = 0; l < N; l++) {
					if (cx == x[l] - x[k] && cy == y[l] - y[k])cnt++;
				}
			}
			ans = min(ans, N - cnt);
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
using namespace std;

int main(){
	long long N, A, B;
	cin >> N >> A >> B;
	if (B < A){
		cout << "0\n";
		return 0;
	}
	if (A == B){
		cout << 1 << "\n";
		return 0;
	}
	if (N == 1){
		cout << 0 << "\n";
		return 0;
	}
	long long minn, maxx;
	minn = A + B + (N-2)*A;
	maxx = A + B + (N-2)*B;

	if (maxx - minn + 1 < 0){
		cout << 0 << "\n";
		return 0;
	}
	cout << maxx - minn + 1 << "\n";


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;ll a[100000],b[100000];ll ans=0;ll k;
void update(ll p){ll t=0;ll t1=t;
	for(int i=1;i<=n;i++){
		b[i]=a[i]%p;t+=b[i];
	}
	sort(b+1,b+1+n,greater<ll>());t1=t;
	for(int i=1;i<=t1/p;i++){
		t-=b[i];
	
	}if(t<=k) {
			ans=max(ans,p);return;	}
}
int main(){
	scanf("%d%lld",&n,&k);ll sum=0;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);sum+=a[i];
	}
	for(ll i=1;i*i<=sum;i++){
		if(sum%i==0){
			update(i);
			update(sum/i);
		}
	}cout<<ans;
}

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

int main(){
 	int n ;
  	cin >> n ;
  	vector <int> v(n) ;
  	for(auto &it : v)cin >> it ;
  	vector <int> dp(n) ;
  	dp[0] = 0 ;
  	//int sum = 0 ;
  	//int val = 0 ;
  	for(int i = 1 ;i<n;i++){
    	if( i == 1 )dp [i] = abs(v[i] - v[i-1]) ;
      	else {
        	//val = min( abs(v[i] - v[i-1]) , abs(v[i] - v[i-2]) ) ;
          	dp[i] =  min(abs(v[i] - v[i-1]) + dp[i-1] ,abs(v[i] - v[i-2])  + dp[i-2]) ;
        }

    }
  	//for(auto a : dp)cout << a << " " ;
 	cout << dp [n-1] ;
  return 0 ;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cassert>

#define ll long long
#define db(x) cout << "> " << #x << " : " << x << endl;

const int N = 2010;
using namespace std;

int n;
ll z, w;
ll a[N];

ll dp1[N], dp2[N];
bool vis1[N], vis2[N];

ll f1(int);
ll f2(int);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> z >> w;
	
	a[0] = w;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	
	cout << f1(1) << '\n';
	return 0;
}

ll f1(int idx)
{
	assert(idx <= n);
	
	if(vis1[idx])
		return dp1[idx];
				
	ll res = abs(a[n] -a[idx -1]);
	
	for(int i = idx; i < n; i++)
		res = max(res, f2(i +1));
	
	vis1[idx] = 1;
	dp1[idx] = res;
	return res;
}

ll f2(int idx)
{
	assert(idx <= n);
	
	if(vis2[idx])
		return dp2[idx];
		
	ll res = abs(a[n] -a[idx -1]);
	
	for(int i = idx; i < n; i++)
		res = min(res, f1(i +1));
	
	vis2[idx] = 1;
	dp2[idx] = res;	
	return res;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
 
int main(){
 
    int n;
    cin >> n;

    vector<int> p(n);
    rep(i,n) cin >> p[i];
    vector<int> q(n);
    rep(i,n) cin >> q[i];
    vector<int> init_perm(n);
    rep(i,n) init_perm[i] = i+1;
    vector<int> current_perm(init_perm);

    int a = 0, b = 0;

    do{
        a++;
        if(current_perm == p) break;
    } while( next_permutation(begin(current_perm), end(current_perm)));

    current_perm = init_perm;
    do{
        b++;
        if(current_perm == q) break;
    } while( next_permutation(begin(current_perm), end(current_perm)));

    cout << abs(b-a) << endl;

    return 0;
 
}

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

int main() {
	ll n; cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	
	vector<ll> r(n), l(n);
	r[0] = a[0];
	for(ll i=0; i<=n-2; i++) {
		r[i+1] = max(r[i], a[i+1]);
	}
	l[n-1] = a[n-1];
	for(ll i = n-1; i>=1; i--) {
		l[i-1] = max(l[i], a[i-1]);
	}

	rep(i, n) {
		if(i == 0) cout << l[1] << endl;
		else if(i == n-1) cout << r[n-2] << endl;
		else cout << max(r[i-1], l[i+1]) << endl;
	}
}

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

bool isEvenString(string s) {
	if (s.size() % 2 != 0) {
		return false;
	}
	int halfLength = s.size() / 2;
	for (int i = 0; i < halfLength; i++) {
		if (s[i] != s[halfLength + i]) {
			return false;
		}
	}
	return true;
}

int main() {

	string s; cin >> s;
	int ans;
	s.pop_back();
	while (true) {
		if (isEvenString(s)) {
			ans = s.size();
			break;
		}
		s.pop_back();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
print([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(input())-1])


Measured memory_bytes: 38256
/*
ID: usaco.t3
TASK: test
LANG: C++14
*/

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define pii pair<intt,intt>
#define vi vector<intt>
#define vii vector<pii>

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();
#define endl '\n'

#define wtfis(x) cerr << "at line " << __LINE__ << ": " << #x << " = " << (x) << endl

const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;

const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;

const intt INF = 2LL * 1000000000;
const intt INFLL = 9LL * 1000000000 * 1000000000;
/***************/

intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

intt gcd (intt a, intt b) {
    while (b > 0) {
        intt t = a % b;
        a = b, b = t;
    }
    return a;
}

intt lcm (intt a, intt b) {
    return (a / gcd (a, b)) * b;
}

intt is_prime (intt n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    IO;
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
}


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

int main(){
    int x[3];
    for(int i=0;i<3;i++){
        cin>>x[i];
    }
    int t=1;
    while(t!=0){
        t=0;
        for(int i=0;i<2;i++){
            if(x[i]>x[i+1]){
                int temp=x[i];
                x[i]=x[i+1];
                x[i+1]=temp;
                t++;
            }
        }
    }
    cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<endl;
    return 0;
}


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

int main() {
    ll X;cin >> X;
    int i = 1;ll t = 100;
    while(true){
        t += t / 100;
        if (t >= X) break;
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 3628
/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-08-16-19.52
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define eps 1e-14
#define  LL long long
#define  ULL unsigned long long
using namespace std;
const int MAXN=10+(int)1e5;
LL n,pw,vw[MAXN],pf[MAXN],vf[MAXN],th[MAXN];
double tmp,t1;
double cal(double& w)
{
      tmp=w*pw;
      for(int i=0;i<n;++i)
      {
            t1=th[i]-w*vw[i];
            if(t1<=0) continue;
            tmp+=(t1)*pf[i]*1./vf[i];
      }
      return tmp;
}

double work(double l,double r)
{
      double mid,mmid;
      int st=300;
      while(st--)
      {
            mid=(l+r)/2;
            mmid=(mid+r)/2;
            if(cal(mid)-cal(mmid)>eps)
                  l=mid;
            else r=mmid;
      }
      return l;
}
int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(0);
      while(scanf("%lld",&n),n)
      {
            scanf("%lld",&pw);
            double r=-100000.0;
            for(int i=0;i<n;++i)
            {
                  scanf("%lld %lld %lld %lld",&vw[i],&pf[i],&vf[i],&th[i]);
//                  r=max(r,th[i]*1./vw[i]);
            }
            double val=work(0,1000);
            printf("%.6lf\n",cal(val));
      }
      return 0;
}
/*

*/

Measured memory_bytes: 4348
N = int(input())
h = list(map(int, input().split()))

# DP
inf = float("inf")
dp = [inf for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[i] - h[i-1])
    else:
        dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[-1])

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

int main() {
  ll x;
  cin >> x;

  ll count = (x / 11) * 2;

  x -= (x / 11) * 11;

  if(x == 0) {
    cout << count << endl;
    return 0;
  }

  if(x > 6) {
    count += 2;
  }else {
    count += 1;
  }

  cout << count << endl;

}


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

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

  long long ans = 0;
  for (int i=0; i<=a; i++) {
    for (int j=0; j<=b; j++) {
      int tmp = x - 500 * i - 100 * j;
      if (tmp < 0) {
        break;
      }
      if (tmp <= 50 * c) {
        ++ans;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define all(c) (c).begin(),(c).end()
#define endl '\n'
using namespace std;

//                                      mdsaqib
signed main(){
    fast;
    char c;
    cin >> c;
    int n=c-'A';
    if(n<26)cout << "A";
    else cout << "a";
}


Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n){
    llong ans = x;
    if (n == 0) return 1;

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

    return ans;
}

template <typename T> struct BIT { // 1-indexed
private:
    vector<T> array;
    const int n;

public:
    // 初期化
    BIT(int _n) : array(_n + 1, 0), n(_n) {}

    // 1番目からi番目までの累積和を求める
    T sum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i; // LSB減算
        }

        return s;
    }

    // [i, j]の要素の総和
    T sum(int i, int j) {
        T ret_i = sum(i - 1);
        T ret_j = sum(j);

        return ret_j - ret_i;
    }

    // i番目に要素xを追加
    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i; // LSB加算
        }
    }
};

template <typename T> struct BIT2 { // 1-indexed
private:
    vector<vector<T> > array;
    const int n;
    const int m;

public:
    // 初期化
    BIT2(int _n, int _m) : array(_n + 1, vector<T>(_m + 1, 0)), n(_n), m(_m) {}

    // (1, 1)から(x, y)までの累積和を求める
    T sum(int x, int y) {
        T s = 0;
        for (int i = x; i > 0; i -= i & (-i)) {
            for (int j = y; j > 0; j -= j & (-j)) {
                s += array[i][j];
            }
        }

        return s;
    }

    // [(x1, y1), (x2, y2)]の要素の総和
    T sum(int x1, int y1, int x2, int y2) {
        return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1);
    }

    // (x, y)に要素kを追加
    void add(int x, int y, T k) {
        for (int i = x; i <= n; i += i & (-i)) {
            for (int j = y; j <= m; j += j & (-j)) {
                array[i][j] += k;
            }
        }
    }
};

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

string toUpper(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = toupper(s[i]);
    }
    return t;
}

string toLower(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = tolower(s[i]);
    }
    return t;
}

bool isOdd(llong i) {
    if(i % 2) {
        return true;
    } else {
        return false;
    }
}

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

    if (a % 2 == 0 || b % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int A,B,C,D,t;
	cin>>A>>B>>C>>D;
	
	if(A>B)
		t=B;
	else
		t=A;
	if(C>D)
		t=t+D;
	else 
		t=t+C;
	cout<<t;
	
	return 0; 
}


Measured memory_bytes: 504
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N];
        int ans = 0;
        int x = 0;

        for(int i=0; i<N; i++){
            a[i] = sc.nextInt();
        }
        loop:for(int i=1; i<N; i++){
            for(int j=x; j<N; j++){
                if(a[j]==i){
                    x = j + 1;
                    break;
                }
                else if(a[j]!=i){
                    ans += 1;
                }
                if(j==N-1){
                    break loop;
                }
                if(ans==N-1){
                    ans = -1;
                    break loop;
                }
            }
        }
        System.out.println(ans);
    }
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define eps 1e-9
#define VECT(v) vector<int>v
#define SCAN(v) for(int i=0; i<n; i++) {int temp; cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) {cout << v[i] << " "; cout << en;}
#define SORT(v) sort(v.begin(), v.end());

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io
	
	int n;
	cin >> n;

	VECT(v);
	SCAN(v);

	ll cnt = 0, def = 1;
	for(int i = 0; i < n - 2; i++)
	{
		for(int j = i + 1; j < n - 1; j++)
		{
			for(int k = j + 1; k < n; k++)
			{
				if(v[i] != v[j] && v[j] != v[k] && v[i] != v[k])
				{
					set <int> s;
					s.insert(v[i]);
					s.insert(v[j]);
					s.insert(v[k]);

					ll sum = *s.begin() + *(++s.begin());
					if(sum > *s.rbegin())
						cnt++;

					//cout << *s.begin() << " " << *(++s.begin()) << " " << *s.rbegin() << "\n";
				}
			}
		}
	}

	cout << cnt << en;

	return 0;
}

Measured memory_bytes: 3664
import java.util.*;
public class Main{
	public static final long INF = (long)Math.pow(2,31) - 1L;
	public static boolean check(int n){
		if(n == 1)
			return true;
		else if(n % 2 != 0)
			return false;
		else
			return check(n / 2);
	}
	public static void update(long rmq[], int i, int x, int n){
		i += (n - 1);
		rmq[i] = x;
		if(i == 0)
			return;
		i = (i-1) / 2;
		while(i >= 0){
			long tmp = Math.min(rmq[2*i + 1],rmq[2*i + 2]);
			if(tmp == rmq[i])
				break;
			else{
				rmq[i] = tmp;
				i = (i-1) / 2;
			}
		}
	}
	public static long find(long rmq[], int s, int t, int left, int right, int i){
		if(right <= s || left > t)
			return INF;
		else if(left >= s && right <= t+1)
			return rmq[i];
		else{
			return Math.min(find(rmq,s,t,left,(left+right)/2, 2*i+1),find(rmq,s,t,(left+right)/2,right,2*i+2));
		}
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int n_ = n;
		while(!check(n_))
			n_++;
		int q = sc.nextInt();
		long rmq[] = new long[2*n_ - 1];
		for(int i = 0 ; i < 2*n_ - 1 ; i++)
			rmq[i] = INF;
		for(int i = 0 ;i < q ; i++){
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			switch(com){
				case 0: update(rmq,x,y,n_); break;
				case 1: System.out.println(find(rmq,x,y,0,n_,0)); break;
			}
		}
	}
}


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

int main()
{
  int64_t a, b, k;
  cin >> a >> b >> k;
  int64_t ans_t, ans_a;
  ans_t = max(a - k, (int64_t)0);
  k = max(k - a, (int64_t)0);
  ans_a = max(b - k, (int64_t)0);
  cout << ans_t << ' ' << ans_a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N, X;
  cin >> N >> X;
  vector<int> vec(N+1, 0);
  REP(i, N) {
    int x;
    cin >> x;
    vec[i+1] = vec[i] + x;
  }
  REP(i, N+1) {
    if (vec[i+1] > X) {
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << N+1 << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

//   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
    String[] s=sc.nextLine().split("");
//     String[] e=sc.nextLine().split(" ");

//int n=Integer.parseInt(nyuA);

//int A=Integer.parseInt(s[0]);
//int B=Integer.parseInt(s[1]);


HashSet<String> list=new HashSet<>();

for(String temp:s){
list.add(temp);
}
ArrayList<String> set=new ArrayList<>(list);
Collections.sort(set);

String[] abc={"a","b","c","d","e","f","g","h","i","j","k","l","n","m",
"o","p","q","r","s","t","u","v","w","x","y","z"};

ArrayList<String>res=new ArrayList<>();
HashSet<String>te=new HashSet<>();

for(String tem:set){
for(int i=0;i<abc.length;i++){
if(tem.equals(abc[i]))abc[i]="0";
}
}

for(int i=0;i<abc.length;i++){
if(!"0".equals(abc[i]))res.add(abc[i]);
}
Collections.sort(res);
if(res.size()==0){
System.out.println("None");

}else
System.out.println(res.get(0));

//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 34492
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	r, D, x := sc.NextInt(), sc.NextInt(), sc.NextInt()

	for i := 0; i < 10; i++ {
		x = r*x - D
		fmt.Println(x)
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

vector<vector<int>> G;
int match[210];
bool used[210];

bool dfs(int v)
{
	used[v] = true;
	rep(i, 0, SZ(G[v]))
	{
		int u = G[v][i], w = match[u];
		if (w < 0 || !used[w] && dfs(w))
		{
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching()
{
	int res = 0;
	rep(i, 0, 210)match[i] = -1;
	rep(v, 0, SZ(G))
	{
		if (match[v] < 0)
		{
			rep(i, 0, 210)used[i] = false;
			if (dfs(v))
			{
				res++;
			}
		}
	}
	return res;
}

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

	int X, Y, E, x, y;
	cin >> X >> Y >> E;
	G.resize(X + Y);
	while (E--)
	{
		cin >> x >> y;
		G[x].push_back(X + y);
		G[X + y].push_back(x);
	}

	cout << bipartite_matching() << endl;

	return 0;
}


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


vector<int> A(11, -1);

int inc(int pos) {
	if (A[pos] == -1) { A[pos] = 0; }
	A[pos]++;
	if ((A[pos + 1] >= 0 && A[pos] > A[pos + 1] + 1) || A[pos] == 10) {
		A[pos] = inc(pos + 1);
	}
	return(A[pos] - 1 < 0 ? 0 : A[pos] - 1);
}

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

	int K;
	cin >> K;


	while (K > 0) {
		inc(0);
		K--;
//		cout << A[10] << A[9] << A[8] << A[7] << A[6] << A[5] << A[4] << A[3] << A[2] << A[1] << A[0] << endl;
	}
	ll ans = 0;
	ll pow = 1;
	for (int i = 0; i < 12; i++) {
		if(A[i] >= 0){
			ans += A[i] * pow;
			pow *= 10;
		}
	}
	cout << ans << endl;


}






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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<string>s(N);
  vector<int>t(N);
  for(int i=0;i<N;i++)cin>>s[i]>>t[i];
  string X;
  cin>>X;
  bool b=false;
  int ans=0;
  for(int i=0;i<N;i++){
    if(b)ans+=t[i];
    if(X==s[i])b=true;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////

int main(){
    itn k;
    cin >> k;

    int ans = 0;
    rep(i,1,k+1){
	rep(j,1,k+1){
	    rep(l,1,k+1){
		ans += gcd(i,gcd(j,l));
	    }
	}
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	p, q := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = nextInt()
		q[i] = p[i]
	}
	sort.Sort(sort.IntSlice(q))

	d := 0
	for i := range p {
		if p[i] != q[i] {
			d++
		}
	}

	if d <= 2 {
		puts("YES")
	} else {
		puts("NO")
	}
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int h,w,ans=LLONG_MAX,a,b,c;
  cin >>h >>w;
  for(long long int i=1;i<w;i++){
    a=i*h;
    if((w-i)%2==0){
      b=h*((w-i)/2);
      c=h*((w-i)/2);
    }
    else{
      b=h*((w-i)/2);
      c=h*((w-i)/2+1);
    }
    ans=min(ans,max(abs(a-b),max(abs(b-c),abs(c-a))));
  }
  for(long long int i=1;i<h;i++){
    a=i*w;
    if((h-i)%2==0){
      b=w*((h-i)/2);
      c=w*((h-i)/2);
    }
    else{
      b=w*((h-i)/2);
      c=w*((h-i)/2+1);
    }
    ans=min(ans,max(abs(a-b),max(abs(b-c),abs(c-a))));
  }
  cerr<<ans<<endl;
  for(long long int i=1;i<h;i++){
    a=i*w;
    if(w%2==0){
      b=(h-i)*(w/2);
      c=(h-i)*(w/2);
    }
    else{
      b=(h-i)*(w/2);
      c=(h-i)*(w/2+1);
    }
    ans=min(ans,max(abs(a-b),max(abs(b-c),abs(c-a))));
    cerr<<a <<b <<c<<endl;
  
  }
  cerr<<ans<<endl;
  for(long long int i=1;i<w;i++){
    a=i*h;
    if(h%2==0){
      b=(w-i)*(h/2);
      c=(w-i)*(h/2);
    }
    else{
      b=(w-i)*(h/2);
      c=(w-i)*(h/2+1);
    }
    ans=min(ans,max(abs(a-b),max(abs(b-c),abs(c-a))));
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll H, W, D;
ll A[310][310];
vector<pair<ll, ll>> pos(100010);
ll dp[100010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W >> D;
  rep(i, H)rep(j, W) cin >> A[i][j];
  rep(i, H)rep(j, W){
    pos[A[i][j]] = {i+1, j+1};
  }
  for(int i = D+1; i <= H * W; i++){
    dp[i] = dp[i - D] + abs(pos[i].first - pos[i-D].first) + abs(pos[i].second - pos[i-D].second);
  }
  ll Q; cin >> Q;
  rep(i, Q){
    ll L, R; cin >> L >> R;
    cout << dp[R] - dp[L] << endl;
  }
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=205,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    string S;cin>>S;
    
    if(S[0]=='A'){
        K--;
        S[0]='B';
    }
    
    if(K==0){
        cout<<S<<endl;
        return 0;
    }
    
    int cnt=0;
    for(int i=1;i<N;i++){
        int to=cnt;
        if(S[i]=='A'){
            if(i&1) to++;
            else to+=2;
        }else{
            if(i&1) to+=2;
            else to++;
        }
        
        if(to>K) cout<<'A';
        if(to==K) cout<<'B';
        
        if(to>=K){
            for(int j=1;j<N;j++){
                if(j+i>=N){
                    if((N-j)&1) cout<<'A';
                    else cout<<'B';
                }else{
                    if(i&1){
                        if(S[j+i]=='A') cout<<'B';
                        else cout<<'A';
                    }else{
                        cout<<S[j+i];
                    }
                }
            }
            cout<<endl;
            return 0;
        }
        
        cnt=to;
    }
    
    K-=cnt;
    
    if(N%2==0){
        for(int j=0;j<N;j++){
            if(j&1) cout<<'A';
            else cout<<'B';
        }
        cout<<endl;
    }else{
        if(K&1) cout<<'A';
        else cout<<'B';
        for(int j=1;j<N;j++){
            if(j&1) cout<<'B';
            else cout<<'A';
        }
        cout<<endl;
    }
    
}


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

bool isPrime(int num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;
  
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main() {
    int x; cin >> x;
    while(true)
    {
        if (isPrime(x)) {
            cout << x << endl;
            return 0;
        }
        x++;
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split())))

tmp = 0
sum_a = sum(A)
ind = N+1
for i in range(N-1):
    tmp += A[i]*2
    if tmp < A[i+1]:
        ind = i

if ind == N+1:
    print(N)
else:
    print(N-ind-1)

Measured memory_bytes: 14304
n = int(input())
s = input()

r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
            ans -= 1
print(ans)


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

int main(){
  int A,B,K;
  cin>>A>>B>>K;


  for(int i=min(A,B);i>=1;--i){
    if((A%i==0)&&(B%i==0)){
      --K;
      if(K==0){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m;
    cin >> n;
    map<string, int> mp;
    while (n--){
        string u;
        cin >> u;
        mp[u] = 1;
    }
    cin >> m;
    int f = 1;
    while (m--){
        string t;
        cin >> t;
        if (mp[t]){
            if (f) cout << "Opened by " << t << endl;
            else cout << "Closed by " << t << endl;
            f ^= 1;
        }else{
            cout << "Unknown " << t << endl;
        }
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int count = 1;
    for (int i = 1; i < n; i++) {
        if (a[i - 1] != a[i]) count++;
    }
    cout << count << 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;

int main(){
    int n; cin >> n;
    vector<string> w(n);
    rep(i,n) 
        cin >> w[i];

    bool flg = true;
    for(int i=0; i<n-1; i++){
        if(w[i].back() != w[i+1].front()){
            flg = false; break;
        }
    }
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(w[i] == w[j]){
                flg = false; break;
            }
        }
    }
    
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 3616
n = int(input())
h = [int(_) for _ in input().split()]
seq = 0
maxi = 0
for i in range(1,n):
    if h[i-1] >= h[i]:
        seq += 1
    else:
        if seq > maxi:
            maxi = seq
        seq = 0
if seq > maxi:
    print(seq)
else:
    print(maxi)

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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() <= k)cout << s << endl;
    else{
        while (s.size() > k)s.pop_back();
        cout << s << "..." << endl;    
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
 
using namespace std;
 
#define D(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
 
 
int main()
{
    string s;
    cin >> s;
    if(s.back() == 's'){
		cout << s+"es" << endl;
	}
	else{
		cout << s+"s" << endl;
	}
 
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
#define FAST_IO {ios::sync_with_stdio(0);cin.tie(0);}
using namespace std;
signed main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  int t = 1, ans = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == t) {
      t++; 
    } else {
      ans++;
    }
  }
  if (ans == N) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}



Measured memory_bytes: 1792
def dfs(x):
	d,q = [-1 for i in range(n+1)],[x]
	d[x] = 0
	while q:
		x = q.pop()
		for i in r[x]:
			if d[i]==-1: d[i],q = d[x]+1,q+[i]
	return d
n = int(input())
x = [[int(i) for i in input().split()] for i in range(n-1)]
r = [[] for i in range(n+1)]
for i,j in x:
	r[i].append(j)
	r[j].append(i)
d1,dn,num = dfs(1),dfs(n),0
for i in range(1,n+1):
	if d1[i]<=dn[i]: num+=1
if num>n//2: print("Fennec")
else: print("Snuke")

Measured memory_bytes: 41036
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  string s;
  cin>>s;
  int w;
  cin>>w;
  int n = s.size();
  string ans = "";
  for(int i=0;i*w<n;i++){
    ans += s[i*w];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
ll n,ans;
vector<P>a;
ll p[100005];
int main(void){
    cin>>n;
    ll b=1,c;
    cin>>c;
    for(int i=1;i<n;i++){
        char s;
        ll x;
        cin>>s>>x;
        if(s=='-'){
            a.PB(P(b,c));
            b=-1;
            c=x;
        }else{
            if(b==1)c+=x;
            else{
                a.PB(P(b,c));
                b=1;
                c=x;
            }
        }
    }
    a.PB(P(b,c));
    n=a.size();
    for(int i=n-1;i>=0;i--){
        p[i]+=p[i+1];
        p[i]+=a[i].S;
        ans+=a[i].F*a[i].S;
    }
    if(n==2){
        cout<<a[0].S+a[1].F*a[1].S<<endl;
        return 0;
    }
    ll r=a[0].S;
    for(int i=1;i<n-1;i+=2){
        if(a[i+1].F==1){
            ans=max(ans,r-a[i].S-a[i+1].S+p[i+2]);
            r=r-a[i].S+a[i+1].S;
        }else{
            ans=max(ans,r-a[i].S+p[i+1]);
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2672
MOD = 10 ** 9 + 7
pow_10_i_13 = [pow(10, i, 13) for i in range(6)]

s = input()

dp = [0] * 13
dp[0] = 1
for i, c in enumerate(reversed(s)):
    if c == '?':
        tmp = [0] * 13
        for j in range(10):
            shift = j * pow_10_i_13[i % 6] % 13
            for k in range(13):
                tmp[k] += dp[k-shift]
                tmp[k] %= MOD
        dp = tmp
    else:
        shift = int(c) * pow_10_i_13[i % 6] % 13
        dp = dp[-shift:] + dp[:-shift]

print(dp[5])


Measured memory_bytes: 44652
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
using namespace std;

int main()
{
	int n, m;
	cin >> m >> n;
	cout << (n - 1) * n / 2 + (m - 1) * m / 2 << endl;

}


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

int main(){
    int n, m;
    cin >> n >> m;
    bool a[200001] = {}, b[200001] = {};
    while(m-- > 0){
        int x, y;
        cin >> x >> y;
        if(x == 1)  a[y] = true;
        if(y == n)  b[x] = true;
    }
    for(int j = 2; j < n; j++){
        if(a[j] && b[j]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 100000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back

int h,w;
char s[100][100];
int t[100][100];
int ans=0;
int main(){
  cin>>h>>w;
  rep(i,h){
    cin>>s[i];
    rep(j,w){
      t[i][j]=inf;
      if(s[i][j]=='.')
        ans++;
    }
  }
  t[0][0]=0;
  queue<P> q;
  q.push(P(0,0));
  while(!q.empty()){
    int a=q.front().F,b=q.front().S;
    q.pop();
    rep(i,4){
      int x=a+vx[i],y=b+vy[i];
      if(!(0<=x&&x<w&&0<=y&&y<h)) continue;
      if(s[y][x]=='.'&&t[y][x]>t[b][a]+1){
        t[y][x]=t[b][a]+1;
        q.push(P(x,y));
      }
    }
  }

  if(t[h-1][w-1]==inf)
    cout<<-1<<endl;
  else
    cout<<ans-1-t[h-1][w-1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

char Cap(char c) {
	int a = c - 'a';
	char Ca = 'A' + a;
	return Ca;
}

int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << Cap(s1[0]) << Cap(s2[0]) << Cap(s3[0]) << endl;
}

Measured memory_bytes: 256