akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

int r, c;

int main() {
    while (cin >> r >> c) {
        if (r == 0) break;
        if ( (r & 1) && (c & 1) ) puts("no");
        else puts("yes");
    }
    return 0;
}


Measured memory_bytes: 1116
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ll a;
    cin >> a;
    ll b;
    cin >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,c;
  cin>>n>>c;
  PII xv[n];
  rep(i,n){
    cin>>xv[i].F>>xv[i].S;
  }
  int now=0;
  int backscore[n+1];
  int frontscore[n+1];
  rep(i,n+1) backscore[i]=frontscore[i]=0;
  int prev=c;
  int bcmax=0,frmax=0;
  repn(i,n){
    now=now+xv[i-1].S-abs(prev-xv[i-1].F);
    prev=xv[i-1].F;
    bcmax=max(bcmax,now);
    backscore[i-1]=bcmax;
    if(i==1) break;
  }
  int ans=bcmax;
  now=0;
  prev=0;
  rep(i,n){
    now=now+xv[i].S-abs(xv[i].F-prev);
    //cout<<now<<" "<<backscore[i+1]-xv[i].F<<endl;
    if(i==n-1){
      ans=max(ans,now);
    }else{
      ans=max(ans,now+max((int)0,backscore[i+1]-xv[i].F));
    }
    frmax=max(frmax,now);
    frontscore[i]=frmax;
    prev=xv[i].F;
  }
  now=0;
  //cout<<ans<<endl;
  prev=c;
  repn(i,n-1){
    now=now+xv[i].S-abs(prev-xv[i].F);
    if(i==0){
      ans=max(ans,now);
    }else{
      ans=max(ans,now+max((int)0,frontscore[i-1]-(c-xv[i].F)));
    }
    //cout<<ans<<endl;
    prev=xv[i].F;
   
    
  }
  rep(i,n+1){
    // cout<<backscore[i]<<" "<<frontscore[i]<<endl;
  }
	  
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 6780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    REP(i,n){cin >> v[i];}
    int max_h=-1,result=1;
    FOR(i,1,n){
        max_h=max(max_h,v[i-1]);
        if(v[i]>=max_h){
            result++;
        }
  
    }

    cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 888
#abc146d
n=int(raw_input())
e={}
t=[[] for i in range(n)]
c=[1]*(n-1)
for i in range(n-1):
 a,b=map(int,raw_input().split())
 a,b=a-1,b-1
 t[a].append(b)
 e[(a,b)]=i
cp=[[] for i in range(n)]
for i in range(n):
 x=1
 for vc in t[i]:
  while x in cp[i]:
   x+=1
  c[e[(i,vc)]]=x
  cp[vc].append(x)
  x+=1
print max(c)
for i in range(len(c)):
 print c[i]


Measured memory_bytes: 50152
# coding: utf-8
# input
from math import sqrt
n, d = map(int, input().split())
data = list(list(map(int, input().split())) for i in range(n))

# processing
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = 0
        for k in range(d):    
            tmp += (data[i][k] - data[j][k]) ** 2
        if tmp == int(sqrt(tmp)) ** 2:
            ans += 1

# output
print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    char a;

    cin >> a;

    if(isupper(a)) {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }

    return 0;
    
}

Measured memory_bytes: 3616
package main 

import (
  "fmt"
)

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  
  a := make([]int ,n)
  for i := 0; i < n; i++ {
  fmt.Scan(&a[i])
  }

  days := 0
  for _, x := range a {
    days += x
  }
  
  if n - days >= 0 {
  fmt.Println(n - days)
  } else {
  fmt.Println(-1)
  }
}

Measured memory_bytes: 10460
import sys
input = sys.stdin.readline
import numpy as np
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x
def calc(x, C, D, l):
    x1 = x // C
    x2 = x // D
    x3 = x // l
    return x - x1 -x2 + x3

def print_ans(A, B, C, D):
    """Test Case
    >>> print_ans(4, 9, 2, 3)
    2
    >>> print_ans(10, 40, 6, 8)
    23
    >>> print_ans(314159265358979323, 846264338327950288, 419716939, 937510582)
    532105071133627368
    """
    # Greatest common divisor
    g = gcd(max(C,D),min(C,D))
    # Least common multiple
    l = C * D // g
    print(calc(B, C, D, l) - calc(A - 1, C, D, l))



if __name__ == '__main__':
    A, B, C, D = map(int, input().rstrip().split())
    print_ans(A, B, C, D)




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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int countR = count(s.begin(), s.end(), 'R');
    int countB = count(s.begin(), s.end(), 'B');
    if(countR > countB){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int n, m, x, y;
bool f[200005], f2[200005];
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m ; ++i){
        scanf("%d%d", &x, &y);
        if(y < x) swap(x, y);
        if(x == 1)
            f[y] = 1;
        if(y == n)
            f2[x] = 1;
    }
    for(int i = 2; i < n ; ++i){
        if(f[i] == 1 && f2[i] == 1) {printf("POSSIBLE"); return 0;}

    }
    printf("IMPOSSIBLE");
    return 0;
}


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

using namespace std;

#if 1
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

#define int long long

const int MOD = 998244353;

int n, k, s;
int a[5010];
int dp[5010];
int ans = 0;

signed main()
{
    //freopen("input_02.txt", "r", stdin);
    //freopen("output_02.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        dp[0] = i + 1;
        if (a[i] <= s)
        {
            ans = (ans + (n - i) * dp[s - a[i]]) % MOD;
        }
        for (int j = s; j >= a[i]; j--)
        {
            dp[j] = (dp[j] + dp[j - a[i]]) % MOD;
        }
    }
    cout << ans;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;
    while(cin>>N,N){
        vector<string>S(N);
        rep(i,N){
            string s;
            cin>>s;
            S[i]+=s[0];
            for(int j=0;j+1<s.size();j++){
                if(s[j]=='a'||s[j]=='i'||s[j]=='u'||s[j]=='e'||s[j]=='o'){
                    S[i]+=s[j+1];
                }
            }
        }

            int ans=0;
            rep(i,N){
                reps(j,i+1,N){
                    if(S[i]==S[j]){
                        ans=1001001001;
                    }
                    else{
                        int c=0;
                        while(c<S[i].size()&&c<S[j].size()&&S[i][c]==S[j][c])c++;
                        chmax(ans,c+1);
                    }
                }
            }
            if(ans==1001001001)cout<<-1<<endl;
            else cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3136
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=tuple(map(int,input().split()))
    q=int(input())
    ms=tuple(map(int,input().split()))
    
    make=set()
    for bit in range(1<<n):
        num=0
        for j in range(n):
            if (bit>>j)&1:
                num+=a[j]
        make.add(num)
    
    for m in ms:
        if m in make:
            print('yes')
        else:
            print('no')
 
if __name__=='__main__':
    main()


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); ++i) 
typedef pair<int,int> P;

bool bitcheck(int bit, int position){
    if((bit >>position) & 1) return true;
    else return false;
}
int main(){
    string s;
    cin>>s;
    lint ans=0;
    int n = s.size() - 1;
    rep(i,1<<n){
        lint cc = 0;
        lint num = s[0] - '0';
        rep(j, n)
        {
            if (bitcheck(i, j))
            {
                cc += num;
                num = s[j + 1]-'0';
            }
            else{
                num = 10 * num + s[j + 1] - '0';
            }
        }
        cc += num;
        ans += cc;
    }
    cout<<ans<<endl;
    return 0;
}

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

int memo[1111];
int p[] = {500, 100, 50, 10, 5, 1};

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  for(int i=0;i<6;i++) ans = min(ans, solve(n-p[i])+1);
  
  return memo[n] = ans;
}

int main(){
  
  for(int i=0;i<1111;i++) solve(i);

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

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

int main() {
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    int sum = a + b*5 + c*10 + d*50 + e*100 + f*500;
    if(sum >= 1000) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1164
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<String> ans = new ArrayList<String>();
        if (n % 2 == 0) {
            for (int i = 1; i < n; i++) {
                for (int j = i+1; j <= n; j++) {
                    if (j == n+1-i) continue;
                    String tmp = i + " " + j;
                    ans.add(tmp);
                }
            }
        } else {
            for (int i = 1; i < n; i++) {
                for (int j = i+1; j <= n; j++) {
                    if (j == n-i) continue;
                    String tmp = i + " " + j;
                    ans.add(tmp);
                }
            }
        }
        
        System.out.println(ans.size());
        for (String s : ans) {
            System.out.println(s);
        }
    }
}


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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if(a<=k) cout << 0 << " " << max(b-(k-a),ll(0)) << endl;
    else cout << a-k << " " << b << endl;
}

Measured memory_bytes: 256
fun main(args:Array<String>?): Unit {
    val (s, t, d) = readLine()!!.trim().split(' ').map(String::toLong)
    val weights = readLine()!!.trim().split(' ').map(String::toLong)
    val min = LongArray(weights.size){weights[it]}.let{a -> a.indices.drop(1).forEach{i -> a[i] += a[i - 1]}; a.min()!!}
    val sum = weights.sum()
    if (sum >= 0 && s + min > t) println(-1)
    else {
        if (s + min <= t) println(calFirstDay(s, t, weights))
        else {
            val loop = (t - s - min + sum + 1) / sum
            println(calFirstDay(s + sum * loop, t, weights)!! + loop * d)
        }
    }
}
fun calFirstDay(initial: Long, target: Long, weights: List<Long>): Int? {
    var current = initial
    for (i in weights.indices) {
        current += weights[i]
        if (current <= target) return i + 1
    }
    return null
}



Measured memory_bytes: 68008
#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
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[1111][1111];
int dp[1111][1111];

void add(int x1, int y1, int x2, int y2, int v)
{
	x1++;y1++;y2++;x2++;
	//cerr<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<' '<<v<<'\n';
	dp[x2][y2]+=v;
	if(x1) dp[x1-1][y2]-=v;
	if(y1) dp[x2][y1-1]-=v;
	if(x1>0&&y1>0) dp[x1-1][y1-1]+=v;
}

void push(int d)
{
	for(int i=0;i<=d;i++)
	{
		for(int j=0;j<=d;j++)
		{
			if(j) dp[i][j]+=dp[i][j-1];
			if(i) dp[i][j]+=dp[i-1][j];
			if(i>0&&j>0) dp[i][j]-=dp[i-1][j-1];
		}
	}
}

void sub(int x1, int y1, int x2, int y2, int v, int d)
{
	while(x1<0) x1+=d;
	while(x1>=d) x1-=d;
	while(y1<0) y1+=d;
	while(y1>=d) y1-=d;
	while(x2<0) x2+=d;
	while(x2>=d) x2-=d;
	while(y2<0) y2+=d;
	while(y2>=d) y2-=d;
	//cerr<<"SUB "<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<' '<<v<<'\n';
	if(x1>x2&&y1>y2)
	{
		add(x1,y1,d-1,d-1,v);
		add(0,y1,x2,d-1,v);
		add(x1,0,d-1,y2,v);
		add(0,0,x2,y2,v);
	}
	else if(x1>x2)
	{
		add(x1,y1,d-1,y2,v);
		add(0,y1,x2,y2,v);
	}
	else if(y1>y2)
	{
		add(x1,y1,x2,d-1,v);
		add(x1,0,x2,y2,v);
	}
	else
	{
		add(x1,y1,x2,y2,v);
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int d; cin>>d;
	for(int i=0;i<n;i++)
	{
		int x,y; cin>>x>>y; x%=d; y%=d;
		a[x][y]++;
	}
	/*
	for(int i=0;i<d;i++)
	{
		for(int j=0;j<d;j++)
		{
			cerr<<a[i][j]<<' ';
		}
		cerr<<'\n';
	}
	*/
	ll lo = 1; ll hi = ll(1e9);
	//ll lo,hi; lo=hi=10; 
	ll ans=hi;
	while(lo<=hi)
	{
		memset(dp,0,sizeof(dp));
		ll mid=(lo+hi)>>1;
		//cerr<<mid<<'\n';
		ll q = mid/d; ll r = mid%d;
		bool pos=1; int cnt=0;
		for(int i=0;i<d;i++)
		{
			for(int j=0;j<d;j++)
			{
				if(a[i][j]>(q+1)*(q+1))
				{
					pos=0; break;
				}
				if(a[i][j]>q*(q+1))
				{
					if(r==0){pos=0;}
					else
					{
						//cerr<<i-r+1<<' '<<j-r+1<<' '<<i<<' '<<j<<'\n';
						sub(i-r+1,j-r+1,i,j,1,d);
					}
					cnt++;
				}
				else if(a[i][j]>q*q)
				{
					if(r==0){pos=0;}
					else
					{
						sub(i-d+1,j-r+1,i,j,1,d);
						sub(i-r+1,j-d+1,i,j,1,d);
						sub(i-r+1,j-r+1,i,j,-1,d);
					}
					cnt++;
				}
			}
		}
		push(d);
		//cerr<<cnt<<'\n';
		if(pos)
		{
			pos=0;
			for(int i=0;i<d;i++)
			{
				for(int j=0;j<d;j++)
				{
					//cerr<<dp[i][j]<<' ';
					if(dp[i][j]==cnt) pos=1;
				}
				//cerr<<'\n';
			}
		}
		if(pos)
		{
			ans=mid;
			hi=mid-1;
		}
		else
		{
			lo=mid+1;
		}
	}
	ans--;
	cout<<ans<<'\n';
}


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
int N,K;
string t[16];
string ans="";
bool used[16];
int f[16];
int INF=1e9+7;

bool check(int key){
  vector<int> v;
  for(int i=0;i<K;i++){
    int id=t[key][i]-'A';
    v.push_back(f[id]);
  }
  for(int i=0;i+1<K;i++)
    if(v[i]>v[i+1])return false;
  return true;
}

void update(int key){
  for(int i=0;i<K;i++){
    int id=t[key][i]-'A';
    f[id]=-100-i;
  }
  vector<int> X;
  for(int i=0;i<N;i++){
    if(f[i]==INF)continue;
    X.push_back(f[i]);
  }
  sort(X.begin(),X.end());
  X.erase( unique( X.begin(),X.end() ), X.end() );
  for(int i=0;i<N;i++){
    if(f[i]==INF)continue;
    f[i]=lower_bound(X.begin(),X.end(),f[i])-X.begin();
  }
}

typedef unsigned long long ull;

ull B=1e9+9;
unordered_map< ull, bool >  mp;

bool dfs(int depth=0){
  ull key=0;
  for(int i=0;i<N;i++){
    key*=B;
    if(f[i]==INF) key+= 1999;
    else key+=(f[i]+1);
    key*=B;
    if(used[i])key+=(1<<i);
  }
  if(mp[key])return false;
  mp[key]=true;
  
  if(depth==N)return true;
  int tmp[16];
  for(int i=0;i<N;i++)tmp[i]=f[i];
  
  for(int i=0;i<N;i++){
    if(used[i])continue;
    if(!check(i))continue;
    
    update(i);
    used[i]=true;
    
    if(dfs(depth+1)){
      ans.push_back('A'+i);
      return true;
    }
    
    used[i]=false;
    for(int j=0;j<N;j++)f[j]=tmp[j];
  }
  return false;
}

int main(){
  cin>>N>>K;
  for(int i=0;i<N;i++)cin>>t[i];
  fill(used,used+N,false);
  fill(f,f+N,INF);
  dfs();
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel

void solve()
{
	string s;
	cin >> s;
	if (s[s.length() - 1] == 's')
	{
		s += "es";
	}
	else
		s += "s";
	cout << s << endl;
}

signed main()
{
	fasterthanlight;
	int T; T = 1;
	//cin>>T;
	while (T--)
	{
		solve();
	}

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

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

typedef long long int ll;

int main () {
    ll p, q, r;
    cin >> p >> q >> r;

    ll min1=0, min2=0;

    if (p>=q && p>=r) {
        min1 = q;
        min2 = r;
    }

    if (q>=p && q>=r) {
        min1 = p;
        min2 = r;
    }

    if (r>=p && r>=q) {
        min1 = p;
        min2 = q;
    }

    cout << min1 + min2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, j, n, a[100], minj, temp, cnt=0;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &a[i]);

  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(a[j] < a[minj]) {
	minj = j;
      }
    }
    if(i != minj) cnt++;
    temp = a[i];
    a[i] = a[minj];
    a[minj] = temp;
  }
  
  for(i = 0; i < n; i++){
      printf("%d", a[i]);
      if(i < n-1) printf(" ");
      else printf("\n%d\n", cnt);
  }
  return 0;
}



Measured memory_bytes: 2144
#include <stdio.h>
int main(){
  int k,n,num1,num2,num,s,number,big,a;

  scanf("%d %d",&k,&n);

  scanf("%d %d",&num1,&num2);

  s=num2-num1;

  num=num2;

  big=s;

  for(int i=2;i<n;i++){

    scanf("%d",&number);

    s=number-num;

    num=number;

    if(big<s){
      big=s;
    }
  }

  a=k+num1-num;

  if(big<a){
    big=a;
  }

  printf("%d",k-big);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll a, b, c; cin >> a >> b >> c;
    cout << min(a, min(b, c)) << " " << max(a, max(b, c)) << endl;
	return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int a,b;
  	cin>>a>>b;
  	char post[a+b+1];
 	bool jud=true;
  	for(int i=0;i<a+b+1;i++){
		cin>>post[i];
      	if(i<a||(i>a+1&&i<a+b+1)){
          if(post[i]>='0'&&post[i]<='9'){
          }else{
            jud=false;
          }
        }
      	if(i==a){
			if(post[i]!='-'){
				jud=false;
            }
        }
    }
  	if(jud==true){
      cout<<"Yes";
    }else{
      cout<<"No";
    }
	cout<<endl;
    return 0;
}

Measured memory_bytes: 764
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> t(n), v(n);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> v[i];
    rep(i, n-1) t[i+1] += t[i];
    int tsum = t[n-1];
    const double inf = 1e18;
    vector<double> ans(2*tsum+1, inf);
    rep(i, 2*tsum + 1) {
        double now = 0.5*i;
        chmin(ans[i], now);
        chmin(ans[i], tsum - now);
        rep(j, n) {
            if (j == 0) {
                if (0 <= now && now <= t[0]) chmin(ans[i], (double)v[0]);
                if (t[0] <= now) chmin(ans[i], v[0] + now - t[0]);
            } else {
                if (now <= t[j-1]) chmin(ans[i], v[j] + t[j-1] - now);
                if (t[j-1] <= now && now <= t[j]) chmin(ans[i], (double)v[j]);
                if (t[j] <= now) chmin(ans[i], v[j] + now - t[j]);
            }
        }
    }
    double dist = 0;
    rep(i, 2*tsum) {
        dist += (ans[i] + ans[i+1]) / 4;
    }
    cout << fixed << setprecision(15) << dist << endl;
}


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

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc162
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            if (n[0] == '7' || n[1] == '7' || n[2] == '7')
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25880
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    cout<<s.substr(0,n-8)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <iomanip>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> H(N,0);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    int ans = 0;
    int cnt = 0;
    for(int i=0;i<N-1;i++){
        if(H[i] >= H[i+1]){
            cnt++;
        }
        else{
            cnt = 0;
        }
        if(cnt > ans) ans = cnt;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int r = 0;
  for (int i = A; i <= B; i++) {
    if(i % 10 == i /10000 && i /10 % 10 == i / 1000 % 10) r+=1;
  }
cout << r;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
    static PrintWriter out=new PrintWriter((System.out));
    public static void main(String args[])throws IOException
    {
        Reader sc=new Reader();
        int n=sc.nextInt();
        int s=sc.nextInt();
        if(n<=s)
        {
            out.println("unsafe");
        }
        else
        {
            out.println("safe");
        }
        out.close();
    }


    static class Reader
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next()
        {
            while(!st.hasMoreTokens())
            {
                try
                {
                    st=new StringTokenizer(br.readLine());
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }

        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public String nextLine()
        {
            try
            {
                return br.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext()
        {
            String next=null;
            try
            {
                next=br.readLine();
            }
            catch(Exception e)
            {
            }
            if(next==null)
            {
                return false;
            }
            st=new StringTokenizer(next);
            return true;
        }
    }
}

Measured memory_bytes: 32608
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int a = in.nextInt();
        String s = in.next();

        out.println(a >= 3200 ? s : "red");
    }

}


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

namespace ProgrammingContest
{
    class ABC045B
    {
        static Queue<Char> Qa, Qb, Qc;
        static void Main(string[] args)
        {
            string Sa = Console.ReadLine();
            string Sb = Console.ReadLine();
            string Sc = Console.ReadLine();
            Qa = new Queue<Char>(); 
            Qb = new Queue<Char>(); 
            Qc = new Queue<Char>();
            Enq(Sa, Qa);
            Enq(Sb, Qb);
            Enq(Sc, Qc);
            Deq(Qa.Dequeue());
        }
        static void Enq(string str,Queue<Char> queue)
        {
            Char[] cs = str.ToCharArray();
            foreach(char c in cs)
            {
                queue.Enqueue(c);
            }
        }
        static void Deq(char c)
        {
            char next = 'a';
            switch (c)
            {
                case 'a':
                    if (Qa.Count == 0)
                    {
                        Console.WriteLine("A");
                        return;
                    }
                    next = Qa.Dequeue();
                    break;
                case 'b':
                    if (Qb.Count == 0)
                    {
                        Console.WriteLine("B");
                        return;
                    }
                    next = Qb.Dequeue();
                    
                    break;
                case 'c':
                    if (Qc.Count == 0)
                    {
                        Console.WriteLine("C");
                        return;
                    }
                    next = Qc.Dequeue();
                    
                    break;
            }
            Deq(next);
        }
    }
}


Measured memory_bytes: 2776
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
count1=0
count2=0

for i in range(0,x):
  if a[cnt]==i:
    count1+=1
    if cnt==len(a)-1:
      pass
    else:
      cnt+=1
    
for j in range(x+1,n+1):
  if a[cnt]==j:
    count2+=1
    if cnt==len(a)-1:
      pass
    else:
      cnt+=1
      
print(count1 if count1<=count2 else count2)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int A, B;
    cin >> A >> B;
    if(A<=9 && B<=9){
        cout << A * B << endl;
    }
    else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    int m;
    int l;
    static a[100][100];
    static b[100][100];
    static long c[100][100];
    
    scanf("%d %d %d", &n, &m, &l);
    
    for (int i = 0; i < n; i++ ) {
        for ( int j = 0; j < m; j++ ) {
            scanf("%d", &a[i][j]);
        }
    }
    
    for (int i = 0; i < m; i++ ) {
        for ( int j = 0; j < l; j++ ) {
            scanf("%d", &b[i][j]);
        }
    }
    
    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < l; j++ ) {
            for ( int k = 0; k < m; k++ ) {
                c[i][j] += a[i][k] * b[k][j];
            }
            printf("%ld", c[i][j]);
            if ( j != l - 1 ) {
                printf(" ");
            }
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n1[110] = {};
int n2[110] = {};
int A,B,K;
void era(){
    for (int i = 2; i <= A; i++)
	    while (A%i == 0){
		    n1[i]++;
		    A /= i;
	    }
    for (int i = 2; i <= B; i++)
	    while (B%i == 0){
		    n2[i]++;
		    B /= i;
	    }
}

int main(){
    cin >> A >> B >> K;
    era();
    bool n[110] = {false};
    n[1] = true;
    int num[110];
    for(int i = 0; i < 100; i++){
        num[i] = min(n1[i],n2[i]);
        while(num[i] > 0){
            for(int j = 100; j > 0; j--){
                if(n[j]) n[j*i] = true;
            }
            num[i]--;
        }
    }
    int ans,L = 0;
    for(int i = 109; i > 0; i--){
        if(L == K) break;
        if(n[i]){
            ans = i;
            L++;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int n; cin >> n;
  string s; cin >> s;
  bool ok = true;
  if(s.size()%2 == 0){
    for(int i = 0; i < s.size()/2; i++){
      if(s[i] != s[i + s.size()/2]) ok = false;
    }
  }else ok = false;
  string ans = (ok) ? "Yes" : "No" ;
  cout << ans << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

vector<string> ans;

void rec(int k, string s)
{
    if (k == 1)
    {
        ans.emplace_back(s);
        return;
    }
    char d = 'a';
    rep(i, s.size())
    {
        d = max(d, s.at(i));
    }

    rep(i, d - 'a' + 2)
    {
        char c = 'a' + i;
        string ss = string(1, c);
        rec(k - 1, s + ss);
    }
}

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

    rec(n, "a");
    sort(ans.begin(), ans.end());
    rep(i, ans.size())
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 9588
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int W, H, sx, sy;
char T[20][20];
bool visited[20][20];

bool isin(int y, int x) {
  return 0 <= y && y < H && 0 <= x && x < W;
}

int dfs(int sy, int sx) {
  int dd[5] = { 0, 1, 0, -1, 0 };
  int ret = 1;

  visited[sy][sx] = true;

  REP(i, 0, 4) {
    int ny = sy + dd[i + 0];
    int nx = sx + dd[i + 1];
    if(isin(ny, nx) && !visited[ny][nx] && T[ny][nx] != '#') ret += dfs(ny, nx);
  }

  return ret;
}

int main(void) {
  while(cin >> W >> H, W) {
    REP(i, 0, H) {
      cin >> T[i];
      REP(j, 0, W) {
        if(T[i][j] == '@') {
          sy = i;
          sx = j;
        }
      }
    }
    REP(i, 0, H) REP(j, 0, W) visited[i][j] = false;

    cout << dfs(sy, sx) << endl;
  }
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */



signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s;
  cin >> s;
  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define ld long double
using namespace std;
const ll INF = 1e18;
const ll MOD = 998244353;


vector<string> vec_splitter(string s) {
		s += ',';
		vector<string> res;
		while(!s.empty()) {
				res.push_back(s.substr(0, s.find(',')));
				s = s.substr(s.find(',') + 1);
		}
		return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
		if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
		stringstream ss; ss << H;
		cerr << args[idx] << " = " << ss.str();
		debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define deb(...) 42
#endif

struct point {
	int x, y;
};

int calc(map<int, vector<int>> &a, map<int, vector<int>> &b) {
	map<int, vector<int>>::iterator it, jt;
	it = a.begin(), jt = b.begin();
	int res = 2e9;

	for(; it != a.end(); it++, jt++) {
		sort(jt->second.begin(), jt->second.end());
		vector<int> &now = jt->second;

		for(auto x : it->second) {
			auto ind = lower_bound(now.begin(), now.end(), x);
			if(ind != now.begin())	ind--, res = min(res, x - *ind);
		}
	}

	return res / 2;
}

int func(map<int, vector<int>> &a, map<int, vector<int>> &b) {
	int res = 2e9;

	auto it = a.begin(), jt = b.begin();

	for(; it != a.end(); it++, jt++) {
		vector<int> &now = jt->second;
		sort(now.begin(), now.end());
		for(auto x : it->second) {
			auto ind = lower_bound(now.begin(), now.end(), x);
			if(ind != now.end())	res = min(res, *ind - x);
		}
	}

	return res;
}

int32_t main() {
	ios::sync_with_stdio(!cin.tie(NULL));

	int n;
	cin >> n;

	vector<point> l, r, u, d;

	int x, y;
	char ch;
	map<int, vector<int>> le, ri, up, down;
	map<int, vector<int>> plusl, plusr, plusu, plusd, minusl, minusr, minusu, minusd;
	for(int i = 0; i < n; i++) {
		cin >> x >> y; 
		x *= 10, y *= 10;
		cin >> ch;
		if(ch == 'L')	le[y], ri[y], le[y].push_back(x), minusl[x - y].push_back(x), plusl[x+y].push_back(x);
		else if(ch == 'R')	ri[y], le[y], ri[y].push_back(x), minusr[x - y].push_back(x), plusr[x + y].push_back(x);
		else if(ch == 'U')	up[x].push_back(y), down[x], minusu[x - y].push_back(x), plusu[x + y].push_back(x);
		else	up[x], down[x].push_back(y), minusd[x - y].push_back(x), plusd[x + y].push_back(x);

		plusl[x + y], plusr[x+ y], plusu[x + y], plusd[x + y];
		minusl[x - y], minusr[x - y], minusu[x - y], minusd[x - y];
	}

	int res = min(calc(le, ri), calc(down, up));
	deb(res);
	res = min({res, func(minusr, minusd), func(minusu, minusl), func(plusd, plusl), func(plusr, plusu)});
	if(res < (int)1e9)
	cout << res;
	else	cout << "SAFE";
}



Measured memory_bytes: 176876
#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define DD double
#define inf 1000000000
#define eps 0.000001
#define maxn 2000
#define mod 1000000007
using namespace std;

int n, k, inv[maxn * maxn + 1], fac[maxn * maxn + 1];
int f[maxn + 1][maxn + 1];

void read(int &x){
	char ch;
	bool ok;
	for(ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if(ch == '-') ok = 1;
	for(x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	if(ok) x = -x;
}

int c(int x, int y){
	if(x < y) return 0;
	return 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int main(){
	read(n); read(k);
	if(k == 1){
		puts("1");
		return 0;
	}
	inv[0] = inv[1] = fac[0] = fac[1] = 1;
	for(int i = 2; i <= n * k; ++i) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	for(int i = 2; i <= n * k; ++i){
		inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
		fac[i] = 1ll * fac[i - 1] * i % mod;
	}
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j <= i; ++j){
			if(j) f[i][j] = (1ll * f[i][j] + f[i][j - 1]) % mod;
			f[i][j] = (1ll * f[i][j] + 1ll * f[i - 1][j] * (n - (i - 1)) % mod * c((i - 1) * (k - 1) + j + k - 2, k - 2) % mod) % mod;
		}
	}
//	cout << c() << endl;
	printf("%d\n", f[n][n]);
	return 0;
}



Measured memory_bytes: 46208
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
from itertools import accumulate

n, m, *a = map(int, sys.stdin.read().split())
a.sort()

def count(border):
  res = 0
  for x in a:
    b = border - x
    res += n - bi_l(a, b)
  return res

def main():
  lo, hi = 1, a[-1] * 2 + 1
  while lo + 1 < hi:
    border = (lo + hi) // 2
    if count(border) >= m:
      lo = border
    else:
      hi = border
  
  s = a.copy() + [0]
  *s, = accumulate(s[::-1])
  tot = 0
  for x in a:
    b = lo - x
    c = n - bi_l(a, b)
    tot += x * c + s[c]
  
  tot -= lo * (count(lo) - m)
  print(tot)

if __name__ == '__main__':
  main()

Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, m;
    cin >> n >> m;
    vint s(m), c(m);
    rep(i, m) cin >> s[i] >> c[i];

    rep(i, 1000) {
        bool flg = true;
        int num = i;
        int d = 0;
        vint a;
        while(num) {
            d++;
            a.push_back(num%10);
            num /= 10;
        }
        if (i == 0) {
            d++;
            a.push_back(0);
        }
        reverse(all(a));
        if (d != n) continue;
        rep(j, m) {
            if (s[j] > a.size()) {
                flg = false;
                break;
            }
            if (a[s[j]-1] != c[j]) {
                flg = false;
                break;
            }
        }
        if (flg) {
            cout << i << endl;
            return 0;
        }
    }
    puts("-1");
    return 0;
}

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

#define ll long long
#define ull unsigneds long long
#define inf 1e18
#define met(a, x) memset(a,x,sizeof(a))

using namespace std;

const ll mod = 1e9 + 7;
const int N = 2e5 + 10;

int c[N];
ll dp[N];
map<int,int> mp;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> c[i];
    ll ans=0;
    dp[0]=1;
    for(int i=1;i<=n;i++){
        dp[i]=dp[i-1];
        if(mp.count(c[i])&&mp[c[i]]+1<i){
            dp[i]=(dp[i]+dp[mp[c[i]]])%mod;
        }
        mp[c[i]]=i;
    }
    cout<<dp[n]<<endl;
    return 0;
}
/*
2
3 2
1 2
2 3
0 0 0
1 0 1
3 2
1 2
2 3
0 0 0
1 1 1
 */

Measured memory_bytes: 12032
def main():
    N, K = map(int, input().split())
    TD = [tuple(map(int, input().split())) for _ in range(N)]
    TD.sort(key=lambda x: x[1], reverse=True)
    s = set()
    rep = []
    for t, d in TD[:K]:
        if t in s:
            rep.append(d)
        else:
            s.add(t)
    m = sum(d for _, d in TD[:K])
    p = len(s) ** 2 + m
    for t, d in TD[K:]:
        if not rep:
            break
        if t in s:
            continue
        m += d - rep.pop()
        s.add(t)
        p = max(p, len(s) ** 2 + m)
    return p

print(main())


Measured memory_bytes: 19920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1e9+7;

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

//********************************template END****************************************//

void solve(void){

	int N;
	cin >> N;

	int ans = 111;

	ans *= (N-1) / 111 + 1;

	putln(ans);

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

main(){
  int i,j,n,c;
  while(1){
    cin >> n;
    c = 0;
    if(n == 0) break;
    while(n != 1){
      if(n % 2 == 0){
	n /= 2;
	c++;
      }
      else{
	n *= 3;
	n += 1;
	c++;
      }
    }
    cout << c << endl;
  }

  return 0;
}

Measured memory_bytes: 0
from collections import deque


def bfs(start, goal):
    q = deque([[start]])
    visited = set()
    while q:
        path = q.popleft()
        i, j = path[-1]
        if (i, j) == goal:
            return path
        for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            ni, nj = i + di, j + dj
            if not (0 <= ni < H and 0 <= nj < W and field[ni][nj] == "."):
                continue
            if (ni, nj) not in visited:
                q.append(path + [(ni, nj)])
                visited.add((ni, nj))
    return []


H, W = map(int, input().split())
field = [input() for _ in range(H)]
shortest_path = bfs((0, 0), (H - 1, W - 1))
if shortest_path:
    print(sum(v == "." for row in field for v in row) - len(shortest_path))
else:
    print(-1)


Measured memory_bytes: 9540