akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

int res[300000];

int main(){
	long long n, a, b;
	cin >> n >> a >> b;

	if(a+b > n+1 || a*b < n){
		cout << -1 << endl;
		return 0;
	}

	int r = n;
	int past = 0;
	int i=0;
	while(r > 0){
		int len;
		len = min(a, r - b + past + 1);
		for(int m=r-len+1; m<=r; m++)
			res[i++] = m;
		
		past += 1;
		r = r - len;
	}

	cout << res[0];
	for(int i=1; i<n; i++)
		cout << " " << res[i];
	cout << endl;


	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  
  int multiple4 = 0, odd = 0, even = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    
    if (x % 4 == 0) {
      multiple4++;
    } else if (x % 2) {
      odd++;
    }
    
  }
  
  even = N - multiple4 - odd;
  if (even) {
    if (multiple4 >= odd) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    } 
  } else {
    if (multiple4 >= odd - 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    int a[n]={0};
    rep(i,q){
        int b;
        cin >> b;
        b--;
        a[b]++;
    }
    rep(i,n){
        if(k-q+a[i]<=0)
            cout << "No" << endl;
        else {
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int en[3],k;
	for(int i=0;i<3;i++)cin>>en[i];
	cin>>k;
	int va[] = {1,0,-1};
	int res = 0;
	for(int i=0;i<3;i++){
		if(k>en[i]){
			res+=en[i]*va[i];
			k-=en[i];
		}
		else {
			res+=k*va[i];
			k=0;
		}
	}
	cout<<res<<endl;
	
	return 0;
}

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

int main(void){
    int long N;
    int long A[100000];
    int long i;
    int minus;
    minus = 0;

int cmp(const void *p, const void *q){
    return *(long int*)p - *(long int*)q;
}

    scanf("%ld", &N);

    for(i = 0; i < N; i++){
        scanf("%ld", &A[i]);
    }

    qsort(A, N, sizeof(long int), cmp);

    for (i = 0; i < N; i++){
        if (A[i] == A[i+1]){
            minus += 1;
            i++;
        }
    }

    printf("%ld\n", N - minus * 2);


}
    

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>

int main(void){
    int N, i;
    char S[1005];
    scanf("%s", S);
    N=0;
    for (i=0; i<strlen(S)/2; i++) {
        if (S[i]!=S[strlen(S)-i-1]) N++;
    }
    printf("%d", N);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,j,N,H,W,ans=0;
  cin>>N;
  if(N==1){
    cout<<"YES"<<endl;
    return 0;
  }
  vec v(N);
  rep(i,N){
    cin>>v[i];
    if(v[i]%2)ans++;
  }
  if(ans%2==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,s;
bitset<4100000>b(1);
int main()
{
	int x;
	cin>>n;
	while (n--)
	{
		cin>>x;
		s += x;
		b |= b << x;
	}
	int ans = s;
	for (int i = s;i >= (s + 1) >> 1;--i)
		if (b[i])
			ans = i;
	cout<<ans;
}

Measured memory_bytes: 1920
n = int(input())
numbers = [0 for i in range(n)]
total = 0
count = 0
for i in range(n):
    num = int(input())
    numbers[i] = num
    total += num
numbers = sorted(numbers)
if total % 10 == 0:
    for i in numbers:
        if i % 10 != 0:
            total = total - i
            count = 1
            break
else:
    count = 1
if count ==0:
    total = 0
print(str(total))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&c);
	int res=(a&1)+(b&1)+(c&1);
	if(res<=2)
	{
		printf("0");
		return 0;
	}
	if(a<b)swap(a,b);
	if(a<c)swap(a,c);
	printf("%lld",b*c);
}

Measured memory_bytes: 256
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    #s = str(stdin.readline().rstrip())
    n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = (2**m)* (((n-m) * 100) + 1900*m)
    print(ans)



main()


Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define int long long
using namespace std;

signed main()
{
	int a;
	while (cin >> a, a) 
	{
		int k = 0;
		vector<int>s(a);
		for (int b = 0; b < a; b++)cin >> s[b];
		sort(s.begin(), s.end());
		for (int p =0; p<a-1; p++) {
			k += s[p] * (s.size() - 1 - p);
		}
		cout << k << endl;
	}
}

Measured memory_bytes: 3216
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	fastio;

	ll n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

const int N = 8123;

vector<int> z[2];
bool dp[2][N*2+1];

bool solve() {
	string s; cin >> s;
	int x, y; cin >> x >> y;
	int cnt = 0, dir = 0; // 0 - horiz
	bool f = false;
	int rrr = 0;
	for (char c: s) {
		if (c == 'F') ++cnt;
		else {
			if (!f) {
				f = true;
				rrr = cnt;
			} else {
				z[dir].push_back(cnt);
			}
			dir = !dir;
			cnt = 0;
		}
	}
	if (f) {
		z[dir].push_back(cnt);
	} else {
		rrr = cnt;
	}
	dp[0][rrr] = dp[1][0] = 1;
	int sum[2] = {rrr, 0};
	// https://medium.com/swlh/solving-the-target-sum-problem-with-dynamic-programming-and-more-b76bd2a661f9
	for (int dir = 0; dir < 2; ++dir) {
		for (int num: z[dir]) {
			sum[dir] += num;
			for (int i = N*2; i >= num; --i) {
				dp[dir][i] |= dp[dir][i-num];
			}
		}
	}
	if (x > sum[0] || -x < -sum[0] || (x+sum[0])%2 == 1) return false;
	if (y > sum[1] || -y < -sum[1] || (y+sum[1])%2 == 1) return false;
	return dp[0][(x+sum[0])/2] && dp[1][(y+sum[1])/2];
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		cout << (solve()?"Yes":"No");
	}
	return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	static BufferedReader br;
	static PrintWriter pw;
	static int[][] memo;
	static int[] arr;
	static ArrayList<Integer> index;
	static int n;

	static short dp(int idx, int c) {
		if (c == n)
			return 1;
		if (idx == index.size() || c > n)
			return 0;
		if (memo[idx][c] != -1)
			return (short) memo[idx][c];
		short t = 0;
		short l = dp(idx + 1, c);
		if (idx == 0) {
			t = dp(idx + 1, c + 2 * n - index.get(idx));
		} else {
			t = dp(idx + 1, c + index.get(idx - 1) - index.get(idx));
		}
		return (short) (memo[idx][c] = l | t);
	}

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
//		br = new BufferedReader(new FileReader(new File("input.txt")));
//		pw = new PrintWriter("output.txt");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);

		n = Integer.parseInt(br.readLine());
		arr = new int[n];
		StringTokenizer st = new StringTokenizer(br.readLine());
		for (int i = 0; i < arr.length; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
		}
		HashMap<Integer, Integer> hm = new HashMap<>();
		long ans = 0;
		for (int i = 0; i < arr.length; i++) {
			int t = i + 1 - arr[i];
			ans += hm.getOrDefault(t, 0);
			hm.put(i + 1 + arr[i], hm.getOrDefault(i + 1 + arr[i], 0) + 1);
		}
		pw.println(ans);

		pw.flush();

	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		public int compareTo(pair o) {
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}

		@Override
		public String toString() {
			// TODO Auto-generated method stub
			return x + " " + y;
		}

	}

}


Measured memory_bytes: 65080
#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    
    int res = a + b;
    res = max(res, a - b);
    res = max(res, a * b);
    printf("%d", res);
    return 0;
}

Measured memory_bytes: 256
MOD = pow(10, 9) + 7

fac = [0 for _ in range(2050)]
finv = [0 for _ in range(2050)]
inv = [0 for _ in range(2050)]

def COMinit():
  fac[0] = 1
  fac[1] = 1
  finv[0] = 1
  finv[1] = 1
  inv[1] = 1
  for i in range(2, 2050):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD


def COM(n, k):
  if n < k:
    return 0
  if n < 0 or k < 0:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD


def main():
  COMinit()
  n, k = map(int, input().split())
  for i in range(1, k+1):
    if n - k + 1 >= i:
      print(COM(n-k+1, i) * COM(k-1, i-1) % MOD)
    else:
      print(0)


if __name__ == '__main__':
  main()


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

#define ll long long int 

const ll N = 2e5+7 ;
ll dp[N] ;

ll min_cost(ll h[] , ll n , ll k){
	if( n <= 0 ){
		dp[0] = 0 ;
		return dp[0] ;
	}
	
	if(	dp[n] != -1) return dp[n] ;

	if( n == 1 ) {
		dp[1] = 0;
		return dp[1] ;
	}
	if( n == 2 ) {
		dp[2] = abs(h[2] - h[1]) ;
		return dp[2] ;
	}
	if(n <= k) {

		ll min1 = LONG_MAX ;
		for(int i = 1 ; i <n ; i++){
			min1 = min ( min1 , min_cost(h , n - i , k) + abs(h[n] - h[n-i]) ) ;
		} 
		dp[n] = min1 ;
		return dp[n] ;

	}
	ll min2 = LONG_MAX ;
	for(int i = 1 ; i <= k ;i++  ){
		min2 = min(min_cost(h,n-i,k) + abs(h[n] - h[n-i]) ,min2) ;
	}
	dp[n] = min2 ;
	return dp[n] ;
}


void solve(ll n , ll k) {
	ll h[n+2] ;
	for(int i = 1; i <= n ; i++ ){
		cin >> h[i] ;
	} 
	memset(dp , -1 , sizeof(dp) ) ;
	cout << min_cost(h,n,k) ;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n , k ; cin >> n >> k ; 
    solve(n,k) ;
    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

int x;

int main() {
    cin >> x;
    while (1) {
        bool flag = true;
        for (int i = 2; i * 2 <= x; i++) {
            if (x % i == 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << x << endl;
            return 0;
        }
        x++;
    }
}

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

/*int n;
  cin >> n;
  vector<int> h(n);*/

int main() {

  int n;
  cin >> n;
  int count=0;
  double ans=0.0;

  for(int i=1;i<=n;i++){
    if((i%2) == 1){
      count++;
    }
  }

  ans = (double)count/n;

  cout << setprecision(6) << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string a;
  cin>>a;
  
  int i,k=0;
  
  for(i=0;i<3;i++){
    if(a.at(i)=='R'){
      k++;
      if(i!=2&&a.at(i+1)!='R'){
        break;
      }
    }
  }
  
  cout<<k;
  
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int v;
map<int,list<int> > m;
vector<int> vec;

int main()
{
 int e;
cin>>v>>e;
for(int i=1;i<=e;i++)
{int a,b;
  cin>>a>>b;
  m[a].push_back(b);

}



int in[v+1]={0};
  in[0]=0;
  for(auto i: m)
  {
    for(auto j: m[i.first])
      in[j]++;
  }
queue<int> q;
for(int i=1;i<=v;i++)
{if(in[i]==0)
  q.push(i);

}

while(!q.empty())
{int d=q.front();
  vec.push_back(d);
  q.pop();
  for(auto i: m[d])
    {in[i]--;
if(in[i]==0)
  q.push(i);
    }

}






int dp[v+1]={0};
for(auto i: vec)
{

for(auto j: m[i])
{
  dp[j]=max(dp[j],dp[i]+1);
} 

}
int ans=0;
for(int i=1;i<=v;i++)
{ans=max(ans,dp[i]);

}
cout<<ans<<endl;


}

Measured memory_bytes: 10876
str = input()
q = int(input())
for i in range(q):
    order = input().split()
    a,b = map(int,order[1:3])
    if order[0] == 'print':
        print(str[a:b+1])
    elif order[0] == 'reverse':
        rev = str[a:b+1]
        str = str[:a]+rev[::-1]+str[b+1:]
    else:
        l = len(str)
        str = str[:a]+order[3]+str[b+1:]


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

xyh=[]
for i in range(N):
    xi,yi,hi=map(int,input().split())
    xyh.append([xi,yi,hi])
xyh.sort(reverse=True,key=lambda x:x[2])
for Cx in range(0,101):
    for Cy in range(0,101):
        for i in range(N):
            X=xyh[i][0]
            Y=xyh[i][1]
            h=xyh[i][2]
            if i==0:
                H=h+abs(X-Cx)+abs(Y-Cy)
                continue
            H_=h+abs(X-Cx)+abs(Y-Cy)
            if h==0:
                if H_<H:
                    break
            elif H!=H_:
                break
            if i==N-1:
                print(Cx,Cy,H)
                quit()


Measured memory_bytes: 40944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
int main(){
    int n;
    cin >>n;
  if (n%2==0) cout<<n/2;
  else cout << n/2 +1;
      
}

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int A[100];
int N;

int main()
{
	cin >> N;
	rep(i, N) cin >> A[i];
	sort(A, A + N);
	cout << A[N-1] - A[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define print(n) std::cout << n << std::endl
#define print_no_indention(n) std::cout << n
using namespace std;


int main() {
    long long int n,k;
    //n = 3;
    //k = 0;
    cin >> n >> k;
    vector<long long int> h(n);
    for (long long int i = 0; i < n; ++i) {
        cin >> h.at(i);
    }
    sort(h.begin(),h.end(),greater<long long int>());
    /*for (long long int i = 0; i < n; ++i) {
        print(h.at(i));
    }*/

    long long int count = 0;
    if(k > n) {
    }else{
        for (long long int i = k; i < n; ++i) {
            count += h.at(i);
        }
    }
    print(count);
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int Q;
    cin >> Q;
    priority_queue<ll> lower;
    priority_queue<ll, vector<ll>, greater<ll>> upper;
    ll B = 0;
    ll L = 0, U = 0;
    int cnt = 0;
    rep(i, Q) {
        int q;
        cin >> q;
        if(q == 1) {
            ll a, b;
            cin >> a >> b;
            if(i == 0) {
                lower.push(a);
                L += a;
            } else {
                ll med = lower.top();
                if(a > med) {
                    upper.push(a);
                    U += a;
                } else {
                    lower.push(a);
                    L += a;
                }
                int lsize = lower.size();
                int usize = upper.size();
                if(lsize - usize >= 2) {
                    ll tmp = lower.top();
                    lower.pop();
                    upper.push(tmp);
                    L -= tmp;
                    U += tmp;
                } else if(usize > lsize) {
                    ll tmp = upper.top();
                    upper.pop();
                    lower.push(tmp);
                    U -= tmp;
                    L += tmp;
                }
            }
            B += b;
            cnt++;
        } else {
            ll m = lower.top();
            ll tm = m;
            if(cnt % 2 == 0)
                tm = 0;
            cout << m << " " << -L + U + B + tm << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5024
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
const int N=1e5+5;
const int inf=1e9+7;
int dp[N],h[N];
int main(){
	int n,i,j,k;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>h[i];
	}
	for(i=2;i<=n;i++){
		dp[i]=inf;
		for(j=max(i-k,1);j<i;j++){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n];
}


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

string a;

int main () {
    cin >> a;
    if (a == "SUN") cout << 7;
	else if (a == "MON") cout << 6;
	else if (a == "TUE") cout << 5;
	else if (a == "WED") cout << 4;
	else if (a == "THU") cout << 3;
	else if (a == "FRI") cout << 2;
	else if (a == "SAT") cout << 1;
	return 0; 
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 100
#define mod 1000000007
#define MK 32768
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,a[MN+5],L[MN+5],num,f[MN+5][MN+5],pw[MK+5],PW[MK+5],ans;
inline void R(int&x,int y){(x+=y)>=mod?x-=mod:0;}
inline int pw2(int x){return 1LL*PW[x>>15]*pw[x&32767]%mod;}
inline int Sum(int l,int r){return (pw2(r+1)-pw2(l)+mod)%mod;}
int main()
{   
    n=read();pw[0]=PW[0]=1;
    for(int i=1;i<=MK;++i) pw[i]=2*pw[i-1]%mod;
    for(int i=1;i<=MK;++i) PW[i]=1LL*PW[i-1]*pw[MK]%mod;
    for(int i=1;i<=n;++i) a[i]=L[i]=read();
    sort(L+1,L+n+1);num=unique(L+1,L+n+1)-L-1;L[++num]=2e9;
    f[0][num]=1;
    for(int i=1;i<=n;++i)
    {
        a[i]=lower_bound(L+1,L+num+1,a[i])-L;
        for(int j=1;j<=a[i];++j) R(f[i][j],1LL*f[i-1][j]*pw2(max(0,L[a[i]]-L[a[i-1]]))%mod);
        int res=0;
        for(int j=a[i]+1;j<=num;++j) R(res,f[i-1][j]);
        res=2*res%mod;
        for(int j=a[i-1]+1;j<=a[i];++j) 
        {
            int l=max(2,L[j-1]+1),r=L[j];if(l>r) continue;
            R(f[i][j],1LL*res*Sum(L[a[i]]-r,L[a[i]]-l)%mod);  
        }
        R(f[i][num],res);
    }
    for(int j=1;j<=num;++j) R(ans,f[n][j]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 512
N,M=map(int, input().split())

def warshall_floyd(d):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

d=[[float("inf")]*N for i in range(N)]
A=[]
for i in range(M):
  x,y,z=map(int, input().split())
  x-=1
  y-=1
  d[x][y]=z
  d[y][x]=z
  A.append((x,y,z))
  
for i in range(N):
  d[i][i]=0 
  
D=warshall_floyd(d)

ans=0
for x,y,z in A:
  if D[x][y]!=z:
    ans+=1
print(ans)

Measured memory_bytes: 80764
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
 
int main() {
    int n;
    scanf("%d ",&n);
    int a[n],b[n];
    int i;
    for(i=0;i<=n-1;i++)scanf("%d %d",&a[i],&b[i]);
    long long int ans=0;
    for(i=n-1;i>=0;i--){
        if((a[i]+ans)%b[i]!=0)ans+=b[i]-(a[i]+ans)%b[i];
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 896
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

#include <iomanip>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;

    rep(ni,N){
        cin>>ltmp;
        A.push_back(ltmp);
    }    
    sort(A.begin(),A.end());

    double val;
    val = A[0];
    for( ll ai = 1 ; ai <N ; ai++ ){
        dtmp = A[ai];
        val = (val + dtmp)/2;
    }
    cout << fixed << setprecision(15) << val << endl;

}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll H, W, K;
char C[100][100];
ll i, j, k;

int main(){
    scanf("%lld%lld%lld", &H, &W, &K);
    rep(i,0,H){
        scanf("%s", C[i]);
    }
    ll ans = 0;
    rep(i,0,1<<H){
        rep(j,0,1<<W){
            ll i2, j2, ct = 0;
            rep(i2,0,H){
                if(i>>i2&1)
                    continue;
                rep(j2,0,W){
                    if(j>>j2&1)
                        continue;
                    if(C[i2][j2]=='#')
                        ++ct;
                }
            }
            if(ct==K)
                ++ans;
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 3832
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
//int dx[] = { 1, 0 };
//int dy[] = { 0, 1 };
#define mod7 1e9+7;
#define mod9 1e9+9;

int nextInt(){
	int a;	cin >> a;return a;
}
string next(){
	string s;cin >> s;return s;
}
char nextChar(){
	char c;cin >> c;return c;
}

unsigned long long strtoint(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve(){
	int n = nextInt();
	int m = nextInt();
	vector<string> v;
	rep(i,n){
		string s;
		cin >> s;
		v.pb(s);
		v.pb(s);
	}
	vP(v);
}

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


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

int main(){
	int N,K,X,Y,sum=0;
	cin>>N>>K>>X>>Y;
	for(int i=1;i<=N;i++){
		if(i<=K) sum+=X;
		else sum+=Y;
	}
	cout<<sum<<endl;
	return 0;
}


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


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

	int cnt = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (i + j + (s - i - j) == s)
				if ((s - i - j) >= 0 && (s - i - j) <= k)
					cnt++;
			//printf("%d+%d+%d\n", i, j, s - i - j);
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
s=input()
l=len(s)
def judge():
  cnt=0
  while True:
    if s[l-cnt-6:l-cnt]=='eraser':
      cnt+=6
    elif s[l-cnt-5:l-cnt]=='erase':
      cnt+=5
    elif s[l-cnt-7:l-cnt]=='dreamer':
      cnt+=7
    elif s[l-cnt-5:l-cnt]=='dream':
      cnt+=5
    else:
      print('NO')
      exit()
    if cnt==len(s):
      print('YES')
      exit()

judge()

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

const int max = 1e5 + 10;

int n,k,s;

int main()
{
	cin >> n >> k >> s;
	for(int i = 0; i < k; i++) cout << s << " ";
	for(int i = 0; i < n - k; i++) {
		int t = 1;
		if(s != 1e9) t = s + 1;
		cout << t << " ";
	}	
	return 0;
}

Measured memory_bytes: 1280
N = int(input())
numbers = []
for i in range(0, N):
	numbers.append(int(input()))
numbers.sort()
ans = 0
tmp = 0
cnt = 0
for i in range(0, N):
	if numbers[i] != tmp:
		ans += cnt%2
		cnt = 0
		tmp = numbers[i]
	cnt += 1
ans += cnt%2
print(ans)

Measured memory_bytes: 50780
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

int c(int n, const vector<int> &G, const vector<int> &cost, vector<int> &ans) {
    if (ans[n] != -1) return ans[n];
    if (n == 0) {
        return ans[0] = cost[0];
    }
    else {
        return ans[n] = cost[n] + c(G[n], G, cost, ans);
    }
}

int main() {
    int n, q; cin >> n >> q;
    vector<int> G(n);
    vector<int> cost(n,0);
    vector<int> ans(n, -1);
    REP(i, n - 1) {
        int a, b;
        cin >> a >> b;
        G[b-1] = a - 1;
    }
    REP(i, q) {
        int p, x;
        cin >> p >> x;
        cost[p-1] += x;
    }
    REP(i, n) {
        cout << c(i,G,cost,ans) << " ";
    }
    cout << endl;
    getchar(); getchar();
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const int N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    998244353;
vector<pair<int,int> > g[N];
bool bo[N];
int dist[N],n,m;
bool ans;
void dfs(int idx,int tot)
{
	if(bo[idx])
	{
		if(dist[idx]!=tot)
		ans=true;
		return ;
	}
	bo[idx]=true;
	dist[idx]=tot;
	for(auto &i: g[idx] ) dfs(i.fi,tot+i.se);
}
int main()
{
	ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
  	int x,y,z;
  	cin>>x>>y>>z;
  	g[x].emplace_back(y,z);
  	g[y].emplace_back(x,-z);
  }
  for(int i=1;i<=n;i++)
  {
  	if(!bo[i])
  	{

		dfs(i,0);
	  }
  }
  if(ans)
  cout<<"No";
  else
  cout<<"Yes";
}


Measured memory_bytes: 13568
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

class UnionFind(n: Int) {
    private val rank = IntArray(n) { 0 }
    private val parent = IntArray(n) { -1 }

    fun find(x: Int): Int {
        if (parent[x] < 0) {
            return x
        }
        parent[x] = find(parent[x])
        return parent[x]
    }

    fun unite(x: Int, y: Int) {
        val x1 = find(x)
        val y1 = find(y)
        if (x1 == y1) {
            return
        }
        if (rank[x1] < rank[y1]) {
            parent[y1] += parent[x1]
            parent[x1] = y1
        } else {
            parent[x1] += parent[y1]
            parent[y1] = x1
            if (rank[x1] == rank[y1]) {
                rank[x1]++
            }
        }
    }

    fun same(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }

    fun size(x: Int): Int {
        return -parent[find(x)]
    }
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val a = Array(m) { 0 }
    val b = Array(m) { 0 }
    for (i in 0 until m) {
        val u = sc.nextInt() - 1
        val v = sc.nextInt() - 1
        a[i] = u
        b[i] = v
    }
    var count = 0
    for (i in 0 until m) {
        val uf = UnionFind(n)
        for (j in 0 until m) {
            if (i != j) {
                uf.unite(a[j], b[j])
            }
        }
        val p = (0 until n).map { uf.find(it) }
        if (p.distinct().count() != 1) count++
    }
    println(count)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 31140
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

struct Node{
  int p;
  int l;
  int r;
  int o;
};

struct Node T[MAX];

int main(void){
  int n,i,j,id,k[MAX],c,d,l;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    T[i].p = -1;
    T[i].l = -1;
    T[i].r = -1;
  }
    
  for(i = 0 ; i < n ; i++){
    scanf("%d",&id);
    scanf("%d",&k[i]);
    T[id].o = k[i];
    
    if(T[id].o != 0){
      for(j = 0 ; j < T[id].o ; j++){
	scanf("%d",&c);
	
	if(j == 0){
	  T[id].l = c;
	  l = c;
	  T[c].p = id;
	}
	else {
	  T[l].r = c;
	  l = c;
	  T[c].p = id;
	}   
      }
    }
  }
 
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, ",i,T[i].p);

    id = i; 
    T[i].o = T[id].o;

    for(d = 0 ; T[id].p != -1 ; d++){
      id = T[id].p;
    }

    printf("depth = %d, ",d);
    
    if(T[i].p == -1){
      printf("root, ");
    }
    else if((T[i].p != -1) && (T[i].l != -1)){
      printf("internal node, ");
    }
    else if(T[i].l == -1){
      printf("leaf, ");
    }

    
    if(T[i].o != 0){

      if(T[i].o == 1){
	printf("[%d]\n",T[i].l);
      }
      else {
	printf("[%d, ",T[i].l);
	for(l = T[i].l ; T[l].r != -1 ;){
	  printf("%d",T[l].r);
	  l = T[l].r;
	  if(T[l].r != -1) printf(", ");
	}
	printf("]\n");
      }
    }
    else {
      printf("[]\n");
    }

  }
  return 0;
}

Measured memory_bytes: 0
def main():
    S = input()
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s not in ["R", "U", "D"]:
                print("No")
                exit()
        else:
            if s not in ["L", "U", "D"]:
                print("No")
                exit()

    print("Yes")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const double Pi=3.14159265;
const int N=4e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
using namespace std;
int main(){
    int n,k;cin>>n>>k;
    k-=1;
    cout<<n-k;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


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

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


int main()
{
  //weather_predicition();
  //odds_of_oddness();
  curtain();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
  int t,n,i,j,k=1e9+7,l=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++) cin>>a[i];
  int dp[n];
  dp[0]=a[0];
  for(i=1;i<n;i++) dp[i]=(dp[i-1]+a[i]);
  for(i=0;i<n-1;i++)
  {
    l=(l+(a[i]*((dp[n-1]-dp[i])%k+k)%k)%k)%k;
  }
  cout<<l;
}

Measured memory_bytes: 6744
circle_meter, N = [int(i) for i in input().split()]
house = [int(i) for i in input().split()]

max_distance = 0

for i in range(N):
	if i == N-1:
		if max_distance < (house[0] + circle_meter - house[i]):
			max_distance = house[0] + circle_meter - house[i]
		else:
			break
	elif max_distance < (house[i+1] -house[i]):
		max_distance = (house[i+1]-house[i])
	
result = circle_meter - max_distance
print(result)

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

void dfs(vector<vector<pair<int, int>>>& g, int start,
         vector<int>& cost) {
    for (auto & elm : g[start]) {
        if(cost[elm.first] != -1) continue;
        cost[elm.first] = (cost[start] + elm.second) % 2;
        dfs(g, elm.first, cost);
    }
}

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

    vector<vector<pair<int, int>>> g(n);
    for (auto i = 0; i < n - 1; i++) {
        int u, v, w; cin >> u >> v >> w; u--; v--;
        g[u].emplace_back(v, w); g[v].emplace_back(u, w);
    }

    vector<int> cost(n, -1);
    cost[0] = 0;
    dfs(g, 0, cost);

    for (auto i = 0; i < n; i++) cout << cost[i] << endl;
    return 0;
}

Measured memory_bytes: 11096
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-10;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

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

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

vector<ll> divis(ll n) {
	vector<ll> ret;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i != n / i) ret.push_back(n / i);
		}
	}
	return ret;
}

int main() {
	IOS();
	ll a, b, k;
	cin >> a >> b >> k;
	ll g		 = gcd(a, b);
	vector<ll> t = divis(g);
	sort(t.begin(), t.end(), greater<ll>());
	dump(t[k - 1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int dp[4001],n,a,b,c,i;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,k,i;
    cin >> n >> k;
    ll h[n],mv=0;
    for(i=0;i<n;i++) cin >> h[i];
    sort(h,h+n);
    if(k>=n) cout << 0;
    else {
        for(i=0;i<n-k;i++) {
            mv+=h[i];
        }
        cout << mv;
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
  
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
  
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
 
typedef long long int64;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
const int INF = 1 << 30;
 
int main()
{
  int R, W[2], H[2], X, Y, L[500][500];
  int min_cost[500][500], limit[2][500 * 500 + 1];
 
  static const signed dy[] = { 0, 1, 0, -1}, dx[] = { 1, 0, -1, 0};
 
  while(scanf("%d", &R), R){
    map< int, int > level[2];
    for(int i = 0; i < 2; i++){
      scanf("%d %d %d %d", &W[i], &H[i], &X, &Y);
      --X, --Y;
      for(int j = 0; j < H[i]; j++){
        for(int k = 0; k < W[i]; k++){
          scanf("%d", &L[j][k]);
        }
      }
      priority_queue< Pii, vector< Pii >, greater< Pii > > que;
      fill_n( *min_cost, 500 * 500, INF);
      que.push( Pii( L[Y][X], make_pair( X, Y)));
      min_cost[X][Y] = L[Y][X];
      level[i][min_cost[X][Y]]++;
      while(!que.empty()){
        Pii p = que.top(); que.pop();
        if(p.first > min_cost[p.second.first][p.second.second]) continue;
        for(int j = 0; j < 4; j++){
          int nx = p.second.first + dx[j], ny = p.second.second + dy[j];
          if(nx < 0 || nx >= W[i] || ny < 0 || ny >= H[i]) continue;
          if(max( L[ny][nx], p.first) >= min_cost[nx][ny]) continue;
          min_cost[nx][ny] = max( L[ny][nx], p.first);
          que.push( Pii( max( L[ny][nx], p.first), make_pair( nx, ny)));
          level[i][min_cost[nx][ny]]++;
        }
      }
 
      int sz = 0;
      fill_n( limit[i], H[i] * W[i], 0);
      ForEach(it, level[i]){
        sz += it -> second;
        limit[i][sz] = it -> first;
      }
      for(int j = H[i] * W[i] - 1; j > 0; j--){
        if(limit[i][j] == 0) limit[i][j] = limit[i][j + 1];
      }
    }
 
    int ret = INF, end = min( H[0] * W[0], R);
    for(int i = 0; i <= end; i++){
      int nokori = R - i;
      if(nokori < 0 || nokori > W[1] * H[1]) continue;
      ret = min( ret, limit[0][i] + limit[1][nokori]);
    }
    printf("%d\n", ret);
  }
}

Measured memory_bytes: 15612
#include <stdio.h>

int main(void){

    int K = 0;
    int A = 0;
    int B = 0;
    int flag = 0;
    scanf("%d", &K);
    scanf("%d %d", &A, &B);

    for (int i = A; i <= B; i++){
        if (i % K == 0){
            flag = 1;
        }
    }

    if (flag == 1){
        printf("OK\n");
    } else {
        printf("NG\n");        
    }


    return 0;
}

Measured memory_bytes: 1612
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;

ll INF = 114514191919119;

int main(){

    ll N; cin >> N;

    vector<ll > vec;

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vec.push_back(t);
    }

    //sort(vec.begin(), vec.end());

    /*
    if(vec[0] < 0){
        ll tmp = abs(vec[0]);
        for(ll i = 0; i < N; i++){
            vec[i] += tmp;
        }      
    }
    */

    vector<ll > ruiseki(N, 0);

    for(ll i = 0; i < N; i++){
        if(i == 0) ruiseki[0] = vec[0];
        else ruiseki[i] = ruiseki[i-1] + vec[i];
    }

    ll ans = INF;

    for(ll i = 0; i < N - 1; i++){
        ans = min(ans, abs(ruiseki[i] - (ruiseki[N-1] - ruiseki[i])));
        //cout << ruiseki[i] << " " << ruiseki[N-1] - ruiseki[i] << endl;
    }    
    
    cout << ans << endl;

}

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for (auto i = mp.begin(); i != mp.end(); i++){
        if ((i -> second) % 2) ans++;
    }

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

Measured memory_bytes: 4992
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<bitset>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int dx[]={0,0,-1,1};
const int dy[]={-1,1,0,0};
const int maxn = 205;
char maze[maxn][maxn];
bool vis[maxn][maxn];
int n,m,dp,ds,cur;

const pair<int,int> step = make_pair(-1,-1);
queue<pair<int,int> > que;
void bfs(int x,int y)
{
    while(!que.empty()) que.pop();
    cur = 0,dp = INF,ds = INF;
    memset(vis,false,sizeof vis);

    vis[y][x] = true;
    que.push(make_pair(x,y));
    que.push(step);

    while(cur <= n+m && (dp==INF||ds==INF)){
        pair<int,int> u = que.front();
        que.pop();

        if(maze[u.second][u.first] == '@') dp = min(dp,cur);
        if(maze[u.second][u.first] == '$') ds = min(ds,cur);

        if(u == step){
            ++cur;
            que.push(step);
            continue;
        }
        for(int i=0;i<4;++i){
            int nx = u.first+dx[i],ny = u.second+dy[i];
            if(!vis[ny][nx] && 0<=nx && 0<=ny && nx<m && ny<n && maze[ny][nx] != '#'){
                vis[ny][nx] = true;
                que.push(make_pair(nx,ny));
            }
        }
    }
}

int main()
{
    while(~scanf("%d%d",&n,&m)){
        for(int i=0;i<n;++i){
            scanf("%s",maze[i]);
        }
        for(int i=0;i<n;++i){
            for(int j=0;j<m;++j){
                if(maze[i][j] == '%'){
                    bfs(j,i);
                }
            }
        }
        if(dp < ds) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 3288
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int n, w;
long long greutate[1000005] = {0}, cost[1000005] = {0};
long long matrice[105][1000005]= {0};

void read()
{
 cin >> n >> w;
 for(int i = 1; i <= n; i++)
 {
  int x, y;
  cin >> x >> y;
  greutate[i] = x;
  cost[i] = y;
 }
}
void solve()
{
    for(int i = 1; i <=  n; i++)
        for(int j = 1; j <= w; j++)
        {
            matrice[i][j] = matrice[i - 1][j];
            if(j >= greutate[i])
            {
                if(matrice[i - 1][j] > matrice[i - 1][j - greutate[i]] + cost[i])
                    matrice[i][j] = matrice[i - 1][j];
                else matrice[i][j] = matrice[i - 1][j - greutate[i]] + cost[i];
            }
        }
}
int main()
{
    read();
    solve();
    cout << matrice[n][w];

}

Measured memory_bytes: 293120
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
        {
            cin>>a[i];
            b[i]=a[i];
        }
    sort(a,a+n);
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
            cnt++;
    }
    if(cnt==2||cnt==0)
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
 
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a + b < 10) cout << a + b << endl;
  else cout << "error" << endl;
}


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

using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += v[i];
    }
    cout << sum << endl;
    
}


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

int main(){
int n,s1=0;
cin>>n;
string s;
cin>>s;
int sr=0;
for(int i=0;i<n;i++){
	if(s[i]=='R')sr++;
} 
for(int i=sr;i<n;i++){
	if(s[i]=='R')s1++;
}
cout<<s1;
return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ll h,a;
    cin>>h>>a;
    ll sum = 0;
    ll b[a];
    cn(b,a);
    for(int  i=0;i<a;i++)
        sum+=b[i];
    //cout<<sum<<endl;
    if(sum>=h)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

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

int main(){
	int n, i, min=1000, max=0;
	cin>>n;
	int a;
	for(i=0; i<n; i++){
		cin>>a;
		if(a<min) min=a;
		if(a>max) max=a;
	}
	cout<<max-min<<endl;
	return 0;
}

Measured memory_bytes: 256
n = list(map(int, list(input())))
ln = len(n)
ans = 0
for i in range(-1, -ln, -1):
    if n[i] == 10:
        n[i-1] += 1
        continue
    elif n[i] < 5:
        ans += n[i]
    elif n[i] > 5:
        ans += 10 - n[i]
        n[i-1] += 1
    else:
        if n[i-1] < 5:
            ans += 5
        else:
            ans += 5
            n[i-1] += 1
if n[0] == 10:
    ans += 1
elif n[0] <= 5:
    ans += n[0]
else:
    ans += 11 - n[0]

print(ans)

Measured memory_bytes: 21092