akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll m=1000000000+7;
ll dp[100005];

ll knsc(ll w[],ll val[],ll c,ll n)
{
  for(ll i=0;i<n;i++)
  {
    for(ll j=100000;j>=0;j--)
    {
      if(j>=val[i])
      {
        dp[j]=min(dp[j],w[i]+dp[j-val[i]]);
      }
    }
  }
  ll ans=0;
  for(ll i=0;i<=100000;i++)
  {
    if(dp[i]<=c)
    {
      ans=i;
    }
  }
  return ans;
}


int main()
{
  IOS;
// memset(dp,0,sizeof(dp));
 for(ll i=0;i<=100005;i++)
 {
  dp[i]=m;
 }
dp[0]=0;

    ll n,c,p,q,i,ans=0,sum=0;
    cin>>n>>c;
    ll w[n];
    ll val[n];
    for(i=0;i<n;i++)
    {
       cin>>w[i]>>val[i];
    }
    ans=knsc(w,val,c,n);
    cout<<ans;
    return 0;
}


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

int n, m, x, y;
vector <int> v[200001];

bool fnd(int node){
    return binary_search(v[node].begin(), v[node].end(), n);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    while(m-- && cin >> x >> y)
        v[x].push_back(y), v[y].push_back(x);
    for(int i = 0 ; i < 200001 ; i++)
        sort(v[i].begin(), v[i].end());
    string ans = "IMPOSSIBLE";
    for(int i = 0 ; i < v[1].size() ; i++)
        if(fnd(v[1][i])) ans = "POSSIBLE";
    cout << ans << endl;
    return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii 		vector<pii>
#define mi 			map<int,int>
#define mii			map<int,pii>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define hell        100000000000000007LL
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;
void solve(){
    string s;
    cin>>s;
    int ans=(s.length()-1)*9+(s[0]-'1'),cur=0;
    rep(i,0,s.length()){
        cur+=s[i]-'0';
    }
    cout<<max(cur,ans);
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> cnt(26,100);
  rep(i, 0, N) {
    string S; cin >> S;
    vector<int> tcnt(26);
    for(auto c : S) tcnt[c - 'a']++;
    rep(j, 0, 26) cnt[j] = min(cnt[j], tcnt[j]);
  }
  string ans = "";
  rep(i, 0, 26) rep(j, 0, cnt[i]) ans += char('a' + i);
  cout << ans << endl;
  return 0;
}


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

dp = [10**6 for _ in range(N+10)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(cost[0] - cost[1])

for cnt in range(3,N+1):
    dp[cnt] = min(dp[cnt - 1] + abs(cost[cnt - 1] - cost[cnt - 2]),dp[cnt - 2] + abs(cost[cnt - 1] - cost[cnt - 3]))

print(dp[N])

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

const int MAX=3005;
vector<vector<int>> S(MAX,vector<int>(MAX,0));
string A,B;

void DP(string A,string B){
    for(int i=0;i<A.size();i++){
        for(int j=0;j<B.size();j++){
            if(A[i]==B[j]) S[i+1][j+1]=S[i][j]+1;
            else S[i+1][j+1]=max(S[i][j+1],S[i+1][j]);
        }
    }
    int i=A.size(),j=B.size();
    string ans="";
    while(i>0&&j>0){
        if(S[i][j]!=S[i-1][j]&&S[i][j]!=S[i][j-1]){
            ans+=A[i-1];
            i--;j--;
        }
        else if(S[i][j]==S[i][j-1]) j--;
        else i--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

int main(){

    cin>>A>>B;
    DP(A,B);
}


Measured memory_bytes: 35712
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 998244353;
const long long int INF = 1e18;




long long int N,K,M,V,P,A[100050],res=0,line=0,sum[100050]={};

char ch;


int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>K;
    for(long long int  i=1;i<=N;i++){
        cin>>A[i];
    }
    sort(A+1,A+N+1);
    for(long long int i = N; i >=N-K+1; i--){
        res+=A[i];
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int sum = 0;
		if(b-c>0){
			sum=b+c;
		}else{
			if(a+b-c>=0){
				sum=b+c;
			}else{
				sum=a+2*b+1;
			}
		}
		System.out.println(sum);
			
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

void solve(long long N, std::vector<long long> A){
    ll ok=N,ng=0;
    while(ok-ng>1){
        ll m=(ok+ng)/2;

        ll len=0;
        vp x;
        rep(i,N){
            if(len<A[i]){
                x.emplace_back(0,A[i]-len);
                len=A[i];
            }else{
                pl p;
                while(len>=A[i]){
                    p=x.back();
                    x.pop_back();
                    len-=p.second;
                }
                if(p.first==m-1){
                    while(len>0&&p.first==m-1){
                        p=x.back();
                        x.pop_back();
                        len-=p.second;
                    }
                    if(p.first==m-1)break;
                    if(p.second>1){
                        x.emplace_back(p.first,p.second-1);
                    }
                    x.emplace_back(p.first+1,1);
                    len+=p.second;
                    if(len<A[i]){
                        x.emplace_back(0,A[i]-len);
                        len=A[i];
                    }
                }else{
                    if(A[i]-len>1){
                        x.emplace_back(p.first,A[i]-len-1);
                    }
                    x.emplace_back(p.first+1,1);
                    len=A[i];
                }
            }
        }
        if(len>0)ok=m;
        else ng=m;
    }
    cout<<ok<<endl;
}

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


Measured memory_bytes: 9160
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int main(){
	LL a,b;
	scanf("%lld%lld",&a,&b);
	if (a==b){printf("1\n");return 0;}
	int r=-1,k=-1;
	fd(i,60,0)
	if ((a&(1ll<<i))!=(b&(1ll<<i))){r=i;break;}
	fd(i,r-1,0)
	if ((b&(1ll<<i))>0){k=i;break;}
	a=a&((1ll<<(r+1))-1);b=b&((1ll<<(r+1))-1);
	LL ans=(1ll<<r+1)-a;
	if (a>(1ll<<k+1))ans=ans-(a-(1ll<<k+1));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int,int> Pair;
const int INF = 1e9+7;

LL n, a, b, v[1000001];

int main(){
	scanf("%lld%lld%lld", &n, &a, &b);
	if (n>a*b || n<a+b-1) return puts("-1")&0;
	
	a=n-a;
	for (int i=1; i<=n; ++i) v[i]=i;
	for (int i=1; i<=n && a; i+=b)
		if (a>=b-1)
			reverse(v+i, v+i+b), a-=b-1;
		else
			reverse(v+i, v+i+a+1), a=0;
	for (int i=1; i<=n; ++i) printf("%lld ", v[i]);
	return 0;
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int A, B; cin >> A >> B;
  //main
  
  
  // output
  if(A>B){cout << 2*A-1 << endl;}
  else if(A == B){cout << A+B << endl;}
  else{cout << 2*B-1 << endl;}

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> S(n + 1);
  S[0] = 0;
  rep(i, n) {
    int L;
    cin >> L;
    S[i + 1] = S[i] + L;
    if(S[i + 1] > x) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << n + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1<<19;
struct Tree{
	int mi[maxn],L,R,w;
	void build(int l,int r,int x){
		mi[x]=w;
		if(l==r)return;
		int mid=(l+r)>>1;
		build(l,mid,x<<1),build(mid+1,r,x<<1|1);
	}
	void pushdown(int x){
		mi[x<<1]=min(mi[x],mi[x<<1]);
		mi[x<<1|1]=min(mi[x],mi[x<<1|1]);
	}
	void modify(int l,int r,int x){
		if(L<=l&&R>=r){mi[x]=min(mi[x],w);return;}
		int mid=(l+r)>>1;pushdown(x);
		if(L<=mid)modify(l,mid,x<<1);
		if(R>mid)modify(mid+1,r,x<<1|1);
	}
	int query(int l,int r,int x){
		if(l==r)return mi[x];
		int mid=(l+r)>>1;pushdown(x);
		if(L<=mid)return query(l,mid,x<<1);
		return query(mid+1,r,x<<1|1);
	}
}t[2];
int main(){
	int n,q,op,x,w;scanf("%d%d",&n,&q),n-=2;
	t[0].w=t[1].w=n;t[0].build(1,n,1),t[1].build(1,n,1);
	long long ans=1ll*n*n;
	for(int i=1;i<=q;i++){
		scanf("%d%d",&op,&x),op--,x--;
		t[op].L=x,w=t[op].query(1,n,1);
		if(w)ans-=w,t[op^1].L=1,t[op^1].R=w,t[op^1].w=x-1,t[op^1].modify(1,n,1);
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 7908
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vl as(n);
    cin>>as;

    ll l = 0, r = 0, s = 0;
    ll ans = 0;
    while (r < n) {
        if ((s & as[r]) == 0) {
            ans += r - l + 1;
            s += as[r];
            r++;
            continue;
        }
        while (s & as[r]) {
            s -= as[l];
            l++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
(let* ((n (read))
       (a (make-array n :element-type 'integer
                        :initial-element 0
                        :adjustable t))
       (m (read))
       (ans 0))
  (setf (aref a 0) m)
  (loop for i from 1 below n do
        (setf (aref a i) (read))
        (setf m (/ (* m (aref a i)) (gcd m (aref a i)))))
  (loop for i below n do
        (incf ans (rem (1- m) (aref a i))))
  (format t "~A~%" ans))


Measured memory_bytes: 61796
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    AC=[0]*N
    WA=[0]*N
    
    for _ in range(M):
        p,s=input().split()
        p=int(p)-1
        if s=="AC":
            AC[p]=1
        else:
            if AC[p]==0:
                WA[p]+=1
       
    acs=sum(AC)     
    was=0
    for i in range(N):
        was+=AC[i]*WA[i]
        
    print(acs,was)
        

main()


Measured memory_bytes: 75776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 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;}

int main() {
  string s; cin >> s;
  if(s=="AAA" || s=="BBB") cout << "No" << endl;
  else cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a , b , c ;
  cin >> a >> b ;
  c= a * b;
  if (c % 2 == 1){
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;  
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int sum = 0;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		cout << sum - a[x - 1] + y << endl;
	}
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int a,b;
    cin >> a >> b;
    ostringstream stra, strb;
    stra << a;
    strb << b;
    
    string ab = stra.str() + strb.str();
    //cout << ab;
    int num = stoi(ab);
    
    //cout << num;
    for(int i=1; i<=1000; i++){
        if (((num/i) == i) && (num%i == 0)){
            cout << " Yes";
            return 0;
        }
    }

    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next()
    val ss = mutableSetOf<Char>()

    for (i in 0 until s.length) {
        if (ss.contains(s[i])) {
            println("no")
            return
        } else {
            ss.add(s[i])
        }
    }

    println("yes")
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

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

int arr[100001];
int N;

int xyz(int x, int y, int z){
	return (x*x + y*y + z*z + x*y + y*z + z*x);
}


int main() {
	cin>>N;
	
	for (int i = 1; i<=100; i++){
		for(int j = 1; j<=100; j++){
			for(int k = 1; k<=100; k++){
				if (arr[xyz(i,j,k)] <= N){
					arr[xyz(i,j,k)]++;
				}
				
			}
		}
	}
	
	for(int k = 1; k<=N; k++){
		cout<<arr[k]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3820
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

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

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

using namespace std;


class A {
	int n;
public:
	A()
	{
		cin >> n;
	}
	void solve()
	{
		if (n & 1)
			cout << 2 * n << endl;
		else
			cout << n << endl;
	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    if(a[i]%2==0)
    { if(a[i]%3!=0&&a[i]%5!=0)
    {
      cout<<"DENIED";return 0;
    }
    }
  }
  cout<<"APPROVED";
  return 0;
}



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

a = list()
b = list()

for i in range(n):
    a.append(list(map(int, input().split())))

for i in range(m):
    b.append(int(input()))

# print(a)
# print(b)

for i in range(n):
    sum = 0
    for j in range(m):
        sum += b[j]*a[i][j]
    print(sum)



Measured memory_bytes: 6008
#include <iostream>
using namespace std;
 
int main()
{
  int n,num,dig;
  std::cin >> n;
  for (int i=1; i<=n; ++i){
    if(i%3==0){
        std::cout << " " << i;
        continue;
    }
    num = i;
    while(num){
      dig = num % 10;
      num = num / 10;
      if (dig == 3){
        std::cout << " " << i;
        break;
      }
    }
  }
  std::cout << endl;
}




Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  vector<vector<int>> A(3, vector<int>(3));
  vector<vector<int>> result(3, vector<int>(3));
  for (auto& row : A) {
    for (auto& c : row) {
      cin >> c;
    }
  }
  int N; cin >> N;
  vector<int> B(N);
  for (auto& b : B) {
    cin >> b;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        if (A[i][j] == b) {
          result[i][j] = 1;
        }
      }
    }
  }
  using Pair = pair<int, int>;
  vector<vector<Pair>> hantei = {
    {{0, 0}, {0, 1}, {0, 2}},
    {{1, 0}, {1, 1}, {1, 2}},
    {{2, 0}, {2, 1}, {2, 2}},

    {{0, 0}, {1, 0}, {2, 0}},
    {{0, 1}, {1, 1}, {2, 1}},
    {{0, 2}, {1, 2}, {2, 2}},

    {{0, 0}, {1, 1}, {2, 2}},
    {{0, 2}, {1, 1}, {2, 0}},
  };

  int res{};
  for (const auto& testCase : hantei) {
    int r = true;
    for (const auto& p : testCase) {
      if (result[p.first][p.second]) {
        ;
      } else {
        r = false;
      }
    }

    if (r) res = true;
    if (res) {
      break;
    }
  }

  auto ans = res ? "Yes" : "No";
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


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



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

    int a,b;
    cin>>a>>b;
    cout << a*b;

}





Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p){int res = 1; x = x % p;while (y > 0){    if (y & 1)        res = (res * x) % p;y = y >> 1;    x = (x * x) % p; } return res % p;}
int lcm(int a, int b) { return a / __gcd(a, b) * b; }
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        int n, m, q;
        cin >> n >> m >> q;
        if(q>=m-1){
            int f = (n * (m - 1)) / m;
            cout <<f << endl;
        }
        else{
            int f = (n * (q)) / m;
            cout << f << endl;
        }
    }

    return 0;
}

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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;
  vector<double> V(N);
  for(int i=0;i<N;i++) cin>>V.at(i);

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

  double ans = V.at(0);
  for(int i=1;i<N;i++){
    ans = (ans+V.at(i))/2;
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 1001001000
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n, sum[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vector<ll> a(n, INF);
    rep(i, 0, n) cin >> a[i];
    sort(ALL(a));
    rep(i, 0, n) {
      sum[i+1] = a[i] + sum[i];
    }
    ll ans = 1;
    per(i, n-1, 0) {
      if (2 * sum[i] < a[i]) break;
      else ans++;
    }
    cout << ans << endl;
    return 0;
}




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

int main(){
  int K,T;
  cin >> K >> T;
  vector<int> a(T);
  for(int i=0;i<T;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end(),greater<int>());
  cout << max(a.front()-1-(K-a.front()),0) << endl;
  return 0;
}


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

typedef pair<int,int> P;
const int INF = 500000000;

int main(){
    string s,t;
    cin >> s;
    t = s;
    reverse(t.begin(),t.end());
    if (s == t){
        if (s.substr(0,s.size()/2) == t.substr(t.size()/2+1)){
            if (t.substr(0,t.size()/2) == s.substr(s.size()/2+1)){
                cout << "Yes" << "\n";
                return 0;
            }
        }
    }
    cout << "No" << "\n";
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, c: String);
    let mut s: Vec<char> = c.chars().collect();

    let mut count = 0;
    let mut index_front = 0;
    let mut index_back = c.len() - 1;
    loop {
        loop {
            if index_front > n - 1 || s[index_front] == 'W' {
                break;
            }
            index_front += 1;
        }
        loop {
            if index_back == 0 || s[index_back] == 'R' {
                break;
            }
            index_back -= 1;
        }

        if index_front > n - 1 || index_back == 0 || index_front >= index_back {
            break;
        }

        //交換
        // indexが交差していた場合終了
        s[index_front] = 'R';
        s[index_back] = 'W';
        count += 1;
    }
    println!("{}", count);
}


Measured memory_bytes: 3252
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int e = k / 2;
    int o = (k + 1) / 2;

    cout << e * o << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N; cin >> N;
  vector<int> d(N);
  for (int &x : d) {
    cin >> x;
  }
  
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    for (int x = i+1; x < N; x++) {
      ans += d[i] * d[x];
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<char> S(N);
    rep(i,N) cin >> S[i];
    set<char> dic;
    rep(i,N) dic.emplace(S[i]);

    cout << (dic.size()==3 ? "Three" : "Four") << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long int ll;

struct Edge{
	int to,rev; ll cap;
	Edge(int to,ll cap,int rev):to(to),cap(cap),rev(rev){}
};
// ここの値に注意！！
const int N=105;
const ll INF=1e9;
vector<Edge> g[N];
int level[N]; 
int iter[N];
void add_edge(int s,int t,ll c){
	g[s].push_back(Edge(t,c,g[t].size()));
	g[t].push_back(Edge(s,0,g[s].size()-1));
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> q;
	level[s]=0;
	q.push(s);
	while(q.size()){
		int v=q.front(); q.pop();
		for(auto &e:g[v]){
			if(e.cap>0&&level[e.to]<0){
				level[e.to]=level[v]+1;
				q.push(e.to);
			}
		}
	}
}
ll dfs(int v,int t,ll f){
	if(v==t)return f;
	for(int &i=iter[v];i<g[v].size();i++){
		Edge &e=g[v][i];
		if(e.cap>0&&level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				g[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
ll max_flow(int s,int t){
	ll flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	for(int i=0;i<m;i++){
		int x,y,c; cin >> x >> y >> c;
		add_edge(x,y,c);
	}
	cout << max_flow(0,n-1) << endl;
}




Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for(auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x;
    vl A;
    for(ll i = -200; i < 201; i++) {
        A.push_back(i * i * i * i * i);
    }

    rep(i, 401) {
        n = lower_bound(all(A), A[i] + x) - A.begin();
        if(n < 401) {
            if(A[n] == A[i] + x) {
                cout << n - 200 << " " << i - 200 << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  double x1,y1,x2,y2,x3,y3;
  cin >> x1 >> y1;
  cin >> x2 >> y2;
  cin >> x3 >> y3;
  double a,b,c,r,d,x;
  a = hypot(x1-x2,y1-y2);
  b = hypot(x2-x3,y2-y3);
  c = hypot(x3-x1,y3-y1);
  r = abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/(a+b+c);
  d = max(a,max(b,c));
  x = d/(2+d/r);
  printf("%.12lf",x);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
  
public class Main {
    public static int N;
    public static int M;
    public static int[] p;
    public static int[] rank;
    public static int[] weight;
 
    public static boolean same(int x, int y) {
        return findSet(x) == findSet(y);
    }
  
    public static void unite(int x, int y, int w) {
        int i = findSet(x);
        int j = findSet(y);
       
 
        if (i == j){
	    return;
	}
        if (rank[i] > rank[j]){
            p[j] = i;	   
            weight[j] =  w - weight[y] + weight[x];
        } else {
            p[i] = j;
            weight[i] =  -w - weight[x] + weight[y];
            if(rank[i] == rank[j]){
		rank[j]++;
            }
        }   
    }
  
    public static int findSet(int i) {
	if(p[i] == i){ 
	    return i;
        }else{
	    int tmp = findSet(p[i]);
	    weight[i] += weight[p[i]];
	    return p[i] = tmp;
        }
    }
  
    public static void DisjointSet() {
        p = new int[N];
        rank = new int[N];
        weight = new int[N];
  
        for (int i = 0; i < N; i++) {
            p[i] = i;
            rank[i] = 0;
            weight[i] = 0;
        }
    }
  
  
    public static void main (String[] args){
        Scanner scanner = new Scanner(System.in);
        while(true){
	    N = scanner.nextInt();
	    M = scanner.nextInt();
 
	    if(N==0 && M==0){
		break;
	    }
  
	    DisjointSet();
 
	    for (int i = 0; i < M; i++) {
		String c = scanner.next();
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		a--; b--; 
         
		if(c.equals("!")){
		    int w = scanner.nextInt();
		    unite(a, b, w);
		}else{ 
		    if(same(a,b)){
			System.out.println(weight[b] - weight[a]);
		    }else{
			System.out.println("UNKNOWN");
		    }
		}
	    }
	}
       
    }
}

Measured memory_bytes: 443248
#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 N, R;
    cin >> N >> R;
    cout << R + max(10 - N, 0) * 100 << endl;

    return 0;
}


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

# if a_l[0] != 0:
#     if n == 0 & a_l[0] == 1:
#         print(1)
#     else:
#         print(-1)
#     exit()

tree = [0]*(n+1)
tree[0] = 1
for i in range(1,n+1):
    tree[i] = (tree[i-1] - a_l[i-1]) * 2
# print(tree)

if tree[-1] < a_l[-1]:
    print(-1)
    exit()

# print(tree)
tree[-1] = a_l[-1]
for i in range(2,n+2):
    # print(i, tree[-i], tree[-(i-1)] + a_l[-i])
    if tree[-i] == tree[-(i-1)] + a_l[-i]:
        break
    else:
        tree[-i] = min(tree[-i], tree[-(i-1)] + a_l[-i])
    # print(tree)
# print(tree)

# while tree[-1] != a_l[-1]:
#     tree[-1] -= 1
#     i = 1
#     while True:
#         i += 1 
#         if tree[-(i-1)] >= (tree[-i] - a_l[-i]):
#             break
#         tree[-i] -= 1
# print(tree)

ans = 0
for val in tree:
    ans += val
print(ans)

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

int main()
{
    int n;
    cin>>n;
    int arr[n],dp[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    dp[0]=0;
    if(n!=1)
        dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]) ,dp[i-1]+abs(arr[i]-arr[i-1]));
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())

def factorize(n):
  b = 2
  fct = []
  while b * b <= n:
    while n % b == 0:
      n //= b
      fct.append(b)
    b = b + 1
  if n > 1:
    fct.append(n)
  return fct

prod = [0]*(N+1)
for i in range(2,N+1):
  for p in factorize(i):
    prod[p] += 1
ans = 1
#print(prod)
for i in range(2,N+1):
  ans *= prod[i]+1
  ans %= 10**9+7
print(ans)

#print(*ans, sep='\n')


Measured memory_bytes: 3064
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


S, T = input().split()
print(T + S)


Measured memory_bytes: 3064
def checker(n)
  return 1 if n==0
  (Math.log10(n)+1).to_i
end

def print_clock(t)
  h = t/3600
  m = t/60 - 60*h
  s = t - (60*60*h + 60*m)
  if checker(m) == 1
    if checker(s) == 1
      puts "0#{h}:0#{m}:0#{s}"
    else
      puts "0#{h}:0#{m}:#{s}"
    end
  else
    if checker(s) == 1
      puts "0#{h}:#{m}:0#{s}"
    else
      puts "0#{h}:#{m}:#{s}"
    end
  end
end

loop do
  h,m,s = gets.chomp.split.map(&:to_i)
  break if [h,m,s].all?{|x| x==-1}
  t1 = 120*60 - (h*60*60 + m*60 + s)
  t2 = t1*3
  print_clock(t1)
  print_clock(t2)
end

Measured memory_bytes: 6164
line = str(input())
lines = line.split(' ')
 
n = int(lines[0])
k = int(lines[1])
 
d = list()
 
line = str(input())
lines = line.split(' ')
 
for l in lines:
    d.append(int(l))
 
ds = list()
 
for i in range(0,n):
    sum = 0
    for j in range(i,n):
        sum += d[j]
        ds.append(sum)
 
for i in range(40,-1,-1):
    count = 0
    o = []
 
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)
 
    if count >= k :
        ds = list(o)
 
sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]
 
print(sum)

Measured memory_bytes: 28700
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]

c=0
for i in range(n-1):
  for j in range(i+1,n):
    c+=(sum((a-b)**2 for a,b in zip(x[i],x[j]))**0.5).is_integer()

print(c)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(void){
    int n;
    cin >> n;

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

    int count = 0;
    int minv, maxv;
    for(int i = 1;i < n-1;i++){
        minv = p[i-1];
        maxv = p[i-1];
        for(int j = 0;j < 2;j++){
            minv = min(minv, p[i+j]);
            maxv = max(maxv, p[i+j]);
        }

        if(p[i] != minv && p[i] != maxv)  count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Two Contests
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii ps[MAX_N];
int lrms[MAX_N], rrms[MAX_N];

/* subroutines */

bool cmplr(const pii &a, const pii &b) {
  return a.first < b.first || (a.first == b.first && a.second > b.second);
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &ps[i].first, &ps[i].second), ps[i].first--;
  sort(ps, ps + n, cmplr);

  lrms[0] = ps[0].second;
  for (int i = 1; i < n; i++)
    lrms[i] = min(lrms[i - 1], ps[i].second);

  rrms[n - 1] = ps[n - 1].second;
  for (int i = n - 2; i >= 0; i--)
    rrms[i] = min(rrms[i + 1], ps[i].second);

  int maxe = 0;
  for (int k = 1; k < n; k++) {
    int l0 = ps[k - 1].first, r0 = lrms[k - 1];
    int l1 = ps[n - 1].first, r1 = rrms[k];
    int e = max(r0 - l0, 0) + max(r1 - l1, 0);
    if (maxe < e) maxe = e;
  }

  int mine = max(lrms[n - 1] - ps[n - 1].first, 0);
  for (int i = 0; i < n; i++) {
    int e = mine + (ps[i].second - ps[i].first);
    if (maxe < e) maxe = e;
  }

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


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int x[n];
    int ma=0;
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> x[i];
        if(ma<x[i]){
            ma=x[i];
        }
        sum+=x[i];
    }
    if(ma<sum-ma){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#define pi 3.14159265358979323846
#define max max_element
#define min min_element
using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

int main() {
	int n, x,u;
	int k=0, ans = 1;
	cin >> n >> x;
	for (int i = 0;i < n;i++) {
		cin >> u;
		k += u;
		if (k > x) {
			cout << ans << endl;
			break;
		}
		ans++;
		if (i == n - 1) cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;
const int NMAX = 10000;

void print(int* A, int N)
{
   cout << A[0]; 
   for (int k = 1; k < N;k++) {
     cout << " " << A[k] ; 
   }
   cout << endl;
}

void insertionSort(int* A, int N)
{
  for (int i = 1; i < N; i++) {
    int v = A[i];
    int j = i - 1;
    print(A, N); 
    while (j >= 0 && A[j] > v) 
    {
      A[j+1] = A[j];
      A[j] = v;
      j -= 1;
    }
  }
    print(A, N); 
}


int main()
{
  int n;
  int array[NMAX+1];
  cin >> n;
  for (int i = 0; i < n;i++) {
    int x; 
    cin >> x; 
    array[i] = x; 
  } 
  insertionSort(array, n);
  return 0;
}

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

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

    ll n;
    cin >> n;

    cout << n * (n - 1) / 2LL << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
vector<vector<ll>> v;
vector<ll> score;
vector<ll> parent;
void dfs(ll now,ll par,ll point){
    score[now] = point+score[now]; 
    // cout<<"now:"<<now<<", point:"<<point<<endl;
    ll size = v[now].size();
    for(auto i=0;i<size;i++){
        ll next = v[now][i];
        if(next!=par){
            dfs(next,now,score[now]);
        }
    }
    return;
}

void search(ll now,ll par){
    ll size = v[now].size();
    parent[now] = par;
    for(auto i=0;i<size;i++){
        ll next = v[now][i];
        if(next!=par){
            search(next,now);
        }
    }
    return;
}

int main(){
    ll N,Q;
    cin>>N>>Q;
    v.resize(N);
    score.resize(N);
    parent.resize(N);
    for(auto i=0;i<N-1;i++){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll p[N],x[N];
    search(0,-1);
    for(auto i=0;i<Q;i++){
        ll a,b;
        cin>>a>>b;
        a--;
        score[a]+=b;
    }
    dfs(0,-1,0);

    for(auto i=0;i<N;i++){
        cout<<score[i]<<" ";
    }
    cout<<endl;

}
 

Measured memory_bytes: 28928
#include <iostream>
using namespace std;
typedef unsigned long long u64;
#include <queue>
#include <vector>

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

  int N;
  cin >> N;
  priority_queue< int, vector< int >, greater< int > > q;
  int sum = 0;
  bool isok = false;
  for (int i = 0; i < N; ++i) {
    int s;
    cin >> s;
    q.push(s);
    sum += s;
    if (s % 10 != 0) {
      isok = true;
    }
  }

  if (!isok) {
    cout << 0 << endl;
  } else if (sum % 10 != 0) {
    cout << sum << endl;
  } else {
    int out = 0;
    while (true) {
      out = q.top();
      q.pop();
      if (out % 10 != 0) {
        break;
      }
    }
    cout << sum - out << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

void chmin(int* a,int b){
    if(*a>b){
        *a=b;
    }
}

int h[100000];
int dp[100000];
const int MAX = 2147483647;

int rec(int i,int K){
    if(dp[i] != MAX){
        return dp[i];
    }
    
    if(i==0){
        return 0;
    }
    
    int res = MAX;
    for(int j=1;j<=K;j++){
        if(i-j < 0){
            break;
        }
        chmin(&res,rec(i-j,K)+abs(h[i-j]-h[i]));
    }
    
    return dp[i] = res;
}

int main(void){
    int N,K;
    
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
        scanf("%d",&h[i]);
        dp[i]= MAX;
    }
    
    printf("%d\n",rec(N-1,K));
    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, K; cin >> N >> K;
  vector<int> A(N); REP(i, N) cin >> A[i];
  vector<int> imos(N + 1); REP(i, N + 1) imos[i] = 0;
  REP(i, K) {
    int flag_s = 0;
    int flag_g = 0;
    REP(n, N) {
      int start = ceil((n + 1) - A[n] - 0.5);
      int end = floor((n + 1) + A[n] + 0.5);
      if(start < 1) {
        imos[0]++;
        flag_s++;
      } else {
        imos[start - 1]++;
      }

      if(end >= N) {
        imos[N]--;
        flag_g++;
      } else {
        imos[end]--;
      }
    }
    REP(m, N) {
      if(m == 0) A[m] = imos[m];
      else {
        A[m] = imos[m] + A[m - 1];
        imos[m - 1] = 0;
      }
    }
    imos[N - 1] = 0;
    if(flag_s == N && flag_g == N) {
      break;
    }
  }
  REP(i, N) {
    cout << A[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4804
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	double a, b; cin >> a >> b;
	cout << round((a + b) / 2.0) << endl;
}

Measured memory_bytes: 256