akhauriyash/Code-Regression huggingface dataset:
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n,s;
    cin>>n>>s;
    vector<pll> A;
    vector<pll> B;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(a<s){A.push_back({a,b});}
        else{B.push_back({a,b});}
    }
    reverse(A.begin(),A.end());
    if(A.empty()){cout<<abs(B.back().F-s)<<endl; return 0;}
    if(B.empty()){cout<<abs(A.back().F-s)<<endl; return 0;}
    char c;
    ll ans=0;
    if(A.back().S<B.back().S){
        c='R';
        B.back().S+=A.back().S;
        ans+=B.back().F-A.back().F;
        //cout<<A.back().F<<endl;
        A.pop_back();
    }
    else{
        c='L';
        A.back().S+=B.back().S;
        ans+=B.back().F-A.back().F;
        //cout<<B.back().F<<endl;
        B.pop_back();
    }
    while(!A.empty() && !B.empty()){
        if(c=='R'){
            if(A.back().S<B.back().S){
                B.back().S+=A.back().S;
                //cout<<A.back().F<<endl;
                A.pop_back();
            }
            else{
                c='L';
                A.back().S+=B.back().S;
                ans+=B.back().F-A.back().F;
                //cout<<B.back().F<<endl;
                B.pop_back();
            }
        }
        else{
            if(A.back().S<B.back().S){
                c='R';
                B.back().S+=A.back().S;
                ans+=B.back().F-A.back().F;
                //cout<<A.back().F<<endl;
                A.pop_back();
            }
            else{
                A.back().S+=B.back().S;
                //cout<<B.back().F<<endl;
                B.pop_back();
            }
        }
    }
    if(c=='L'){ans+=abs(s-A.back().F);}
    else{ans+=abs(B.back().F-s);}
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 2804
# -*- coding: utf-8 -*-
N = int(input())
S = list()
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
  s = input()
  if s == "AC":
    AC += 1
  elif s == "WA":
    WA += 1
  elif s == "TLE":
    TLE += 1
  elif s == "RE":
    RE += 1

print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

Measured memory_bytes: 69840
n,k = map(int,input().split())
wi = []
for _ in range(n):
    wi.append(int(input()))

def isPossibleCarry(k, wi, P):
    track_num = 1
    track_weight = 0
    
    for w in wi:
        if(w > P):
            return False
        
        if(track_weight + w < P):
            track_weight = track_weight + w
        elif(track_weight + w == P):
            track_num += 1
            track_weight = 0
        else:
            track_num += 1
            track_weight = w
            if(track_num > k):
                return False
            
    return track_num <= k or (track_num == k+1 and track_weight==0)

left_P = 1
right_P = sum(wi)
while left_P < right_P:
    mid = int((left_P + right_P) /2)
    if(isPossibleCarry(k, wi, mid)):
        right_P = mid
    else:
        left_P = mid + 1
if(isPossibleCarry(k, wi, mid)):
    print(mid)
else:
    print(left_P)



Measured memory_bytes: 9560
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int n,s;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n>>s && (n||s)){
		int ans=0;
		rep(mask,1<<10)if(__builtin_popcount(mask)==n){
			int sum=0;
			rep(i,10)if(mask>>i&1)sum+=i;
			if(sum==s)ans++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1196
import math
def intersectionCC0(x1, y1, r1, r2):
    r = x1**2 + y1**2
    t = (r + r1**2 - r2**2) / (2*r)
    dd = r1**2/r - t**2
    if - (10**-16) < dd < 0: dd = 0
    if dd < 0: return []
    x, y = t * x1, t * y1
    if dd == 0: return [(x, y)]
    sq = math.sqrt(dd)
    dx, dy = y1 * sq, -x1 * sq
    return [(x+dx, y+dy), (x-dx, y-dy)]

def intersectionCC(x1, y1, x2, y2, r1, r2):
    return [(x1+x, y1+y) for x, y in intersectionCC0(x2-x1, y2-y1, r1, r2)]

def chk(t):
    L = [a for a in L0]
    for i, (x1, y1, c1) in enumerate(X):
        for x2, y2, c2 in X[:i]:
            L += intersectionCC(x1, y1, x2, y2, t/c1, t/c2)
    for x0, y0 in L:
        cnt = 0
        for x, y, c in X:
            if math.sqrt((x-x0) ** 2 + (y-y0) ** 2) * c <= t + 10**-8:
                cnt += 1
        if cnt >= K: return 1
    return 0

N, K = map(int, input().split())
X = []
L0 = []
for _ in range(N):
    x, y, c = map(int, input().split())
    X.append((x, y, c))
    L0.append((x, y))

l, r = 0, 1 << 30
while (r-l) * (1<<25) > max(1, l):
    m = (l+r) / 2
    if chk(m):
        r = m
    else:
        l = m
    
print(l)

Measured memory_bytes: 49756
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll t1,t2,a1,a2,b1,b2;

int main(){
	cin>>t1>>t2>>a1>>a2>>b1>>b2;
	ll sa=t1*a1+t2*a2;
	ll sb=t1*b1+t2*b2;
	if(sa==sb){
		cout<<"infinity"<<endl;
		return 0;
	}
	if(sa<sb){
		swap(a1,b1);
		swap(a2,b2);
		swap(sa,sb);
	}
	if(a1>b1){
		cout<<0<<endl;
		return 0;
	}
	ll t=sa-sb,tmp=(b1-a1)*t1,res=1;
	tmp-=t;
	if(tmp>0){
		res+=(tmp+t-1)/t*2;
		tmp%=t;
	}
	if(tmp==0) res++;
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
class temp{
  public:
  int value;
};
void swapVal(temp &t1,temp &t2){
  swap(t1.value,t2.value);
  return;
}
int main(){
  temp A,B,C;
  cin>>A.value>>B.value>>C.value;
  swapVal(A,B);
  swapVal(A,C);
  cout<<A.value<<" "<<B.value<<" "<<C.value<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] ab = new int[m][2];
		
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			ab[i][0] = a;
			ab[i][1] = b;
		}
		
		Arrays.sort(ab, (x, y) -> y[0] - x[0]);
		int res = 0;
		int prev = Integer.MAX_VALUE;
		/*for (int i = 0; i < m; i++) {
			System.out.println(Arrays.toString(ab[i]));
		}*/
		
		for (int i = 0; i < m; i++) {
			if (prev >= ab[i][1]) {
				prev = ab[i][0];
				res++;
			}
		}
		System.out.println(res);
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 46124
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define int ll
#define N 200010
typedef long long ll;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,l[N],r[N];
ll a[N],b[N],c[N];
double ans;
void init(){
	int k=max_element(a+1,a+n+1)-a;
	rotate(a+1,a+k,a+n+1);
	rotate(b+1,b+k,b+n+1);
	a[n+1]=a[1];
	c[1]=c[2]=0;
	for(int i=3;i<=n+1;++i){
		c[i]=2*(b[i-1]+c[i-1])-c[i-2];
		a[i]-=c[i];
	}
}
struct Point{
	ll x,y;
	Point(ll _x=0,ll _y=0){x=_x,y=_y;}
	inline Point operator + (const Point b){
		return Point(x+b.x,y+b.y);
	} 
	inline Point operator - (const Point b){
		return Point(x-b.x,y-b.y);
	}
	inline ll operator % (const Point b){
		return x*b.y-y*b.x;
	}
	inline bool operator < (const Point b){
		return y==b.y?x<b.x:y<b.y;
	}
	inline __int128 len2(){
		return (__int128)x*x+(__int128)y*y;
	}
}p[N];
typedef vector<Point> Poly;
inline bool Para(Point a,Point b){
	return b%a==0;
}
inline bool Left(Point a,Point b){
	return b%a>0;
}
Poly A,B;
Poly Convex(Poly &a){
	Point LTL=(*min_element(a.begin(),a.end()));
	sort(a.begin(),a.end(),[&](Point a,Point b){
		a=a-LTL,b=b-LTL;
		return Para(a,b)?a.len2()<b.len2():Left(b,a);
	});
	static Point st[N];
	static int top;
	top=0;
	for(int i=0;i<(int)a.size();++i){
		while(top>1&&!Left(a[i]-st[top-1],st[top]-st[top-1]))--top;
		st[++top]=a[i];
	}
	Poly ans;
	st[top+1]=st[1];
	for(int i=1;i<=top;++i){
		if((st[i+1]-st[i]).x<=0)ans.push_back(st[i]);
	}
	return ans;
}
main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	for(int i=1;i<=n;++i){
		b[i]=read();
	}
	init();
	A.emplace_back(0,0);
	for(int i=1;i<=n+1;++i){
		A.emplace_back(i,a[i]);
	}
	B=Convex(A);
	l[0]=0,r[n+1]=n+1;
	for(auto p:B)l[p.x]=r[p.x]=p.x;
	for(int i=1;i<=n;++i)if(!l[i])l[i]=l[i-1];
	for(int i=n;i>=1;--i)if(!r[i])r[i]=r[i+1];
	for(int i=1;i<=n;++i){
		ans+=c[i];
		if(l[i]==r[i]){
			ans+=a[i];
		}
		else{
			int len=r[i]-l[i];
			ans+=((i-l[i])*a[r[i]]+(r[i]-i)*a[l[i]])*1.0/len;
		}
	}
	printf("%.12lf\n",ans/n);
	return 0;
}



Measured memory_bytes: 24000
#include<stdio.h>
#include<stdlib.h>

#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B;
  int i,n;
  int C[VMAX+1];

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i = 0;i <= VMAX;i++){
    C[i] = 0;
  }

  for(i = 0;i < n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i = 1;i <= VMAX;i++){
    C[i] = C[i] + C[i-1];
  }
  for(i = 1;i <= n;i++){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

  for(i = 1;;){
    printf("%d",B[i]);
    i++;
    if(i > n)break;
    printf(" ");
  }
  printf("\n");

  return 0;
}

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

void sum()
{
	int t,a,b,c,d;
	a = b = c = d = 0;
	cin >> t;
	char ar[t+2];
	for(int i=1; i<=t; i++)
	{
		cin >> ar[i];
		if(ar[i]=='P')
			a++;
		if(ar[i]=='W')
			b++;
		if(ar[i]=='G')
			c++;
		if(ar[i]=='Y')
			d++;
	}
	if (a!=0 && b!=0 && c!=0 && d!=0)
	{
		cout <<"Four"<< endl;
	}
	else
		cout << "Three" << endl;
	
}

int main()
{
	sum();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

void printVector(std::vector<int> &a) {
  int n = (int)a.size();
  for (int i = 0; i < n; i++) {
    std::cout << a[i];
    if (i < n - 1)
      std::cout << " ";
    else
      std::cout << std::endl;
  }
}

void printMark(int l, int r, int m, int n) {
  if (l == m)
    l = -1;
  if (r == m)
    r = -1;
  for (int i = 0; i < n; i++) {
    if (i == l)
      std::cout << 'l';
    else if (i == r)
      std::cout << 'r';
    else if (i == m)
      std::cout << 'm';
    else
      std::cout << " ";
    std::cout << " ";
  }
  std::cout << std::endl;
}

int binarySearch(std::vector<int> s, int x) {
  int n = (int)s.size(), l = 0, r = n, m;
  // std::cout << "find: " << x << std::endl;
  while (l < r) {
    m = (l + r) / 2;
    // printVector(s);
    // printMark(l, r, m, n);
    if (s[m] == x) return m;
    else if (x < s[m]) r = m;
    else l = m + 1;
  }
  return -1;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> s(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> s[i];
  }

  int count = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    std::cin >> t;
    if (binarySearch(s, t) >= 0) {
      count++;
    }
  }
  std::cout << count << std::endl;
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    if(a>=b){
        string res="";
        char c=b+'0';
        for(int i=0;i<a;i++){
            res+=c;
        }
        cout<<res<<endl;
    }
    else {
        string res="";
        char c=a+'0';
        for(int i=0;i<b;i++){
            res+=c;
        }
        cout<<res<<endl;
    }
    return 0;
    }


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

using namespace std;

const int NMAX = 2e5;
const int INF  = 1e9;

#define fS (2*nod)
#define fD (2*nod+1)

int arb[4*NMAX+2][2];
int v[NMAX+2];
int N;
vector<int> sol;
int where[NMAX+2];
int qry[2];

void combina(int rez[], int st[], int dr[], int a, int x, int y)
{
    int lef = min(st[(x - a) % 2], dr[(y - a) % 2]);
    int rig = min(st[(x - a + 1) % 2], dr[(y - a + 1) % 2]);
    rez[0] = lef;
    rez[1] = rig;
}

void build(int nod, int st, int dr)
{
    if( st == dr ) {
        arb[nod][0] = v[st];
        arb[nod][1] = INF;
        return ;
    }
    int m = (st + dr) / 2;
    build(fS, st, m);
    build(fD, m + 1, dr);
    combina(arb[nod], arb[fS], arb[fD], st, st, m + 1);
}

void query(int nod, int st, int dr, int x, int y)
{
    if( x <= st && dr <= y ) {
        combina(qry, qry, arb[nod], x, x, st);
        return ;
    }
    if( y < st || dr < x )
        return ;
    int m = (st + dr) / 2;
    query(fS, st, m, x, y);
    query(fD, m + 1, dr, x, y);
}

pair<int,int> query(int x, int y)
{
    qry[0] = qry[1] = INF;
    query(1, 1,N, x, y);
    return {qry[0], qry[1]};
}

struct Gap
{
    int x,y,val;

    bool operator < (const Gap& a) const {
        return val > a.val;
    }
};

priority_queue<Gap> pq;

int main()
{
    cin >> N;
    for( int i = 1;  i <= N;  ++i ) {
        cin >> v[i];
        where[ v[i] ] = i;
    }
    build(1, 1,N);

    pq.push({1,N, query(1,N).first});
    while( !pq.empty() ) {
        auto el = pq.top();
        assert(el.x < el.y && (el.x+el.y) % 2 == 1);
        pq.pop();
        int pos_lef = where[el.val];
        int pos_rig = where[query(pos_lef + 1, el.y).first];
        sol.push_back(v[pos_lef]);
        sol.push_back(v[pos_rig]);

        if( el.x < pos_lef )
            pq.push({el.x, pos_lef - 1, query(el.x, pos_lef - 1).first});
        if( pos_lef + 1 <= pos_rig - 1 )
            pq.push({pos_lef + 1, pos_rig - 1, query(pos_lef + 1, pos_rig - 1).first});
        if( pos_rig + 1 <= el.y )
            pq.push({pos_rig + 1, el.y, query(pos_rig + 1, el.y).first});
    }
    for( auto x : sol ) cout << x << ' ';
    return 0;
}


Measured memory_bytes: 9100
# -*- coding: utf-8 -*-
# 156c
n = int(input())
x = list(map(int, input().split()))
point_list = []

for p in range(1, max(x) + 1):
  point = 0
  for _x in x:
    point += (_x - p) ** 2
    #print(p, _x, point)
  point_list.append(point)
#print(point_list)
print(min(point_list))

Measured memory_bytes: 3064
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M = MI()
    ans = 0
    L = tuple(TI() for i in range(M))
    seq = [i for i in range(M)]
    
    for i in seq:
        Union = UnionFind(N)
        for j in filter(lambda x: x != i, seq):
            a, b = L[j]
            Union.union(a-1, b-1)
            
        a, b = L[i]
        if not Union.same(a-1,b-1):
            ans += 1
            
    print(ans)   
        
    
        
    
if __name__ == "__main__":
    main()

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

int main(void){
    string s ;
    cin >> s ;
    if (s=="Sunny"){
        cout << "Cloudy" << endl ;
    } else if (s=="Cloudy"){
        cout << "Rainy" << endl ;
    } else {
        cout << "Sunny" << endl ;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e3 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

struct node{
	ll val,id;
	bool operator<(const node& a)const{
		return val > a.val;
	}
}a[maxn];
ll dp[maxn][maxn];
int main(){
	int n;scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%lld",&a[i].val);a[i].id = i;
	}
	sort(a + 1,a + 1 + n);
	for(int i = 1;i <= n;i++){
		node tmp = a[i];
		for(ll l = 1,r = n - i + 1;r <= n;l++,r++){
			dp[i][l] = max(dp[i][l],dp[i - 1][l - 1] + abs(tmp.id - l) * tmp.val);
			dp[i][l - 1] = max(dp[i][l - 1],dp[i - 1][l - 1] + abs(tmp.id - r) * tmp.val);
		}
	}
	ll ans = 0;
	for(int i  = 1;i <= n;i++) ans = max(ans,dp[n][i]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 26412
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

ll N, M, L, Q;
ll fuel[305][305];
ll dist[305][305];
ll s[105000], t[105000];
ll A[100000], B[100000], C[100000];

int main() {
	cin >> N >> M >> L;
    rep (i, M) {
        cin >> A[i] >> B[i] >> C[i];
        A[i] -= 1;
        B[i] -= 1;
    }
    cin >> Q;
    rep (i, Q) {
        cin >> s[i] >> t[i];
        s[i] -= 1;
        t[i] -= 1;
    }

    rep (i, N) {
        rep (j, N) {
            fuel[i][j] = LINF;
            dist[i][j] = LINF;
        }
        fuel[i][i] = 0;
        dist[i][i] = 0;
    }
    rep (i, M) {
        chmin(fuel[A[i]][B[i]], C[i]);
        chmin(fuel[B[i]][A[i]], C[i]);
    }
    rep (i, N) rep (j, N) rep (k, N) {
        chmin(fuel[j][k], fuel[j][i] + fuel[i][k]);
    }
    rep (i, N) rep(j, N) {
        if (i==j) continue;
        if (fuel[i][j] <= L) chmin(dist[i][j], 1LL);
    }
    rep (i, N) rep(j, N) rep(k, N) {
        chmin(dist[j][k], dist[j][i] + dist[i][k]);
    }

    rep(i, Q) {
        if(dist[t[i]][s[i]] < LINF) cout << dist[t[i]][s[i]] - 1 << endl;
        else cout << -1 << endl;
    }
	return 0;
}


Measured memory_bytes: 4864
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool calc(string s) {
    if (s.startsWith("keyence")) return true;
    if (s.startsWith("k") && s.endsWith("eyence")) return true;
    if (s.startsWith("ke") && s.endsWith("yence")) return true;
    if (s.startsWith("key") && s.endsWith("ence")) return true;
    if (s.startsWith("keye") && s.endsWith("nce")) return true;
    if (s.startsWith("keyen") && s.endsWith("ce")) return true;
    if (s.startsWith("keyenc") && s.endsWith("e")) return true;
    if (s.endsWith("keyence")) return true;

    return false;
}

void main() {
    string s = read!string;
    writeln(calc(s) ? "YES" : "NO");
}


Measured memory_bytes: 256
from sys import stdin

def main():
  read = stdin.readline
  N = int(read())
  data = list(map(int,read().split(" ")))
  ans = 1
  flg = False
  if 0 in data:
    print("0")
    flg = True
    exit()
  for i in data:
    
    if ans*i > 10**18:
      print("-1")
      flg = True
      break
    else:
      ans *= i
      
  if not flg:  
    print(ans)
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 21720
using System;

namespace _0280
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int[] motihuda = new int[n];
                string huda = Console.ReadLine();
                int ba = 0;
                for (int i = 0; i < 100; i++)
                {
                    switch (huda[i])
                    {
                        case ('M'):
                            {
                                motihuda[i % n]++;
                                break;
                            }
                        case ('S'):
                            {
                                ba += motihuda[i % n] + 1;
                                motihuda[i % n] = 0;
                                break;
                            }
                        case ('L'):
                            {
                                motihuda[i % n] += ba + 1;
                                ba = 0;
                                break;
                            }
                    }
                }
                Array.Sort(motihuda);
                Console.Write(motihuda[0]);
                for (int i = 1; i < n; i++) Console.Write(" " + motihuda[i]);
                Console.WriteLine(" " + ba);
            }
        }
    }
}

Measured memory_bytes: 9316
# Problem B - Two Colors Card Game

# input
N = int(input())
s_list = {}
for i in range(N):
    s = input()
    if s in s_list:
        s_list[s] += 1
    else:
        s_list[s] = 1
M = int(input())
t_list = {}
for i in range(M):
    t = input()
    if t in t_list:
        t_list[t] += 1
    else:
        t_list[t] = 1

# initialization
max_cost = 0

# count step
for s in s_list:
    s_cost = s_list[s]
    if s in t_list:
        max_cost = max(max_cost, s_cost - t_list[s])
    else:
        max_cost = max(max_cost, s_cost)

# output
print(max_cost)


Measured memory_bytes: 38564
import std;

void calc(int[] a, int[][] adj) {
    auto dp = new int[a.length].assumeSorted;
    foreach (i; 0..a.length) dp[i] = int.max;
    auto ans = new ulong[a.length];

    void dfs(int node, int prev) {
        auto x = dp.lowerBound(a[node]);
        auto old = dp[x.length];
        dp[x.length] = a[node];

        ans[node] = dp.lowerBound(int.max).length;
        foreach (to; adj[node]) {
            if (to == prev) continue;
            dfs(to, node);
        }

        dp[x.length] = old;
    }

    dfs(0, -1);
    foreach (e; ans) writeln(e);
}

void main() {
    int n; scan(n);
    auto a = readints;
    int[][] adj;
    foreach (_; 0..n) adj ~= [[]];
    foreach (_; 0..n-1) {
        int u, v; scan(u, v);
        u--; v--;
        adj[u] ~= v;
        adj[v] ~= u;
    }
    calc(a, adj);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 48360
#include <iostream>
#include <algorithm>

using namespace std;

class UnionFind
{
public:
    void init ()
    {
        for (int i=1; i<100010; i++) link[i]=i;
        for (int i=1; i<100010; i++) sze[i]=1;
    }
    int Find (int x)
    {
        int y=x;
        while (x!=link[x]) x=link[x];
        link[y]=x;
        return x;
    }
    bool same (int a, int b)
    {
        return Find(a)==Find(b);
    }
    void unite (int a, int b) //join the sets that contains element a and b
    {                         //(a and b have to be in different sets)
        a=Find(a);
        b=Find(b);
        if (sze[a]<sze[b]) swap(a, b);
        sze[a]+=sze[b]; //connect smaller set to larger set
        link[b]=a;
    }
private:
    int link[100010], sze[100010];
};

int main ()
{
    int n, m, x, y, p[100010], ans=0;
    UnionFind U;
    U.init();
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>p[i];
    for (int i=0; i<m; i++)
    {
        cin>>x>>y;
        if (!U.same(p[x], p[y])) U.unite(p[x], p[y]);
    }
    for (int i=1; i<=n; i++)
    {
        if (U.same(i, p[i])) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0; i<=k; ++i){
        for(int j=0; j<=k; ++j){
            if(s-i-j>=0&&s-i-j<=k)ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
class Node
  attr_accessor :id, :children, :visited, :d, :f
  
  def initialize(id)
    @id = id
    @children = []
    @visited = false
    @d = nil
    @f = nil
  end 

  def add_child(node)
    @children << node
  end

  def visit
    @visited = true
  end

  def to_s
    "#{@id}"
  end

  def unvisited_child
    self.children.each do | child |
      return child unless child.visited
    end
    nil
  end

  def dfs_recursive
    self.visit
    self.children.each do | child |
      child.dfs unless child.visited
    end
  end

  def dfs_stack(time)
    self.visit
    stack = [self]
    self.d = time
    while not stack.empty?
      time += 1
      u = stack.last
      v = u.unvisited_child
      if v
        v.visit
        v.d = time
        stack << v
      else
        v = stack.pop
        v.f = time
      end
    end
    return time
  end

end

n = gets.to_i
tree = Array.new(n+1){ | i | Node.new(i) }
tree[0] = nil

n.times do
  # v -> '親', '子の数', ['子', ...]
  v = gets.split.map(&:to_i)
  id = v.shift; v.shift
  v.each do | cid |
    tree[id].add_child(tree[cid])
  end
end

time = 0
1.upto(n) do | i |
  time = tree[i].dfs_stack(time+1) unless tree[i].d
end

1.upto(n) do | i |
  puts "#{i} #{tree[i].d} #{tree[i].f}"
end



Measured memory_bytes: 6908
using System;
using System.Linq;

class Test
{
    static void Main()
    {
        int taro = 0;
        int hanako = 0;
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            string[] ss = Console.ReadLine().Split();

            switch (ss[0].CompareTo(ss[1]))
            {
                case 1:
                    taro += 3;
                    break;
                case -1:
                    hanako += 3;
                    break;
                case 0:
                    taro++;
                    hanako++;
                    break;
            }
        }

        Console.WriteLine("{0} {1}", taro, hanako);
    }
}


Measured memory_bytes: 16752
<?php
fscanf(STDIN, "%d", $n);
$v = explode(" ", trim(fgets(STDIN)));
$e = $o = [PHP_INT_MAX => 0];
foreach ($v as $k => $x) {
    if ($k % 2 === 0) {
        isset($e[$x]) ? $e[$x]++ : $e[$x] = 1;
    } else {
        isset($o[$x]) ? $o[$x]++ : $o[$x] = 1;
    }
}
arsort($e);
arsort($o);
// var_dump($e);
// var_dump($o);
$e_key = array_keys($e);
$e_val = array_values($e);
$o_key = array_keys($o);
$o_val = array_values($o);
if ($e_key[0] === $o_key[0]) {
    echo $n - max($e_val[0] + $o_val[1], $e_val[1] + $o_val[0]);
} else {
    echo $n - $e_val[0] - $o_val[0];
}


Measured memory_bytes: 25076
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    vector<string>v;
    v.push_back("KIHBR");
    v.push_back("AKIHBR");
    v.push_back("KIHABR");
    v.push_back("KIHBAR");
    v.push_back("KIHBRA");
    v.push_back("AKIHABR");
    v.push_back("AKIHBAR");
    v.push_back("AKIHBRA");
    v.push_back("KIHABAR");
    v.push_back("KIHABRA");
    v.push_back("KIHBARA");
    v.push_back("AKIHABAR");
    v.push_back("AKIHABRA");
    v.push_back("KIHABARA");
    v.push_back("AKIHABARA");
    rep(i,v.size()){
        if(s==v[i])return YES,0;
    }
    NO;
}


Measured memory_bytes: 256
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

ans = 10**9
for m in range(4**n):
    length = [0, 0, 0, 0]
    counts = [0, 0, 0, 0]
    for d in range(n-1, -1, -1):
        i = m//(4**d)
        length[i] += l[d]
        counts[i] += 1
        m %= 4**d
        
    if 0 in length[:3]:
        continue
    ans_tmp = 0
    for i in range(3):
        ans_tmp += abs([a,b,c][i] - length[i]) + 10*(counts[i]-1)
    ans = min(ans, ans_tmp)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(ll i=a;i<n;i++)
#define rfore(i, a, b) for(ll i = b - 1; i >= (ll)a; i--)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define mm(a,b) memset(a,b,sizeof(a));
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define INFI ((ll)1e9)
#define MINI ((ll)-1e15)
#define EPS 1e-9
#define endl "\n"
using namespace std;
typedef long long ll;  
typedef long double ld;
const ll MOD = 1e9+7;     
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const ll MAXN =300005;
ll n,t,q,x,s,k,m,h;
ll dp[1001][10001];
ll a[1001], b[1001];
ll solve(ll i, ll h){
    if(i>=n && h>0)return INFI;
    if(h<=0)return 0;
    ll &r = dp[i][h];
    if(~r)return r;
    r = INFI;
    r = min(solve(i+1,h),b[i]+solve(i,h-a[i]));
    return r;
}
int main(){
    cin >> h >> n;
    fore(i,0,n)cin>>a[i]>>b[i];
    mm(dp,-1);
    cout << solve(0,h);
    return 0;
}


Measured memory_bytes: 78976
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const int inf = 1e9;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

int main() {
	int n;	cin >> n;
	vector<vint> a(2, vint(n));
	rep(i, 2)	rep(j, n)	cin >> a[i][j];
	int ret = 0;
	rep(i, n) {
		int tmp = 0;
		REP(j, i)	tmp += a[0][j];
		srep(j, i, n)	tmp += a[1][j];
		ret = max(ret, tmp);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

		int n = scanner.nextInt();
		int[] numbers = new int[n];
		int alice = 0;
		int bob = 0;

		for (int i = 0; i < n; i++) {
			numbers[i] = scanner.nextInt();
		}
		Arrays.sort(numbers);

		for (int i = n - 1; i >= 0; i--) {
			if (i % 2 == 0) {
				alice += numbers[i];
			} else {
				bob += numbers[i];
			}
		}

		System.out.println(Math.abs(alice - bob));

		System.out.println();

		scanner.close();
	}
}

Measured memory_bytes: 21332
def inpl():
    return list(map(int, input().split()))


N = int(input())

A = inpl()
A.sort()

if N % 2 == 1:
    a = 1
    if A[0] != 0:
        print(0)
        exit()
else:
    a = 0

ans = 1
for j, i in enumerate(range(a, N, 2)):
    if A[i] == A[i + 1] == 2 * (j + 1) - (a + 1) % 2:
        ans *= 2
    else:
        print(0)
        exit()
print(ans % (10**9 + 7))


Measured memory_bytes: 14008
def examA():
    S = SI()
    if S=="AAA" or S=="BBB":
        print("No")
    else:
        print("Yes")
    return

def examB():
    N, A, B = LI()
    loop = N//(A+B)
    ans = loop*A + min(A,N%(A+B))
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

Measured memory_bytes: 4848
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var H = sc.nextInt();
        var W = sc.nextInt();
        WriteLine(new string('#', W + 2));
        for (int i = 0; i < H; i++) {
            WriteLine("#" + ReadLine() + "#");
        }
        WriteLine(new string('#', W + 2));

    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13140
N = gets.to_i
Ps = gets.split.map(&:to_i)
Qs = gets.split.map(&:to_i)

Ns = [*1..N]

As = Ns.permutation(N).to_a

p = 0
q = 0

As.each_with_index{|a, i|
  p = i if a == Ps
  q = i if a == Qs
}

ans = (p - q).abs

puts ans


Measured memory_bytes: 6780
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

struct work {
    int l, r;
    work(int l, int r):l(l), r(r) {}
    bool operator<(const work& w) {
        return r < w.r;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int A, B;
    vector<work> W;
    rep(_, 0, N) {
        cin >> A >> B;
        W.emplace_back(A, B);
    }
    sort(all(W));
    int now = 0;
    for (auto w : W) {
        if (now + w.l > w.r) {
            cout << "No" << endl;
            return 0;
        }
        now += w.l;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 2420
a, b, k = map(int, input().split())
if b-a+1 < 2*k:
    for i in range(a,b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)
    for i in range(b-k+1, b+1):
        print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;cin>>x>>y;
  int X,Y;
  if(x==2)X=3;
  else if(x==4 or x==6 or x==9 or x==11)X=2;
  else X=1;
  if(y==2)Y=3;
  else if(y==4 or y==6 or y==9 or y==11)Y=2;
  else Y=1;
  
  if(X==Y)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

#define REP(var,n) for(int var=0;var<(n);var++)
#define ALL(c) (c).begin(),(c).end()

ll solve(int N, int M, vector<ll>&  x, vector<ll>& y, vector<ll>& z){
    ll best =0;
    for(int pm1=-1;pm1<=1;pm1+=2)
        for(int pm2=-1;pm2<=1;pm2+=2)
            for(int pm3=-1;pm3<=1;pm3+=2){
                vector<ll> s(N);
                REP(i,N){
                    s[i] = x[i]*pm1 + y[i]*pm2 + z[i]*pm3;
                }
                sort(ALL(s)); reverse(ALL(s));
                ll score = 0;
                REP(i,M) score += s[i];
                best = max(best, score);
            }
    return best;
}

int main()
{
    int N,M; cin >> N >> M;
    vector<ll> x(N), y(N), z(N);

    REP(i,N){
        cin >> x[i] >> y[i] >> z[i];
    }
    cout << solve(N,M,x,y,z) << endl;

    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int ans = 1 << 30;
	for(char c = 'a'; c <= 'z'; c++){
		int p = 0, tmp = -(1 << 30);
		for(int i = 0; i < s.size(); i++){
			if(s[i] == c){
				tmp = max(tmp, i - p);
				p = i + 1;
			}
		}
		tmp = max(tmp, int(s.size()) - p);
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}


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

int main(){
  int a, b;


  int sum;
  while(1){
    int pattern=0;
    cin>>a>>b;
    if(a==0&&b==0) break;
    for(int i=0;i<a;i++){
      for(int j=i+1;j<a;j++){
        for(int k=j+1;k<a;k++){
          if((i+j+k+3)==b){
            pattern++;
          }
        }
      }
    }
    cout<<pattern<<endl;    
  }

  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	char B;
	cin >> B;
	if (B == 'A') {
		cout << 'T' << endl;
	}
	if (B == 'T') {
		cout << 'A' << endl;
	}
	if (B == 'C') {
		cout << 'G' << endl;
	}
	if (B == 'G') {
		cout << 'C' << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int sum_a = 0, sum_b = 0;
  vector<int> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  sort (a.begin(), a.end());
  reverse (a.begin(), a.end());
  
  for (int j = 0; j < N; j++) {
    if (j % 2 == 0) {
      sum_a += a.at(j);
    }
    else {
      sum_b += a.at(j);
    }
  }
  
  cout << sum_a - sum_b << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int n,y;cin>>n>>y;
  	for(int i=0;i<=n;i++){
    	for(int j=0;j<=n-i;j++){
          	int k=n-i-j;
 			if(y==10000*i+5000*j+1000*k){
            	cout<<i<<" "<<j<<" "<<k<<endl;
              	return 0;
            }
        }
    }
  	cout<<-1<<" "<<-1<<" "<<-1<<endl;
}


Measured memory_bytes: 256
import sys

def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())

n,k = get_ints()
Arr = get_array()

if k>=n:
    print(0)
    exit()

Arr.sort(reverse = True)
ans = 0
for i in range(k,n):
    ans+=Arr[i]
print(ans)

Measured memory_bytes: 78804
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[][] switches = new int[m][];
		int[] p = new int[m];

		int Allptr = (int) Math.pow(2, n);
		boolean[] light = new boolean[Allptr];
		Arrays.fill(light, true);

		for ( int i = 0; i < m; i++ ) {
			int k = in.nextInt();
			int[] s = new int[k];
			for ( int j = 0; j < k; j++ ) {
				s[j] = in.nextInt();
			}
			switches[i] = s;
		}
		for ( int i = 0; i < m; i++ ) {
			p[i] = in.nextInt();
		}

		// スイッチのパターンを上限まで列挙
		for ( int ptr = 0; ptr < Allptr; ptr++ ) {
			// 電球ごとのスイッチパターンと照らし合わせる
			for ( int d = 0; d < m; d++ ) {
				int temp = 0;
				for ( int i : switches[d] ) {
					// System.out.println("switch:" + i);
					int mask = 1 << (i - 1);
					temp += ((ptr & mask) >> (i - 1));
				}
				// System.out.println("temp:" + temp);
				if ( temp % 2 != p[d] ) {
					light[ptr] = false;
					break;
				}
				// if(d == m-1)System.out.println("ptr:" + Integer.toBinaryString(ptr) + " is OK");
			}
		}

		int cnt = 0;
		for ( int i = 0; i < Allptr; i++) {
			if ( light[i] ) {
				// System.out.println(Integer.toBinaryString(i));
				cnt++;
			}
		}

		System.out.println(cnt);

		// 確認用
//		for ( int i = 0; i < m; i++ ) {
//			System.out.print("電球 " + i + "     p: " + p[i] + "    s: ");
//			for ( int j : switches[i] ) {
//				System.out.print(j + " ");
//			}
//			//System.out.print(" p:" + p[i]);			
//			System.out.println();
//		}
		in.close();
	}
}


Measured memory_bytes: 23764