akhauriyash/Code-Regression huggingface dataset:
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    writefln("%.10s", lread() * 2 * PI);
}

bool is_exist(string s, char c)
{
    return (s.countUntil(c) >= 0);
}

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


Measured memory_bytes: 2996
s=list(input())
n=int(input())
for i in range(n):
    inst=list(input().split())
    start=int(inst[1])
    end=int(inst[2])
    if(inst[0]=="print"):
        print(''.join(s[start:end+1]))
    elif(inst[0]=="replace"):
        for j in range(len(inst[3])):
            s[start+j]=inst[3][j]
    elif(inst[0]=="reverse"):
        rev=list(reversed(s[start:end+1]))
        for j in range(len(rev)):
            s[start+j]=rev[j]



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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int k, n;
	vi v;
	cin >> k >> n;
	for (int i = 0; i < n; i++) {
		int e; cin >> e;
		v.pb(e);
	}
	sort(all(v));

	int mn = v[n-1] - v[0];
	for (int i = 0; i < n-1; i++)
		mn = min(mn, v[i]+k-v[i+1]);

	cout << mn << ende;
  return 0;
}


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e5 + 5;
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen(".INP", "r")){
                freopen(".INP", "r", stdin);
                freopen(".OUT", "w", stdout);
        }
        ll n, m;
        cin >> n >> m;
        cout << n * (n - 1) / 2 + m * (m - 1) / 2;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const ll MAX = 510000;
const ll MOD = 1000000007;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

vector<ll> sum(MAX);
vector<ll> msum(MAX);

int main(){
    ll N,K;cin>>N>>K;

    repn(i,N){
      sum[i] = i*(i+1)/2;
      sum[i] %= MOD;
    }

    for(ll i = N+1; i>=1; i--){
      msum[i-1] += msum[i] + i;
      msum[i-1] %= MOD;
    }


    ll ans = 0;
    for(ll i = K; i <= N+1; i++){
      ans += msum[i] - sum[N-i+1] + 1;
      // cout<<ans<<endl;
      ans %= MOD;
    }



    cout<<ans<<endl;
}


Measured memory_bytes: 10968
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
#include <climits>
#define INF 1000000000000000
#define ll long long
using namespace std;
ll N;
struct edge{ ll to, cost;};
vector<edge> G[200005];
ll d[200005];
typedef pair<ll,ll> P;
ll dijkstra(int s){
    priority_queue<P, vector<P>,greater<P>> que;
    fill(d,d+N,INF);
    d[s] = 0;
    que.push(P(0,s));
 
    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        if(d[v] < p.first)continue;
 
        for(ll i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if( d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
int main(){
    ll M;
    cin >> N >> M;
    int a,b,c;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        a--; b--;
        G[a].push_back(edge{b,1});
        G[b].push_back(edge{a,1});
    }
    dijkstra(0);
    if(d[N-1]==2){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 18912
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int a[200000];
int ans;
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];a[i]--;
	}
	rep(i,n)
	{
		if(a[a[i]]==i)ans++;
	}
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,m,a,b,i,j,l,lg,lgmaxi;
char s;
int main()
{
    cin>>s;
    if(s=='A')
        cout<<'T';
    else if(s=='T')
        cout<<'A';
    else if(s=='C')
        cout<<'G';
    else if(s=='G')
        cout<<'C';
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 17 16:53:19 2016

@author: Yasuhiro_2
"""

def checkSorted(A):
    check = True
    a = A[0]
    for e in A:
        if a > e:
            check = False
            break
        else:
            a = e
    return check
        

def insertionSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return [cnt, A]

"""
def shellSort(A, n):
    cnt = 0
    m = 0
    G = []          
    while checkSorted(A) == False:
        g = 1
        for i in range(n):
            j = i
            tmp = g
            while j < n:
                if A[i] > A[j]:
                    g = j - i
                j += tmp
        G.append(g)
        m += 1
        A = insertionSort(A, n, g, cnt)
        cnt = A[0]
        A = A[1]
    if m == 0:
        m = 1
        G = [1]
    return [m, G, cnt, A]
"""
def shellSort(A, n):
    cnt = 0
    m = 1
    G = [1]
    while G[-1] < n:
        G.append(3*G[-1] + 1)
        m += 1
    if m > 1:
        G = G[:-1]
        G.reverse()
        m -= 1
    
    for g in G:
        A = insertionSort(A, n, g, cnt)
        cnt = A[0]
        A = A[1]

    return [m, G, cnt, A]

            

if __name__ == '__main__':   
    n = int(input())
    A = []
    for i in range(n):
        A.append(int(input()))
    results = shellSort(A, n)
    m = results[0]
    G = results[1]
    cnt = results[2]
    Ar = results[3]
    print(m)
    gs = ''
    for g in G:
        gs = gs + str(g) + ' '
    print(gs[:-1])
    print(cnt)
    for a in Ar:
        print(a)
    
    

Measured memory_bytes: 47456
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    string s,t; cin >> s >> t;
    int q; cin >> q;

    vector<int> sa(s.size()+10,0);
    vector<int> ta(t.size()+10,0);
    for(int i=0;i<s.size();i++){
        if(s[i] == 'A') sa[i] = 1;
        else sa[i] = 2;
    }
    for(int i=0;i<t.size();i++){
        if(t[i] == 'A') ta[i] = 1;
        else ta[i] = 2;
    }

    for(int i=0;i<s.size();i++) sa[i+1] += sa[i];
    for(int i=0;i<t.size();i++) ta[i+1] += ta[i];

    rep(i,q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;b--;c--;d--;
        int sum1 = sa[b];
        if(a) sum1 -= sa[a-1];
        int sum2 = ta[d];
        if(c) sum2 -= ta[c-1];
        if(sum1 % 3 == sum2 % 3){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

int n, ma, mb;
int dp[50][500][500];

void solve()
{
	REP(i, 50) REP(a, 500) REP(b, 500) dp[i][a][b] = INF;
	cin >> n >> ma >> mb;
	dp[0][0][0] = 0;
	REP(i, n) {
		int a, b, c; 
		cin >> a >> b >> c;
		REP(x, 500) REP(y, 500) {
			dp[i + 1][x][y] = min(dp[i + 1][x][y], dp[i][x][y]);
			dp[i + 1][x + a][y + b] = min(dp[i + 1][x + a][y + b], dp[i][x][y] + c);
		}
	}
	int ans = INF;
	RREP(i, 400) {
		if (ma*i > 400 && mb *i > 400) break;
		RREP(j, n) ans = min(ans, dp[j][ma*i][mb*i]);
	}
	cout << (ans < INF ? ans : -1) << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 52436
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;

const int MAX_H = 55;
const int MAX_W = 55;
char c[MAX_H][MAX_W];//ここはcharとかかもしれない
int d[MAX_H][MAX_W],h,w;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};//二度と間違えるな
bool contain(int x,int y){
    return (0<=x&&x<MAX_H&&0<=y&&y<MAX_W);
}
bool cell(int x,int y){
    return (c[x][y]=='.');//右辺もいじろう
}

void BFS(int sx,int sy){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            d[i][j] = INF;
        }
    }
    d[sx][sy]=0;
    queue<P> q;
    q.push({sx,sy});
    int nx,ny;
    while(!q.empty()){
        P p = q.front();q.pop();
        int x = p.first,y = p.second;
        for(int i=0;i<4;i++){
            nx = x + dx[i];
            ny = y + dy[i];
            if(contain(nx,ny)&&cell(nx,ny)&&d[nx][ny]==INF){
                d[nx][ny] = d[x][y] + 1;
                q.push({nx,ny});
            }
        } 
    }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>h>>w;
    int white = 0;
    rep(i,0,h){
        rep(j,0,w){
            cin>>c[i][j];
            if(c[i][j]=='.'){white++;}
        }
    }
    BFS(0,0);
    if(d[h-1][w-1]!=INF)cout<<white-d[h-1][w-1]-1<<endl;
    else{cout<<-1<<endl;}
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, m, x, y, xmax = -200, ymin = 200, a;
  scanf("%lld%lld%lld%lld", &n, &m, &x, &y);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    if(a > xmax) xmax = a;
  }
  for(i = 0; i < m; ++i) {
    scanf("%lld", &a);
    if(a <= ymin) ymin = a;
  }
  printf("%s", (xmax > x ? xmax : x) < (ymin < y ? ymin : y) ? "No War" : "War");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);

int main(){
  ll N,W; cin>>N>>W;
  vi v(N),w(N);
  REP(i,N) cin>>v[i]>>w[i];
  vvi dp(N,vi(100*N+1,INF));
  dp[0][0]=0; dp[0][v[0]]=w[0];
  FOR(i,1,N) REP(j,100*N+1){
    dp[i][j]=dp[i-1][j];
    if(j-v[i]>=0) dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
  }
  ll ans=0;
  REP(j,100*N+1) if(dp[N-1][j]<=W) ans=j;
  cout<<ans<<endl;
}

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

int main()
{
  string s, t; cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

s = []
for i in range(m):
  array = list(map(int, input().split()))
  tmp = 0
  for j in range(1, len(array)):
    tmp += 2 ** (array[j]-1)
    
  s.append(tmp)

p = list(map(int, input().split()))  

count = 0
for i in range(0, 2**n):
  array = []
  for j in range(len(s)):
    tmp = i & s[j]
    tmp = bin(tmp).replace('0b', '').replace('0', '')
    r = len(tmp) % 2
    array.append(r)
    
  if p == array:
    count += 1
    
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, t;
    cin >> X >> t;
    cout << max(0, X - t) << endl;

    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s,t; cin >> s >> t;
	cout << t << s << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for (int i = 0; i < m; i++) cin >> l[i] >> r[i];
    
    sort (l.begin(), l.end());
    sort (r.begin(), r.end());
    
    int ans = r[0] - l[m-1] + 1;
    ans = max (ans, 0);

    cout << ans << endl;
}

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

int main() {
	int k;
	string s;
	cin >> k;
	cin >> s;
	if (s.size() <= k) cout << s << endl;
	else {
		for (int i = 0; i < k; i++) cout << s[i];
		cout << "..." << endl;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>

const int maxn=1000000;

int n,ans,sum[maxn+10];
char s[maxn+10],t[maxn+10];

int main()
{
  scanf("%d%s%s",&n,s+1,t+1);
  if(s[1]!=t[1])
    {
      puts("-1");
      return 0;
    }
  int f=0,k=0,now=n;
  for(int i=n; i; --i)
    {
      f+=sum[i+k];
      if((now>i)||(t[i]!=s[now]))
        {
          while((now>0)&&((now>i)||(t[i]!=s[now])))
            {
              --now;
            }
          if(now==i)
            {
              continue;
            }
          if(now<=0)
            {
              puts("-1");
              return 0;
            }
          ++k;
          ++f;
          sum[i+k-1]=0;
          --sum[now+k-1];
        }
      ans=std::max(ans,f);
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 5888
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

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

//SegmentTreeMin
template<typename ValueType>
class SegmentTreeMin{
public:
  SegmentTreeMin(){}
  SegmentTreeMin(int n, ValueType max_value){
    this->N = 1;
    this->max_value = max_value;
    while (this->N < n) this->N *= 2;
    this->data.resize(2 * N - 1, this->max_value);
  }
  //init
  void init(int n, ValueType max_value){
    this->N = 1;
    this->max_value = max_value;
    while (this->N < n) this->N *= 2;
    this->data.resize(2 * N - 1, this->max_value);
  }
  // update k th element
  void update(int k, ValueType val){
    k += N - 1;
    data[k] = val;
    while (k > 0){
      k = (k - 1) / 2;
      data[k] = std::min(data[2 * k + 1], data[2 * k + 2]);
    }
  }
  //min [a, b)
  ValueType min(int a, int b) {
    return min(a, b, 0, 0, N);
  }
  ValueType min(int a, int b, int k, int l, int r){
    if (r <= a or b <= l) return max_value;
    if (a <= l and r <= b) return data[k];
    int med = (l + r) / 2;
    return std::min(min(a, b, 2 *k + 1, l, med), min(a, b, 2 * k + 2, med, r));
  }
private:
  std::vector<ValueType> data;
  int N;
  ValueType max_value;
};
///////////////////////////////////////

int N, Q;
int main() {
  cin >> N >> Q;
  SegmentTreeMin<int64_t> seg;
  int64_t INF = (1LL << 31) - 1;
  seg.init(N, INF);
  for (int i = 0; i < Q; i++){
    int com,x,y;
    cin >> com >> x >> y;
    if (com == 0){
      seg.update(x, y);
    }else{
      cout << seg.min(x, y + 1) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4964
#include<iostream>
using namespace std;
int n;
bool check(int k)
{
	int a=n;
	for(int i=k;i>0;i--)
	{
		if(a-i>=0)a-=i;
		if(!a)break;
	}
	return a?false:true;
}
main()
{
	cin>>n;
	int l=0,p=n+1;
	for(int i=0;i<100;i++)
	{
		int m=(l+p)/2;
		if(check(m))p=m;
		else l=m;
	}
	cout<<p<<endl;
}

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

using namespace std;

int main(void)
{
	long long a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0)
	{
		cout << (a + b) / 2 << endl;
	}
	else
	{
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int A = Cin();
        int B = Cin();
        int C = Cin();
        int D = Cin();
        Console.WriteLine(Math.Min(A, B) + Math.Min(C, D));
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int Cin()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
}


Measured memory_bytes: 11092
import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();

		// 各入力値を取得して2で割れる回数を取得。最小回数を算出する。
		int minNum = -1;
		for(int i = 0; i < n; i++){
			int a = sc.nextInt(); // 入力値取得
			if(minNum == -1){
				minNum = NumberOfDevision(a);
			}else{
				minNum = min(minNum, NumberOfDevision(a));
			}
		}

		// 出力
		System.out.println(minNum);
	}

	// 偶数かどうかを判定
	static boolean isEven(int n){
		if(n%2 == 0){
			return true;
		}else{
			return false;
		}
	}

	// 2で割り切れる回数を取得
	static int NumberOfDevision(int n){
		if(isEven(n)){
			return 1 + NumberOfDevision(n/2);
		}else{
			return 0;
		}
	}

}




Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X,T;
  int time = 0;
 cin >> N >> X >> T;
  if(N%X==0){
   time =  (N/X)*T;
  }
  else{
    time = (N/X*T)+T;
  }
 cout << time<<endl;
}

Measured memory_bytes: 3628
H,W,K = map(int,input().split())

dp = [[0]*10 for _ in range(H+1)]   
dp[0][1] = 1

    

for i in range(1,H+1):
    for x in range(2**(W-1)):           
        Alloc = [0]*9
        tmp = x
        for y in range(1,8):  
            Alloc[y] = tmp%2
            tmp //= 2 
        for y in range(0,9):
            if Alloc[y] == 1 and Alloc[y+1] == 1:
                break
        else:   
            for j in range(1,9):  
                if Alloc[j-1] == 1: 
                    dp[i][j] += dp[i-1][j-1]
                elif Alloc[j] == 1:
                    dp[i][j] += dp[i-1][j+1]
                else:
                    dp[i][j] += dp[i-1][j]
                dp[i][j] %= 1000000007

print(dp[H][K])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {

    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    int min_index = 0;
    int max_index = 0;
    rep(i,N) {
        if (a[i] > a[max_index]) max_index = i;
        if (a[i] < a[min_index]) min_index = i;
    }

    int maximum = a[max_index];
    int minimum = a[min_index];

    if (minimum == maximum) {
        cout << 0 << endl;
        return 0;
    }

    int count = 0;
    vector<P> ans;

    if (minimum < 0 && maximum > 0) {
        if (abs(minimum) > maximum) {
            rep(i,N) {
                if (i != min_index) {
                    ans.emplace_back(min_index + 1, i + 1);
                    a[i] += a[min_index];
                    count++;
                }
            }
        } else {
            rep(i,N) {
                if (i != max_index) {
                    ans.emplace_back(max_index + 1, i + 1);
                    a[i] += a[max_index];
                    count++;
                }
            }
        }
    }

    min_index = 0;
    max_index = 0;
    
    rep(i,N) {
        if (a[i] > a[max_index]) max_index = i;
        if (a[i] < a[min_index]) min_index = i;
    }

    if (a[max_index] <= 0) {
        rep(i,N - 1) {
            ans.emplace_back(N - i, N - i - 1);
            count++;
        }
    } else {
        rep(i,N - 1) {
            ans.emplace_back(i + 1, i + 2);
            count++;
        }
    }

    cout << count << endl;
    rep(i,count) {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }
    
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if ( a % 2 == 0 || b % 2 == 0 ) {
  	cout << "Even" << endl;
  }else {
  	cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,q,ans,a[52],b[52],c[52],d[52],f[52];
inline void dfs(re int x){
	if(x>n){
		re int sum=0;
		for(re int i=1;i<=q;++i){
			if(f[b[i]]-f[a[i]]==c[i])sum+=d[i];
		}
		ans=max(ans,sum);
		return;
	}
	for(re int i=f[x-1];i<=m;++i){
		f[x]=i;
		dfs(x+1);
	}
}
signed main(){
	n=read(),m=read(),q=read();
	for(re int i=1;i<=q;++i){
		a[i]=read();
		b[i]=read();
		c[i]=read();
		d[i]=read();
	}
	f[0]=1;
	dfs(1);
	printf("%d",ans);
}

Measured memory_bytes: 3752
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ANextAlphabet {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        char c;
        cin >> c;
        char n = c + 1;
        cout << n << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ANextAlphabet solver;
    solver.solve(in, out);
    return 0;
}


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

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


void func(long long N, std::vector<long long> a){
    lli cnt=0;
    REP(i,0,N){
        while(a[i]%2==0){
            a[i]/=2;
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    func(N, std::move(a));
    return 0;
}


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

int main(){
	int N,L;
	cin>>N>>L;
	
	int taste[N];
	for(int i=0;i<N;i++){
		taste[i]=L+(i+1)-1;
	}
	
		
	int ans=0;
	for(int i=0;i<N;i++){
			ans+=taste[i];
		}
	//cout<<ans<<endl;
	
	for(int i=0;i<N;i++){
		if(taste[i]<0)
			taste[i]=-taste[i];
	}
	
	/*for(int i=0;i<N;i++){
		cout<<i<<' '<<taste[i]<<endl;
	}*/
	
	int min=taste[0];
	for(int i=0;i<N;i++){
		if(min>taste[i])
			min=taste[i];
	}
	//cout<<min<<endl;
	
	if(ans>0)
		ans-=min;
	else
		ans+=min;
	
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 3E5 + 100;
typedef long long ll;
int n, m, a[MAXN];
ll p[MAXN];
 
int main()
{
    ll all = 0;
    scanf("%d%d", &n, &m);
    for(int i=0; i<n; ++i) scanf("%d", a+i);
    for(int i=1; i<n; ++i)
    {
        int l = a[i-1], r = a[i];
        if(l>r) r += m;
        all += r-l;
        if(r-l>1)
        {
            p[l+2] += 1;
            p[r+1] -= (r-(l+2)+1) + 1;
            p[r+2] += (r-(l+2)+1);
        }
    }
    for(int i=1; i<=2*m; ++i) p[i] += p[i-1];
    for(int i=1; i<=2*m; ++i) p[i] += p[i-1];
 
    ll ans = -1;
    for(int i=1; i<=m; ++i)
    {
        ans = max(ans, p[i]+p[i+m]);
    }
    cout << all - ans << endl;
 
    return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main{
	public static void main(String []args)throws Exception{
    	Scanner sc=new Scanner(System.in);
      	int N=sc.nextInt();
      	boolean iswareru = false;
        for(int i = 1;i<10;i++){
              if((N % i ==0)&&(1<=N / i)&&(N / i<=9)){
                iswareru =true;
              }
        }
        if(iswareru){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }  
          
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	if(s.length()<4) cout<<"No\n";
	else if(s.substr(0,4)=="YAKI") cout<<"Yes\n";
	else cout<<"No\n";
}


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

int main(){

	int n;
	cin >> n;

	for(int j=0; j<n; j++){
		int d=0;
		int a[8];
		int n1=0,n2=0;
	
		cin >>d;

		for(int i=0; i<8; i++){
			a[i]=d%10;
			d/=10;
		}
		
		stable_sort(a,a+8);
	
		for(int i=0; i<8; i++){
			n1+=a[7-i]*pow(10,i);
			n2+=a[i]*pow(10,i);
		}

		cout << n2-n1 << endl;

	}
}

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

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;

    int max = 0;
    for (size_t i = 1; i < S.size(); ++i) {
        const std::string a = S.substr(0, i);
        const std::string b = S.substr(i, S.size());
    
        int cnt = 0;
        for (int i = 0; i < 26; ++i) {
            const char c = 'a' + i;

            if (a.find(c) != std::string::npos && b.find(c) != std::string::npos) {
                ++cnt;
            }
        }

        max = std::max(max, cnt); 
    }

    std::cout << max << std::endl;

    return 0;
}


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

int n, m, q;
vector<int> graph[100000];
vector<pair<int, int> > question;
int INF = -1;
// 未探索はINF
int group[100000];

void dfs(int i, int c) {
  group[i] = c;
  vector<int> v = graph[i];
  for (int j = 0; j < v.size(); j++) {
    if (group[v[j]] == INF) {
      dfs(v[j], c);
    }
  }
}

int main() {

  cin >> n >> m;

  // 配列を初期化
  for(int i = 0; i < n; i++) {
    group[i] = INF;
  }

  // 入力を受け取る
  for(int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    graph[s].push_back(t);
    graph[t].push_back(s);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int s, t;
    cin >> s >> t;
    question.push_back(make_pair(s,t));
  }

  // 探索
  int id = 1;

  for (int i = 0; i < n; i++) {
    if (group[i] == INF) {
      dfs(i, ++id);
    }
  }

  // 探索結果を出力
  for (int i = 0; i < q; i++) {
    int s = question[i].first;
    int t = question[i].second;
    if (group[s] == group[t]) {
      cout << "yes" << endl;
    } else{
      cout << "no" << endl;
    }
  }

  return 0;

}


Measured memory_bytes: 16748
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

s = gets_i
a_list = [s]

i = 1
while true do
  ans = 0
  n   = a_list[i-1]
  if n.even?
    ans = n /2
  else
    ans = 3 * n + 1
  end
  if a_list.include?(ans)
    puts i + 1
    exit
  else
    a_list[i] = ans
    i += 1
  end
end

Measured memory_bytes: 2172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int s;
    cin >> s;
    int mae = s/100 ,usiro = s%100;
    if(0<mae && mae<=12 && 0<usiro && usiro<=12 )cout << "AMBIGUOUS" << endl;
    else if(0<mae && mae<=12)cout << "MMYY" << endl;
    else if(0<usiro && usiro<=12)cout << "YYMM" <<endl;
    else cout << "NA" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s;
bool c=true;
int main()
{
	cin>>s;
	for(int i=0;s[i]!='\0';i++)
	{
		if(s[i]=='C')
			c=false;
		if(s[i]=='F'&&c==false)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<set>
#define ll long long 
using namespace std;
int main()
{
	ll int n,i,s=0,sum=0;
	cin>>n;
	ll int a[n],f[n]={0},p[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		f[a[i]-1]++;
		
		
	}

	for(i=0;i<n;i++)
	{
		p[i]=f[i]*(f[i]-1)/2;
		sum+=p[i];
	}
	
	for(i=0;i<n;i++)
	{
		sum-=(f[a[i]-1]-1)*f[a[i]-1]/2;
		sum+=(f[a[i]-1]-2)*(f[a[i]-1]-1)/2;
		cout<<sum<<endl;
		sum-=(f[a[i]-1]-2)*(f[a[i]-1]-1)/2;
		sum+=(f[a[i]-1]-1)*f[a[i]-1]/2;
		
		
	}
	
}






Measured memory_bytes: 7680
n = int(input())
k = int(input())
dp = [ [0,0] for i in range(n+1) ]
dp[0][0] = 1
dp[0][1] = 1
for i in range(1,n+1):
    dp[i][0] = min(dp[i-1][0], dp[i-1][1]) * 2
    dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + k
print(min(dp[n][0],dp[n][1]))    


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;
  vll a(n);
  REP(i, n)
    cin >> a[i];

 vll cum(n+1, 0);
  REP(i, n)
    cum[i+1] = cum[i]+a[i];

  map<ll, ll> m;
  set<ll> s;
  REP(i, cum.size()){
    m[cum[i]] += 1;
    s.insert(cum[i]);
  }

  ll ans = 0;
  for(auto w:s){
    ans += m[w]*(m[w]-1)/2;
  }

  cout << ans << endl;





}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

int main() {
    long long N, D, A;
    cin >> N >> D >> A;

    vector<pair<long long, long long>> monster(N);
    for (int i = 0; i < N; i++)
        cin >> monster[i].first >> monster[i].second;

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

    long long total = 0;
    long long ans = 0;
    queue<pair<long long, long long>> q;
    D = 2 * D;

    for (int i = 0; i < N; i++) {
        while (!q.empty() && monster[i].first > q.front().first) {
            total -= q.front().second;
            q.pop();
        }

        monster[i].second -= total;
        if (monster[i].second < 0)continue;
        long long cnt = (monster[i].second + A - 1) / A;
        long long damage = A * cnt;
        q.emplace(monster[i].first + D, damage);
        total += damage;
        ans += cnt;
    }

    cout << ans << endl;
}



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

int main() {
int n,m,ans,sum;
  ans=0;
  sum=0;
cin>>n>>m;
vector<int> vec(n);
 
for(int i=0;i<n;i++){cin>>vec.at(i);}
   for(int i=0;i<n;i++){sum=sum+vec.at(i);}
  for(int i=0;i<n;i++){
  if(vec.at(i)>(sum-1)/(4*m)){ans++;}}
  if(ans>=m){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 3;
const int N = 1e3 + 10, M = 1e6 + 10;
const ll INF = 1e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi acos(-1)

int a[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
            for (int k = j + 1; k <= n; k++)
            {
                if (a[i] + a[j] > a[k] && a[i] != a[j] && a[j] != a[k])
                    ans++;
            }
    }
    cout << ans << endl;
    return 0;
}
/*

*/

Measured memory_bytes: 3632
from collections import deque

n, m = map(int, input().split())

adj = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

q = deque()

dist = [-1] * n
ans = [0] * n
q.append(0)

while len(q) != 0:
    now = q.popleft()
    for to in adj[now]:
        if dist[to] != -1: continue
        dist[to] = dist[now] + 1
        ans[to] = now
        q.append(to)

print("Yes")
for i in range(1, n):
    print(ans[i] + 1)

Measured memory_bytes: 95052
/*
* @author:  codancer
* @createTime:  2020-02-17, 09:39:06
*/
#include<bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
ll n,k;
ll a[200010];
bool check(ll x){
	ll cnt=0;// the number that less than x
	for(int i=1;i<=n;i++){
		ll num=0;
		if(a[i]==0){
			if(x>0) num=n;
		}
		else if(a[i]>0){
			ll h=x/a[i];
			if(x%a[i]&&(x>0)){
				++h;
			}
			num=lower_bound(a+1,a+n+1,h)-a-1;
		}
		else{
			ll h=x/a[i];
			if(x%a[i]&&(x>0)){
				h--;
			}
			ll great=upper_bound(a+1,a+n+1,h)-a-1;
			num=n-great;
		}
		cnt+=num;
	}
	for(int i=1;i<=n;i++){
		if(a[i]*a[i]<x) --cnt;
	}
	cnt/=2;
	return cnt<k;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	ll l=-3e18,r=3e18;
	// cout<<check(-6)<<endl;
	for(int i=1;i<=100;i++){
		ll mid=(l+r)/2;
		if(check(mid)) l=mid;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 1792
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp(" %s = %s\n", #x, to_string(x).data())
/* ==================== */ 
int n;
vector<ii> a[20];

bool consistent (int mask) {
	for (int i = 0; i < n; i++) if (mask & (1 << i)) {
		for (ii p : a[i]) {
			int x = (mask & (1 << p.first)) > 0;
			if (x != p.second) return false;
		}
	}
	return true;
}

int main() {
	scanf("%d", &n);
	int t, x, y;
	for (int i = 0; i < n; i++) {
		scanf("%d", &t);
		while (t--) {
			scanf("%d%d", &x, &y);
			a[i].push_back({x - 1, y});
		}
	}
	int mx = 0;
	for (int i = 0; i < (1 << n); i++) {
		if (consistent(i))
			mx = max(mx, __builtin_popcount(i));
	}
	printf("%d\n", mx);
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main()
{
  char c1,c2,c3,c4,c5,c6;

  cin>>c1>>c2>>c3>>c4>>c5>>c6;

  if (c1 == c6 && c2 == c5 && c3 == c4)
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,r = inpl()
if n >= 10:
    print(r)
else:
    print(r + 100*(10-n))

Measured memory_bytes: 5120
program sum
implicit none
integer::n, a, b, c, d ,e ,ans
 
read(5,*)n
 
 if(n==10.or.n==100.or.n==1000.or.n==10000.or.n==100000) then  
  ans=10
 else
  a=n/10000
  b=n/1000-10*a
  c=n/100-10*b-100*a
  d=n/10-10*c-100*b-1000*a
  e=n-10*d-100*c-1000*b-10000*a
  ans=a+b+c+d+e
endif
 
write(6,*)ans
 
end program sum

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

int N;
int K;
vector<P> p[100000];
ll cost[100000];//Kまでの最短経路長
bool vtd[100000];

void dfs(int n){
  //cout << n+1 << endl;
  vtd[n] = true;
  for(int i=0;i<(int)p[n].size();i++){
    if(!vtd[p[n][i].first]){
      cost[p[n][i].first] = cost[n] + p[n][i].second;
      dfs(p[n][i].first);
    }
  }
  return;
}


int main(){
  cin >> N;
  for(int i=0;i<N-1;i++){
    int a,b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    p[a].push_back(P(b,c));
    p[b].push_back(P(a,c));
  }

  int Q;
  cin >> Q >> K;
  int x[Q],y[Q];
  for(int i=0;i<Q;i++){
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
  }

  fill(vtd,vtd+100000,false);
  cost[K-1] = 0;
  dfs(K-1);

  for(int i=0;i<Q;i++){
    cout << cost[x[i]] + cost[y[i]] << endl;
  }

  return 0;
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,a[100005];
ll dp[100005][3];
ll rec(int i=0,int pos=0)
{
    if(i>=n)
        return LONG_MAX;
    if(i==n-1)
        return abs(a[i]-a[i-pos]);
    if(dp[i][pos]+1)
        return dp[i][pos];
    ll one = rec(i+1,1);
    ll two = rec(i+2,2);

    return dp[i][pos] = min(one,two)+abs(a[i]-a[i-pos]);
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> a[i];
    cout << rec();
    return 0;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  if(K == 1) {
    cout << 0 << endl;
  } else {
    cout << N - K << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    vector<bool> visit1(n,false),visit2(n,false);
    ll all = 1;
    //0から始めた時のループ回数
    visit1[0] = true;
    ll ind = a[0];
    for(int i=0;i<n;i++){
        if(visit1[ind] == false){
            visit1[ind] = true;
            all++;
            ind = a[ind];
        }else{
            break;
        }
    }

    ll ind1 = a[0],bubun = 1,ind2 = a[ind],amari;
    if(ind == 0){        //ind == 0なら最初の位置に戻るので直接計算できる
        amari = k % all;
        if(amari != 0){
        for(int i=0;i<amari - 1;i++){
            ind1 = a[ind1];
        }
        cout << ind1 + 1<< endl;
        return 0;
        }else{
            cout << 1 << endl;
            return 0;
        }
    }else{
        if(k > all){
        visit2[ind] = true;
        for(int i=0;i<n;i++){
            if(visit2[ind2] == false){
                visit2[ind2] = true;
                bubun++;
                ind2 = a[ind2];
            }else{
                break;
            }
        }
        k -= (all - bubun);
        ll g = k % bubun;
        ll ind3 = ind;
        for(int j=0;j<g;j++){
            ind3 = a[ind3];
        }
        cout << ind3 + 1<< endl;
        return 0;
    }else{
        ll ind3 = 0;
        for(ll i=0;i<k;i++){
            ind3 = a[ind3];
        }
        cout << ind3 + 1 << endl;
        return 0;
    }
    }
}


Measured memory_bytes: 4844