akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include<stdlib.h>
int asc(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int main(void){
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    qsort(a,3,sizeof(int),asc);
    if((a[0]==a[1] || a[1]==a[2]) && a[0]!=a[2]) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_string = '';

process.stdin.on('data', function (chunk) {
    input_string = chunk;
    const lines = input_string;
    const c = []
    c.push(lines.split(' ').map(value => parseFloat(value)));

    // console.log("c:", c);
    var A = c[0][0];
    var B = c[0][1];

    console.log(Math.floor(A * B));

});





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

ll power(ll x,ll y,ll p)  
{  
    ll res = 1;     // Initialize result  
    if(y == 0)
        return(1 % p);
    
    x = x % p; // Update x if it is more than or  
                // equal to p 
    if (x == 0)
        return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {   
        // If y is odd, multiply x with result  
        if (y & 1LL)  
            res = (res * x) % p;  
  
        // y must be even now  
        y = y >> 1LL; // y = y/2  
        x = (x * x) % p;  
    }
    
    return res;  
}

ll solve(ll N) //N is of order 1e5
{
    ll c = 1;
    while(N)
    {
        ll set = __builtin_popcount(N);
        N = N % set;
        c++;
    }
    
    return(c);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll T = 1;
    while(T--)
    {
        ll L,R,D; cin>>L>>R>>D;
        ll ans = 0;
        for(ll i=L;i<=R;++i)
        {
            if(i%D == 0)
                ans++;
        }
        
        cout<<ans<<endl;
    }
}

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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	while(cin>>n>>m,n||m){
		VV(double) vv;
		initvv(vv, n, n);
		rep(i,n){
			rep(j,n){
				cin>>vv[i][j];
			}
		}
		vector<double> dist(n,1.0);
		rep(i,m-1){
			vector<double> pre = dist;
			dist = vector<double>(n,0.0);
			rep(j,n){
				rep(k,n){
					maxs(dist[j], pre[k]*vv[k][j]);
				}
			}
		}
		double ans = 0.0;
		rep(i,n){
			maxs(ans, dist[i]);
		}
		printf("%.2lf\n", ans);
	}	
}


signed main() {
    mainmain();
}

Measured memory_bytes: 3264
#include<stdio.h>

#define N 100

int main( ){
  int i,j,k,v,m,n,u,Adj[N][N];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      Adj[i][j] = 0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      Adj[u][v] = 1;
    }
  }

    for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",Adj[i][j]);
    }
    printf("\n");
  }
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(void){
    int i,n,h,a,sum=0;
    cin >> h >> n;
    for(i=0; i<n; i++){
        cin >> a;
        sum+=a;
    }
    if(sum < h){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
cou = n
l_h = []
for i in range(n):
  x,l  = map(int,input().split())
  l_h.append([x-l,x+l])
l_h.sort(key=lambda x: x[1])
d = deque(l_h)
t= d.popleft()
a,b = t[0],t[1]
for i in range(n-1):
  m= d.popleft()
  c,e= m[0],m[1]
  if b<=c:
    b = e
  else:
    cou -= 1
print(cou)
  

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int n,m,c;
  cin>>n>>m>>c;
  vector<int> b(m);
  int a,sum=0,cnt=0;
  r(i,m)cin>>b.at(i);

  r(i,n){
    r(j,m){
      cin>>a;
      sum+=a*b.at(j);
    }
    if(sum+c>0)cnt++;
    sum=0;
  }
  cout<<cnt<<endl;

return 0;}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static String KEYENCE = "keyence";

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String line = in.nextLine();
		in.close();
		List<String> startStrs = startStrs(line);
		List<String> endStrs = endStrs(line);
		boolean enable = false;
		for (String startStr : startStrs) {
			for (String endStr : endStrs) {
				if (KEYENCE.equals(startStr + endStr)) {
					enable = true;
					break;
				}
			}
			if (enable) {
				break;
			}
		}
		if (line.startsWith(KEYENCE)) {
			enable = true;
		}
		if (line.endsWith(KEYENCE)) {
			enable = true;
		}
		if (enable) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	static List<String> startStrs(String line) {
		List<String> result = new ArrayList<>();
		for (int i = 1; i <= KEYENCE.length(); ++i) {
			result.add(line.substring(0, i));
		}
		return result;
	}

	static List<String> endStrs(String line) {
		List<String> result = new ArrayList<>();
		for (int i = line.length() - 1; i >= line.length() - KEYENCE.length(); --i) {
			result.add(line.substring(i, line.length()));
		}
		return result;
	}

}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

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

    int h, w;
    cin >> h >> w;

    int n;
    cin >> n;

    vi a(n);
    rep(i, n) cin >> a[i];

    vector<int> v(h * w);

    int idx = 0;
    rep(i, n) {
        rep(j, a[i]) {
            v[idx] = i + 1;
            idx++;
        }
    }

    vector<vector<int>> ans(h, vector<int>(w));

    bool rev = true;
    rep(i, h) {
        rep(j, w) {
            int idx = i * w + j;

            if (rev) {
                ans[i][j] = v[idx];
            } else {
                ans[i][w - j - 1] = v[idx];
            }

            if (j == w - 1) {
                rev = !rev;
            }
        }
    }

    rep(i, h) {
        rep(j, w) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll nCr(int n,int k){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(void){
  int n;
  scanf("%d",&n);
  int a,cnt=1;
  FOR(n){
    scanf("%d",&a);
    if(a==cnt)cnt++;
  }
  if(cnt==1)cnt=n+2;
  PRN(n-cnt+1);
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse4.2")

#include <cstdio>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
typedef int key;

int main(){
	int r,c,n;
	scanf("%d%d%d",&r,&c,&n);
	unordered_map<key,vector<pair<key,long long>>>m;
	for(;n;n--){
		int s1,s2,d;
		scanf("%d%d%d",&s1,&s2,&d);
		m[s1].emplace_back(s2+r,d);
		m[s2+r].emplace_back(s1,-d);
	}
	for(;!m.empty();){
		long long a=-1LL<<61,b=1LL<<61;
		auto s=m.begin()->first;
		vector<pair<key,long long>>st={{s,0}};
		unordered_map<key,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.rbegin();st.pop_back();
			auto cur=p.first;long long d=p.second;
			memo[cur]=d;
			if(cur<=r)a=max(a,d);
			else b=min(b,d);
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return 0;
				}
			}
		}
		if(a>b){
			puts("No");
			return 0;
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}

Measured memory_bytes: 17864
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,x = inm()
a = inl()
sm = 0
if a[0]>x:
    sm = a[0]-x
    a[0] = x
for i in range(1,n):
    d = a[i]+a[i-1]-x
    if d>0:
        a[i] -= d
        sm += d
print(sm)


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

#define MAXN (int)(2 * 1e5 + 1)
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if (0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int, int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};


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

  string s;
  cin >> s;
  set<char> aux;

  for(auto i : s) aux.insert(i);

  if(aux.size() > 1) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	if (abs(n) > abs(m)) {
		if (n > 0 && m > 0) { cout<< abs(n) - abs(m) + 2 << endl; }
		if (n > 0 && m == 0) { cout << abs(n) + 1 << endl; }
		if (n < 0 && m == 0) { cout << abs(n) << endl; }
		if (n < 0 && m > 0) { cout << abs(n) - abs(m) + 1 << endl; }
		if (n > 0 && m < 0){ cout << abs(n) - abs(m) + 1 << endl; }
		if (n < 0 && m < 0) { cout << abs(n) - abs(m) << endl; }
	}
	else if (abs(n) == abs(m)) {
		cout << 1 << endl;
	}
	else {
		if (n > 0 && m > 0) { cout << m - n << endl; }
		if (n == 0 && m > 0) { cout << m - n << endl; }
		if (n == 0 && m < 0) { cout << n - m + 1 << endl; }
		if (n < 0 && m < 0) { cout << abs(m) - abs(n) + 2 << endl; }
		if (n > 0 && m < 0) { cout << abs(m) - n + 1 << endl; }
		if (n < 0 && m > 0) { cout << m - abs(n) + 1 << endl; }
	}
	cin >> n;
}

Measured memory_bytes: 256
//Author: master19
#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 ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
void debug_out() { cerr << endl; }
template <typename HeadStart, typename... TailEnd>
void debug_out(HeadStart H, TailEnd... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll lets_do_it();
pair < ll, ll > xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
pair < ll, ll > dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
bool isValid(ll x, ll y, ll row, ll col){
    return ((x>=0) && (y >=0)  && (x < row) && (y < col));
}
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    // Your code goes by here !!
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll value = max(a*c, a*d);
    value = max(value, max(b*c, b*d));
    cout << value << endl;





    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int P=1e9+7;
const int N=2e5+10;
int n,m,k;
LL fac[N],inv[N];

LL power(LL x,LL p) {
	LL ret=1;
	for (;p;p>>=1) {
		if (p&1) ret=ret*x%P;
		x=x*x%P;
	}
	return ret;
}

void prework() {
	fac[0]=1; inv[0]=power(fac[0],P-2);
	for (int i=1;i<=200000;i++) {
		fac[i]=fac[i-1]*i%P;
		inv[i]=power(fac[i],P-2);
	}
}

LL C(LL n,LL m) {
	return fac[n]*inv[m]%P*inv[n-m]%P;
}

int main()
{
	prework();
	cin>>n>>m>>k;
	LL ans=C(n*m,k)%P*C(k,2)%P*(n+m)%P*power(3,P-2)%P;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std; 
int main(){
    int n;
    cin >> n;
    vector<vector<int>> arr(n, vector<int>(3)),  dp(n, vector<int>(3));
    for (auto &i: arr)
        for (auto &j: i)
            cin >> j;
    dp[0] = arr[0];
    for (int i=1; i<n; i++){
        dp[i][0] = arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = arr[i][1] +max(dp[i-1][0], dp[i-1][2]) ;
        dp[i][2] = arr[i][2] +max(dp[i-1][0], dp[i-1][1]);
    }
    cout << *max_element(dp.back().begin(), dp.back().end()) <<"\n";
}

Measured memory_bytes: 14004
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int main() {
  while( 1 ) {
    int n;
    map<string, string> table;
    cin >> n;
    if( !n ) { break; }
    for( int i = 0; i < n; i++ ) {
      string src, dest;
      cin >> src >> dest;
      table[ src ] = dest;
    }

    cin >> n;
    vector<string> seq;
    for( int i = 0; i < n; i++ ) {
      string s;
      cin >> s;
      if( table.find( s ) == table.end() ) {
        cout << s << flush;
      } else {
        cout << table[ s ] << flush;
      }
    }
    cout << endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1208
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] data = new int[3];
        data[0] = sc.nextInt();
        data[1] = sc.nextInt();
        data[2] = sc.nextInt();
        int n = 0;
        if (data[0] > data[1]) {
            n = data[0];
            data[0] = data[1];
            data[1] = n;
        }
        if (data[0] > data[2]) {
            n = data[0];
            data[0] = data[2];
            data[2] = n;
        }
        if (data[1] > data[2]) {
            n = data[1];
            data[1] = data[2];
            data[2] = n;
        }
        System.out.println(data[0] + " " + data[1] + " " + data[2]);
        sc.close();
    }
}


Measured memory_bytes: 26424
#include<stdio.h>


int fib(int);
int a[45];

int main(){
  int n,r,i;

  scanf("%d",&n);
  for(i=0;i<45;i++){
    a[i]=0;
  }
  r=fib(n);

  printf("%d\n",r);

  return 0;
}

int fib(int n){
  int i;
  a[1]=1;
  a[0]=1;
  
  if(n==0) return 1;
  else if(n==1) return 1;
 
  if(a[n]!=0){
    return a[n];
  }
  a[n]=fib(n-1)+fib(n-2);
  return a[n];
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=10005;
int x[N],y[N],cnt[N];
int SA[N],n,k;
char s[N];
bool cmp(int i,int j,int k,int n){
	return y[i]!=y[j]||((i+k>n?-1:y[i+k])!=(j+k>n?-1:y[j+k]));
}
void build_SA(int n){
	int m=26;
	For(i,0,m) cnt[i]=0;
	For(i,1,n) cnt[x[i]=s[i]-'a'+1]++;
	For(i,1,m) cnt[i]+=cnt[i-1];
	Rep(i,n,1) SA[cnt[x[i]]--]=i;
	for (int k=1;k<n;k<<=1){
		int p=0;
		For(i,n-k+1,n) y[++p]=i;
		For(i,1,n) if (SA[i]>k) y[++p]=SA[i]-k;
		For(i,0,m) cnt[i]=0;
		For(i,1,n) cnt[x[y[i]]]++;
		For(i,1,m) cnt[i]+=cnt[i-1];
		Rep(i,n,1) SA[cnt[x[y[i]]]--]=y[i];
		swap(x,y); m=x[SA[1]]=1;
		For(i,2,n) x[SA[i]]=(m+=cmp(SA[i-1],SA[i],k,n));
		if (k==n) break;
	}
}
int main(){
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	For(T,1,min(k,20)){
		if (T!=1) reverse(s+1,s+n+1);
		For(i,1,n) s[n+i]=s[n-i+1];
		build_SA(2*n);
		For(i,1,n) if (SA[i]<=n+1){
			int d=SA[i]-1;
			For(j,1,n) s[j]=s[j+d];
			break;
		}
	}
	For(i,1,n)
		putchar(s[i]);
}

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

int main(){
	long N;
	cin >> N;
	vector<long> A(N);
	for(long i=0; i<N; i++) cin >> A.at(i);

	long buf;
	long count = 0;
	bool flg = true;
	while(flg){
		flg = false;
		for(long j=N-1; j>0; j--){
			if(A.at(j) < A.at(j-1)){
				buf = A.at(j);
				A.at(j) = A.at(j-1);
				A.at(j-1) = buf;
				flg = true;
				count++;
			}
		}
	}

	for(long i=0; i<N; i++){
		cout << A.at(i);
		if(i<N-1) cout << " ";
	}
	cout << endl;
	cout << count << endl;
}



Measured memory_bytes: 3100
#include <cstdio>

using namespace std;

int n;
int a[200043];

int main() {
  scanf("%d", &n);
  int xorsum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    xorsum ^= a[i];
  }
  for (int i = 0; i < n; ++i) {
    printf("%d ", xorsum ^ a[i]);
  }
  printf("\n");
  return 0;
}

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

using namespace std;
typedef long long ll;

const int N=300005;
vector<int> tree(4*N,0);

void update(int idx,int l,int r,int pos,int val)
{
    if(l==r) tree[idx]+=val;
    else
    {
        int m=(l+r)/2;
        if(pos<=m) update(2*idx,l,m,pos,val);
        else update(2*idx+1,m+1,r,pos,val);
        tree[idx]=max(tree[2*idx],tree[2*idx+1]);
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    int c;
    cin >> c;
    vector<vector<int>> v(m+1);
    for(int i=0;i<c;i++)
    {
        int a,b;
        cin >> a >> b;
        v[b].push_back(a);
        update(1,1,n,a,1);
    }
    int res=0;
    for(int i=1;i<=m;i++)
    {
        for(int a:v[i]) update(1,1,n,a,-1);
        res=max(res,(int)(tree[1]+v[i].size()));
        for(int a:v[i]) update(1,1,n,a,1);
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 24308
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

def dfs(i, d, ans):
    if d[0]<0 or d[1]<0 or d[2]<0:
        return
    if i == N:
        print('Yes')
        for m in ans:
            print(m)
        exit()
    s, t = cv(S[i][0]), cv(S[i][1])
    d[s] += 1
    d[t] -= 1
    #print(i, D[s], D[t])
    ans[i] = S[i][0]
    dfs(i+1, D, ans)
    d[s] -= 2
    d[t] += 2
    #print(i, D[s], D[t])
    ans[i] = S[i][1]
    dfs(i+1, d, ans)
    d[s] += 1
    d[t] -= 1

def cv(m):
    if m == 'A':
        return 0
    if m == 'B':
        return 1
    if m == 'C':
        return 2
'''
def dfs(i, A, B, C, ans):
    if A<0 or B<0 or C<0:
        return
    if i == N:
        print('Yes')
        for m in ans:
            print(m)
        exit()
    if S[i] == 'AB':
        ans[i] = 'A'
        dfs(i+1, A+1, B-1, C, ans)
        ans[i] = 'B'
        dfs(i+1, A-1, B+1, C, ans)
    if S[i] == 'BC':
        ans[i] = 'B'
        dfs(i+1, A, B+1, C-1, ans)
        ans[i] = 'C'
        dfs(i+1, A, B-1, C+1, ans)
    if S[i] == 'AC':
        ans[i] = 'A'
        dfs(i+1, A+1, B, C-1, ans)
        ans[i] = 'C'
        dfs(i+1, A-1, B, C+1, ans)
'''
N, *D = mi()
S = [sys.stdin.readline()[:2] for _ in range(N)]
ans = [0]*N
dfs(0, D, ans)
print('No')

Measured memory_bytes: 110788
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Data.Ord
import Control.Monad


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [n,m] <- r'
    pys <- replicateM m $ do
        [p,y] <- r'
        return (p,y)
    let numPY = zip [1..] pys :: [(Int,(Int,Int))]
    let srtdPY = sortBy (comparing snd) numPY
    let rnkdPY = rank (fst (head srtdPY), 1) srtdPY
    let finPY = map snd $ sortOn fst rnkdPY
    mapM_ (putStrLn.showCity) finPY


rank :: (Int, Int) -> [(Int,(Int,Int))] -> [(Int,(Int,Int))]
rank _ [] = []
rank (cPref, ac) ((city,(pref,year)):xs)
    | pref==cPref = (city,(pref,ac)):(rank (pref,ac+1) xs)
    | otherwise   = (city,(pref,1 )):(rank (pref, 1+1) xs)

showCity :: (Int,Int) -> String
showCity (pref,rank) =
    let pS = show pref
        rS = show rank
        pI = 6 - (length pS)
        rI = 6 - (length rS)
    in  replicate pI '0' ++ pS ++ replicate rI '0' ++ rS



Measured memory_bytes: 48124
#include <iostream>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  
  rep(i, 3) {
    if(N / (int)pow(10, 2-i) == 7) {
      cout << "Yes" << endl;
      return 0;
    }
    N = N % (int)pow(10, 2-i);
  }
  cout << "No" << endl; 
}

Measured memory_bytes: 3668
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    multiset<ll> s;
    set<ll> tmp;
    ll sum = 0;
    vector<ll> v;
    v.resize(n);
    for (int i = 0; i < n; i++) {
        sum += a[i];
        s.insert(sum);
        v[i] = sum;
        if (tmp.find(sum) == tmp.end()) {
            tmp.insert(sum);
        }
    }
    ll res = 0;
    for (auto it = tmp.begin(); it != tmp.end(); it++) {
        ll count = s.count(*it);
        res += count * (count - 1) / 2;
    }
    res += s.count(0);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 22144
N, K = map(int, input().split())
A = list(map(int, input().split()))
before = [0] * N
after = [0] * N
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if i < j:
            if A[i] > A[j]:
                after[i] += 1
        elif i > j:
            if A[i] > A[j]:
                before[i] += 1
sum_after = (sum(after) * (K * (K + 1)) // 2) % ((10 ** 9) + 7)
K -= 1
sum_before = (sum(before) * (K * (K + 1)) // 2) % ((10 ** 9) + 7)
ans = sum_after + sum_before
ans %= ((10 ** 9) + 7)
#print(after, before)
#print(sum_after, sum_before)
print(ans)

Measured memory_bytes: 68364
from functools import lru_cache

MOD = 998244353


def solve_baka(n, m, k):
    print('params:', n, m, k)
    ans = 0
    for i in range(m**n):
        s = ''
        for j in range(n):
            s = str(i % m) + s
            i = i // m
        cnt = 0
        for j in range(n-1):
            if s[j] == s[j+1]:
                cnt += 1
        if cnt <= k:
            ans += 1
        print(s, cnt <= k)
    print('ans:', ans)
    return ans


@lru_cache(maxsize=None)
def modpow(n, m):
    ret = 1
    while m > 0:
        if m & 1:
            ret = ret * n % MOD
        n = n * n % MOD
        m >>= 1
    return ret


def solve(n, m, k):
    factorial = [1]
    for i in range(1, max(n+1, m+1)):
        factorial.append(i*factorial[i-1] % MOD)
    permutation = [1]
    for i in list(range(1, n))[::-1]:
        permutation.append(i * permutation[-1] % MOD)

    ans = 0
    for i in range(0, k+1):
        val = m * permutation[i] % MOD
        val = val * modpow(factorial[i], MOD-2) % MOD
        val = val * modpow(m-1, n-1-i) % MOD
        ans = (ans + val) % MOD
    return ans


def main():
    # for n in range(3, 7):
    #     for m in range(1, 5):
    #         for k in range(0, n):
    #             assert solve_baka(n, m, k) == solve(n, m, k)
    n, m, k = map(int, input().split())
    print(solve(n, m, k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 181936
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int N;
  cin>>N;
  int M = 3*N;
  int ANS= 0;
  vector<int> vec (M,0);
  for (int i = 0; i < M; i++)
  {
    cin>>vec[i];
  }
  sort(ALL(vec),greater<int>());
  for (int i = 0; i < M; i++)
  {
    int X; X = vec[i];
    if(i%2 ==1 && i < 2*N)ANS += X;
  }
  cout<<ANS<<endl;
  
  return;
}




int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

int main(){
  int X;
  cin >> X;
  bool ans = true;
  if (X < 2000 && (X / 100 * 5) < (X % 100) && (X % 100) < 100) ans = false;
  
  if (ans) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db              double
#define ll              long long int
#define ld              long long double
//#define int           long long int
#define ull             unsigned long long
#define fi              first
#define se              second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl            '\n'
#define mem(a,b)        memset(a, b, sizeof a)
#define mkp             make_pair
#define pb              push_back
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)          a.begin(), a.end()
#define sz(a)           int((a).size())
#define dbg(x)          cerr << #x << " = " << x << endl;
//Bitwise 
#define isOn(S, j)      (S & (1<<j))
#define setBit(S, j)    (S |= (1<<j))
#define clearBit(S, j)  (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S)       (S & (-S))
#define setAll(S, n)    (S = (1<<n)-1)
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
//Can use tuples in C++17
using namespace std;
typedef map < int, int > mii;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
const db PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =          0.000001;
ll mod       =          998244353;   //(1e9+7)
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=2000008;
bool judge(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}
int main(){ 
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  cout.tie(NULL);
//  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
	int n,k;
	cin>>n>>k;
	vii arr(n);
	rep(i,0,n) cin>>arr[i];
	sort(all(arr));
	ll tot=0;
	rep(i,0,k) tot+=arr[i];
	cout<<tot<<endl;
    return 0;
}

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

int main(){
    int H, W;
    int A[80][80] = {0};
    cin >> H >> W;
    for(int t=0; t<2; t++) for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        int a;
        cin >> a;
        A[i][j] += a * (t==0 ? 1 : -1);
    }

    const int M = 80*160;
    static bitset<2*M> dp[80][80];
    dp[0][0][M] = 1;
    for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        if(i) dp[i][j] |= dp[i-1][j];
        if(j) dp[i][j] |= dp[i][j-1];
        int a = abs(A[i][j]);
        dp[i][j] = (dp[i][j]<<a) | (dp[i][j]>>a);
    }
    int ans = 1e9;
    for(int i=0; i<2*M; i++) if(dp[H-1][W-1][i]) ans = min(ans, abs(M-i));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int k = scanner.nextInt();
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();

        final boolean answer = IntStream.rangeClosed(a, b)
                .anyMatch(i -> i % k == 0);
        System.out.println(answer ? "OK" : "NG");
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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


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

using namespace std;
priority_queue<int> pq;
int main(){
	int n,m;
	cin >> n >> m;
	while(n--){
		int x;
		cin >> x;
		pq.push(x);
	}
	while(m--){
		int x = pq.top();
		pq.pop();
		pq.push(x/2);
	}
	long long ans = 0;
	while(pq.size()){
		ans += (long long)pq.top();
		pq.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
long long s[100001],n,k,ans=9999999999999;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	  	cin>>s[i];
	sort(s+1,s+n+1);
	for(int i=n-k;i>=0;i--)
	  {
	  	ans=min(ans,s[i+k]-s[i+1]);
	  }
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
def examC():
    N = I()
    a = LI()
    ansC = []
    """
        if a[0]<0:
        for i in range(N):
            a[i] = -a[i]
    """
    for l in range(2):
        sumA = 0
        ans = 0
        for i in range(N):
            sumA += a[i]
            if (i + l) % 2 == 0:
                if sumA >= 0:
                    ans += abs(sumA)+1
                    sumA = -1
            else:
                if sumA <= 0:
                    ans += abs(sumA)+1
                    sumA = 1
        ansC.append(ans)
    print(min(ansC))

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

int n;
int q, k;

struct LowestCommonAncestor {
  const int MAX_LOG_V = 30;

  int V, root = 0;
  vector<vector<pair<int, long long>>> G;
  vector<long long> depth, length;
  vector<vector<int> > parent;

  LowestCommonAncestor() {}
  LowestCommonAncestor(int V) : V(V) { init(); }
  LowestCommonAncestor(int V, int root) : V(V), root(root) { init(); }

  void init() {
    G.resize(V);
    depth.resize(V);
    length.resize(V);
    parent.resize(MAX_LOG_V, vector<int>(V));
  }

  void add_edge(int u, int v, long long c) {
    G[u].push_back(make_pair(v, c));
    G[v].push_back(make_pair(u, c));
  }

  void add_edge(int u, int v) {
    add_edge(u, v, 1ll);
  }

  void dfs(int v, int u, int d, long long l){
    depth[v] = d;
    length[v] = l;
    parent[0][v] = u;
    for (int i = 0; i < G[v].size(); ++i) {
      pair<int, long long> p = G[v][i];
      if (p.first != u) {
        dfs(p.first, v, d + 1, l + p.second);
      }
    }
  }

  void build() {
    dfs(root, -1, 0, 0ll);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
      for (int v = 0; v < V; v++) {
        if (parent[k][v] < 0) parent[k + 1][v] = -1;
        else parent[k + 1][v] = parent[k][parent[k][v]];
      }
    }
  }

  int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_V; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }

    if (u == v) return u;

    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }

    return parent[0][u];
  }

  long long dist(int u, int v) {
    int z = lca(u, v);
    return length[u] + length[v] - 2 * length[z];
  }
};

signed main() {
  cin >> n;

  LowestCommonAncestor LCA(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    u--; v--;

    LCA.add_edge(u, v, c);
  }

  LCA.build();

  cin >> q >> k;
  while (q--) {
    int x, y;
    cin >> x >> y;

    cout << LCA.dist(x - 1, k - 1) + LCA.dist(k - 1, y - 1) << endl;;
  }
}


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

typedef long long ll;

int main () {

    ll x;
    string s;
    cin >> x >> s;

    x = 0;
    ll ans = x;
    for(auto& e : s) {
	if(e == 'I') {
	    x++;
	}
	else{
	    x--;
	}
	ans = max(ans,x);
    }
    cout << ans << endl;

    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int x;
  cin>>x;
  Int n;
  cin>>n;
  vector<Int> rs(n);
  for(Int i=0;i<n;i++) cin>>rs[i];

  vector<Int> fs(n+1);
  fs[0]=-1;
  for(Int i=0;i<n;i++) fs[i+1]=fs[i]*-1;

  struct State{
    Int p,q,x,y;
    State(Int p,Int q,Int x,Int y):p(p),q(q),x(x),y(y){}
  };

  auto next=
    [&](State st,Int d)->State{
      st.x+=d;
      st.y+=d;
      if(st.y<=0){
        st.p=st.q=0;
        st.x=st.y=0;
        return st;
      }
      if(st.x>=x){
        st.p=st.q=0;
        st.x=st.y=x;
        return st;
      }
      if(st.x<0) st.p-=st.x,st.x=0;
      if(st.y>x) st.q-=(st.y-x),st.y=x;
      return st;
    };

  vector<State> st;
  st.emplace_back(0,x,0,x);
  for(Int i=0;i<n;i++){
    Int d=rs[i]-(i?rs[i-1]:0);
    auto nx=next(st[i],d*fs[i]);
    st.emplace_back(nx);
  }

  Int q;
  cin>>q;
  for(Int i=0;i<q;i++){
    Int t,a;
    cin>>t>>a;
    Int k=upper_bound(rs.begin(),rs.end(),t)-rs.begin();
    Int d=t-(k?rs[k-1]:0);
    auto res=next(st[k],d*fs[k]);
    // cout<<k<<":"<<d*fs[k]<<" ";
    // cout<<res.p<<" "<<res.q<<" "<<res.x<<" "<<res.y<<endl;

    if(a<=res.p) cout<<res.x<<"\n";
    else if(a<=res.q) cout<<res.x+(a-res.p)<<"\n";
    else cout<<res.y<<"\n";
  }
  return 0;
}


Measured memory_bytes: 8048
n,m=gets.split.map &:to_i
x=gets.split.map &:to_i
x.sort!
a=[]
for i in 0 .. m - 2
  a << x[i + 1] - x[i]
end
a.sort!
ans = 0
for i in 0 ... [0, m - n].max
  ans += a[i]
end
puts ans


Measured memory_bytes: 9968
#include <bits/stdc++.h>
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define oprecision                                                             \
  cout.precision(30);                                                          \
  cerr.precision(7);
#define bb bool
#define ii int
#define ll long long
#define ff float
#define dd double
#define cc char
#define ss string
#define forn(sz) for (int i = 1; i <= sz; i++)
#define forni(i, sz) for (int i = 1; i <= sz; i++)
#define fornid(i, m, sz) for (int i = m; i <= sz; i++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vii vector<ii>
#define vii64 vector<ll>
#define vb vector<bb>
using namespace std;
ss a, b;
ii cnt;
ii main() {
  speed;
  oprecision;
  /*#ifndef ONLINE_JUDGE
    freopen("outd.txt", "rt", stdin);
  #endif*/
  // code
  cin >> a >> b;
  for (int i = 0; i < 3; i++) {
    if (a[i] == b[i])
      cnt++;
  }
  cout << cnt;
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a,b,c;
    int x,y;
    scanf("%d %d %d",&a,&b,&c);
    for (x=a; x<=b; x++){
        if (c%x==0)y++;
    }
    printf("%d\n",y);
    return 0;
}

Measured memory_bytes: 596
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int n[]=new int[N];
        for(int i=0;i<N;i++){
            n[i]=sc.nextInt();
        }
        int max=0;
        int Alice=0;
        int Bob=0;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(n[j]>=max){
                    max=n[j];
                }
                
                }
            Alice=Alice+max;
            for(int j=0;j<N;j++){
                if(max==n[j]){
                    n[j]=0;
                    max=0;
                    break;
                }
            }
            for(int j=0;j<N;j++){
                if(n[j]>=max){
                    max=n[j];
                }
                
                }
            Bob=Bob+max;
            for(int j=0;j<N;j++){
                if(max==n[j]){
                    n[j]=0;
                    max=0;
                    break;
                }
            }
        }
        System.out.println(Alice-Bob);

        }
        
     
    }


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

int32_t main()
{
	int t=1;
	while(t--)
	{
		unsigned ll n,k;
		cin >> n >> k;
		
		cout << min(n%k,k-n%k);
	}
}




Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;



int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if(c >= a && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int bai(int x,int d){
  int i=0;
  while(i<d){
    x=x*2;
    i++;
  }
  return x;
}
int main(){
  int a,b,c,d,ans;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if(a>=b&&a>=c){
    ans=bai(a,d)+b+c;
  }
  else if(b>=c&&b>=a){
    ans=bai(b,d)+a+c;
  }
  else if(c>=b&&c>=a){
    ans=bai(c,d)+a+b;
  }
  printf("%d",ans);
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
    int A, B, C, X,cnt=0;
    cin >> A >> B >> C >> X;

    for (int i = 0; i <= A;i++){
        for (int j = 0; j <= B;j++){
            for (int k = 0; k <= C;k++){
                if(500*i+100*j+50*k==X){
                    cnt++;
                }
            }
        }
    }
    cout << cnt;
}

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

int main() {
	// your code goes here
	long int n ;
    int k,i ;
    cin>>n>>k ;
    for(i=0;n>0;++i)
    {
    	n=n/k ;
    }
    cout<<i ;
	return 0;
}

Measured memory_bytes: 256
/* "It's okay if you hate me. I hate me too." */

#include <bits/stdc++.h>

using namespace std;

const int maxN = (int)2E5+5;

int n;
int a[maxN];
int b[maxN];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	b[(n/2)+1] = a[1];
	int left = (n/2)+1, right = (n/2)+1;
	for (int i = 2; i <= n; ++i)
		if (i%2 == n%2) 
			b[--left] = a[i];
		else
			b[++right] = a[i];
	for (int i = 1; i <= n; ++i)
		printf("%d ", b[i]);
	puts("");
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main()
{
    int h, w, k; cin >> h >> w >> k;
    vector<bool> grid(h*w);

    char cij;
    int sum = 0;
    rep(i, h){
        rep(j, w){
            cin >> cij;
            if(cij == '#'){
                grid.at(i*w+j) = true;
                sum++;
            }else{
                grid.at(i*w+j) = false;
            }
        }
    }
    
    int ans = 0, cnt = 0;
    rep(red, 1<<(h+w)){
        rep(i, h){
            rep(j, w){
                int index = i*w+j;
                if(!(red & ((1<<j) + (1<<(i+w))))){
                    if(grid.at(i*w+j)) cnt++;
                }
            }
        }
        if(cnt == k) ans++;

        cnt = 0;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
main(){
    int N,K;
    int num[50];
    scanf("%d%d",&N,&K);
    for(int i = 0;i < N;i++){
        scanf("%d",&num[i]);
    }
    std::sort(num,num+N);
    int sum = 0;
    for(int i = N-1;i >= N-K;i--){
        sum += num[i];
    }
    printf("%d\n",sum);
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int n;
    cin >> n;
    ll dp[n+1];
    dp[0] = 2;
    dp[1] = 1;
    for (int i = 2; i <= n; ++i) dp[i] = dp[i - 1] + dp[i - 2];
    cout << dp[n];
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Solve s = new Solve();
		s.solve();
	}
}

class Solve{
	Scanner in = new Scanner(System.in);

	void solve(){
		int n = in.nextInt();
		Set<String> st = new HashSet<String>();
		for(int i = 0; i< n; i++) {
			String str = in.next();
			st.add(str);
		}
		boolean open = false;
		int m = in.nextInt();
		for(int i = 0; i< m; i++){
			String str = in.next();
			if(st.contains(str)) {
				if(open) System.out.println("Closed by " + str);
				else System.out.println("Opened by " + str);
				open = !open;
			}
			else System.out.println("Unknown " + str);
		}
	}
}

Measured memory_bytes: 28340