akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
int main() {
  int t, n;
  while (scanf("%d",&t)) {
	if (t==0) break;
	scanf("%d",&n);
	int sum = 0;
	for (int i=0; i<n; i++) {
	  int s, f; scanf("%d%d",&s,&f);
	  sum += f - s;
	}
	if (sum >= t) puts("OK");
	else printf("%d\n",t-sum);
  }
}

Measured memory_bytes: 1040
#include <stdio.h>

int
get_right_surface(int *surfaces, int top, int front)
{
	if (top == surfaces[0] && front == surfaces[1]) return surfaces[2];
	if (top == surfaces[0] && front == surfaces[2]) return surfaces[4];
	if (top == surfaces[0] && front == surfaces[4]) return surfaces[3];
	if (top == surfaces[0] && front == surfaces[3]) return surfaces[1];
	if (top == surfaces[1] && front == surfaces[5]) return surfaces[2];
	if (top == surfaces[1] && front == surfaces[2]) return surfaces[0];
	if (top == surfaces[1] && front == surfaces[0]) return surfaces[3];
	if (top == surfaces[1] && front == surfaces[3]) return surfaces[5];
	if (top == surfaces[2] && front == surfaces[1]) return surfaces[5];
	if (top == surfaces[2] && front == surfaces[5]) return surfaces[4];
	if (top == surfaces[2] && front == surfaces[4]) return surfaces[0];
	if (top == surfaces[2] && front == surfaces[0]) return surfaces[1];
	if (top == surfaces[3] && front == surfaces[1]) return surfaces[0];
	if (top == surfaces[3] && front == surfaces[0]) return surfaces[4];
	if (top == surfaces[3] && front == surfaces[4]) return surfaces[5];
	if (top == surfaces[3] && front == surfaces[5]) return surfaces[1];
	if (top == surfaces[4] && front == surfaces[2]) return surfaces[5];
	if (top == surfaces[4] && front == surfaces[5]) return surfaces[3];
	if (top == surfaces[4] && front == surfaces[3]) return surfaces[0];
	if (top == surfaces[4] && front == surfaces[0]) return surfaces[2];
	if (top == surfaces[5] && front == surfaces[1]) return surfaces[3];
	if (top == surfaces[5] && front == surfaces[3]) return surfaces[4];
	if (top == surfaces[5] && front == surfaces[4]) return surfaces[2];
	if (top == surfaces[5] && front == surfaces[2]) return surfaces[1];
	return 0;
}

int main()
{
	int i;
	int top, front;
	int n;
	int surfaces[6];

	for (i = 0; i < 6; i++)
	{
		scanf("%d", &surfaces[i]);
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &top, &front);
		printf("%d\n", get_right_surface(surfaces, top, front));
	}

	return 0;
}



Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

const ULL M = 998244353;

ULL dp[302][302][302][2] = {};
UL K;
UL N = 0;
vector<UL> P;

ULL Solve() {
	UL I = P.size() - 2;
	UL mK = min(K, I);
	dp[0][0][0][0] = 1;
	for (UL i = 0; i <= I; i++) {
		for (UL k = 0; k <= mK; k++) {
			for (UL n = N; n != (UL)-1; n--) {
				if (i) if (n > 1) dp[i][k][n - 1][1] += dp[i][k][n][1];
			}
		}
		UL d = P[i + 1] - P[i];
		if (d) {
			for (UL k = 0; k <= mK; k++) {
				for (UL n = N; n != d - 1; n--)
					dp[i][k][n][0] = dp[i][k][n - d][0] + dp[i][k][n - d + 1][1];
				dp[i][k][d - 1][0] = dp[i][k][0][1];
				for (UL n = d - 2; n != (UL)-1; n--)
					dp[i][k][n][0] = 0;

				for (UL n = N; n != (UL)-1; n--) dp[i][k][n][1] = 0;
			}
		}
		for (UL k = 0; k <= mK; k++) {
			for (UL n = N; n != (UL)-1; n--) {
				dp[i][k][n][0] %= M;
				dp[i][k][n][1] %= M;
				if (k != mK) if(i != I) if(n != 0) dp[i + 1][k + 1][n][1] += dp[i][k][n][0] + dp[i][k][n][1];
				if (i != I) dp[i + 1][k][n][0] += dp[i][k][n][0];
			}
		}
	}
	ULL ans = 0;
	for (UL k = 0; k <= mK; k++) {
		for (UL n = 0; n <= N; n++) {
			ans += dp[I][k][n][0] + dp[I][k][n][1];
		}
	}
	ans %= M;
	return ans;
}

int main() {
	string S; cin >> S;
	cin >> K;
	P.push_back(0);
	for (char c : S) {
		if (c == '1') P.push_back(N);
		else N++;
	}
	P.push_back(N);
	N++;
	cout << Solve() << endl;
	return 0;
}


Measured memory_bytes: 361388
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

bool from1[200010];
bool toN[200010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(a == 0) from1[b] = true;
        if(b == N - 1) toN[a] = true;
    }
    rep(i, N) {
        if(from1[i] && toN[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

int len=0;
set<int> st;

void rec(string s) {
	bool th =false,fi=false,se= false;
	rep(i, s.size()) {
		if (s[i] == '3')th = true;
		if (s[i] == '5')fi = true;
		if (s[i] == '7')se = true;
	}
	if (th&&fi&&se) {
		st.insert(stoi(s));
	}
	if ((double)s.size() < len) {
		rec(s + "3");
		rec(s + "5");
		rec(s + "7");
	}

}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	len = ceil(log(n) / log(10));
	rec("");
	ll ans = 0;
	for (int x: st) {
		if (x <= n)ans++;
	}
	cout << ans << endl;
}

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

int par[100005],rnk[100005];

void init(int n){
	for(int i=1;i<=n;i++){
		par[i]=i;
		rnk[i]=0;
	}
}

int find(int x){
	if(par[x]==x) {
		return x;
	} else {
		par[x]=find(par[x]);
		return par[x];
	}
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rnk[x]<rnk[y]){
		par[x]=y;
	} else {
		par[y]=x;
		if(rnk[x]==rnk[y]) rnk[y]++;
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

int main() {
	// your code goes here
	int n,m,i,x[100005],y[100005],z[100005],ans=0;
	cin >> n >> m;
	init(n);
	for(i=0;i<m;i++) {
		cin >> x[i] >> y[i] >> z[i];
		unite(x[i],y[i]);
	}
	for(i=1;i<=n;i++) {
		if(rnk[i]==0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
/*
 Author : Alokit Kumar
  */
 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 
 int32_t main()
 {
   int t,n,i,j,k,l=0,d,q,m,r,x,y,x1,y1;
   cin>>n>>m>>d;
   map<int,pair<int,int> > m1;
   for(i=1;i<=n;i++)
   {
     for(j=1;j<=m;j++)
     {
       cin>>l;
       m1[l]={i,j};
     }
   }
   int a[n*m+1];
   memset(a,0,sizeof(a));
   for(i=1;i<=n*m;i++)
   {
     if(a[i]==0){
     for(j=i+d;j<=n*m;j+=d)
      {
        x=m1[j-d].first,y=m1[j-d].second;
        x1=m1[j].first,y1=m1[j].second;
        a[j]=a[j-d]+abs(x-x1)+abs(y-y1);
      }
     }
   }
   cin>>q;
   while(q--){
     cin>>l>>r;int s=0;
     s=a[r]-a[l];
     cout<<s<<"\n";
   }
 }

Measured memory_bytes: 9952
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;

int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if(H%h == 0 and W%w == 0){
    puts("No");
    return 0;
  }
  vector<vector<long long>> A(H,vector<long long>(W,1));
  long long INF = 1e9;

  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if((i+1)%h == 0 and (j+1)%w == 0){
        A[i][j] = -INF;
      }
    }
  }
  
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(i%h == 0 and j%w == 0){
        A[H-i-1][W-j-1] = INF-h*w+1;
      }
    }
  }
  
  long long s = 0;
  for(int i = 0; i < H; ++i)
    for(int j = 0; j < W; ++j)
      s += A[i][j];
  
  cerr << s << endl;
  assert(s > 0);
  if(s <= 0){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cout << A[i][j] << ((j+1 < W) ? " " : "\n");
    }
  }
}


Measured memory_bytes: 4864
N = int(input())
A = list(input())
B = list(input())
C = list(input())

res = 0

for a, b, c in zip(A, B, C):
    if a == b and b == c:
        res += 0
    elif a == b or b == c or c == a:
        res += 1
    else:
        res += 2

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll q,h,s,d,n;cin >> q >> h >> s >> d >> n;
	q*=4;
	h*=2;
	ll ans=0;
	if(n%2==0) ans=min(q*n,min(h*n,min(s*n,d*(n/2))));
	else{
		ans+=min(q*(n-1),min(h*(n-1),min(s*(n-1),d*(n/2))));
		ans+=min(q,min(h,s));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#create date: 2020-07-11 21:03

import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    l = [0] * (10 **4 + 1)
    for x, y, z in product(range(1, 101), repeat=3):
        m =  x**2 + y**2 + z**2 + x*y + y*z + z*x
        if m <= 10**4:
            l[m] += 1
    for i in range(n):
        print(l[i+1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 68672
n, a, b = map(int, input().split())
diff = abs(a - b)
if diff % 2 == 0:
    print(diff // 2)
else:
    lose = n - max(a, b)
    win = min(a, b) - 1
    print(min(win, lose) + (abs(a - b) - 1) // 2 + 1)

Measured memory_bytes: 3064
#include <cstdio>
#include<bitset>
#include<algorithm>
#include<iostream>
#include<string>
#define ll long long 
using namespace std;
long long n,k;
ll a[5010];
bitset<5010> bs;
bool check(int x)
{
	bs.reset();
	bs[0]=1;
	for(int i=1;i<=n;i++)
	if(i!=x) bs|=(bs<<a[i]);
	for(int i=k-a[x];i<k;i++)
	if(bs[i]==1) return false;
	return true;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	int l=0,r=0,mid;
	for(int i=n;i>=1;i--)
	{
		if(a[i]<k) 
		{
			r=i;
			break;
		}
	}
	while(l<r)
	{
		mid=((l+r)>>1)+1;
		if(check(mid)) 
			l=mid;
		else r=mid-1;
	}
	cout<<l;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	if(n==3){
		cout<<"Yes"<<endl;
		cout<<1<<" "<<2<<endl;
		cout<<3<<" "<<2<<endl;
		cout<<3<<" "<<4<<endl;
		cout<<5<<" "<<4<<endl;
		cout<<5<<" "<<6<<endl;
		return 0;
	}
	FOR(i,0,20){
		if(n==(1<<i)){
			cout<<"No"<<endl;
			return 0;
		}
		if((n>>i)==0){
			cout<<"Yes"<<endl;
			int d=1<<(i-1);
			FOR(i,1,d-1){
				cout<<i<<" "<<i+1<<endl;
			}
			cout<<d-1<<" "<<n+1<<endl;
			FOR(i,1,d-1){
				cout<<i+n<<" "<<i+n+1<<endl;
			}
			if(n<=d+1){
				cout<<d<<" "<<d+1<<endl;
				cout<<1<<" "<<d+1<<endl;
				cout<<d+n<<" "<<d+1+n<<endl;
				cout<<d+n<<" "<<1<<endl;
				return 0;
			}
			if(n==d+2&&d>=4){
				cout<<d<<" "<<d+1<<endl;
				cout<<1<<" "<<d+1<<endl;
				cout<<d+n<<" "<<d+1+n<<endl;
				cout<<d+n<<" "<<1<<endl;
				cout<<d+2<<" "<<d+1<<endl;
				cout<<2<<" "<<d+2+n<<endl;
				return 0;
			}
			FOR(i,d+2,n+1){
				if(i==n){
					cout<<d<<" "<<d+1<<endl;
					cout<<i-d-2<<" "<<d+1<<endl;
					cout<<d+n<<" "<<d+1+n<<endl;
					cout<<d+n<<" "<<i-d-1<<endl;
					cout<<i-d<<" "<<i<<endl;
					cout<<d+1<<" "<<i+n<<endl;
				}else{
					cout<<i+1<<" "<<1<<endl;
					cout<<i+1<<" "<<i<<endl;
					cout<<i+n<<" "<<1<<endl;
					cout<<i+n+1<<" "<<i+n<<endl;
				}
				if(i+1==n){//偶数終わり
					cout<<d<<" "<<d+1<<endl;
					cout<<1<<" "<<d+1<<endl;
					cout<<d+n<<" "<<d+1+n<<endl;
					cout<<d+n<<" "<<1<<endl;
				}
				i+=1;
			}


			return 0;
		}
	}



	return 0;
}


Measured memory_bytes: 2560
x, k, d = list(map(int, input().split()))

s = 0

if x - k * d > 0:
    s = x - k * d
elif x + k * d < 0:
    s = abs(x + k * d)
else:
    e = x // d
    r = x % d
    if (k-e) % 2 == 1:
        s = abs(r-d)
    else:
        s = r

print(s)

Measured memory_bytes: 61688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
		static int n;
		static int[] A;
		static int q;
		static int m;
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str;
		
		n = Integer.parseInt(br.readLine());
		A = new int[n];
		
		str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		q = Integer.parseInt(br.readLine());
		
		str = br.readLine().split(" ");
		for(int i = 0; i < q; i++){
			m = Integer.parseInt(str[i]);
			
			System.out.println(dfs(0, 0)?"yes" : "no");
		}
		
	}
	
	public static boolean dfs(int i, int sum){
		if(sum == m) return true;
		
		if(i == n) return false;
		
		if(dfs(i + 1, sum)) return true;
		
		if(dfs(i + 1, sum + A[i])) return true;
		
		return false;
	}
}


Measured memory_bytes: 24736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    string s, a;
        cin >> s;
    a = s.substr(0, s.size()/2);
    int cnt=0;
        for(int i=0; i<a.size(); i++){
            if(a[i]==s[s.size()-(i+1)]) continue;
            cnt += 1;
        }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
    int l,i;
    char a[21],b[21];

    scanf("%s",a);
    l=strlen(a);
    for(i=0; i<=l+1;i++){
        if(i==l)
        b[i]=a[i];
        else
        b[l-i-1]=a[i];
    }
    printf("%s\n",b);

    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000];
int main()
{
	int n,x,ans=0;
	cin>>n>>x;
	for(int i=0;i<n;i++)
	   {
	   	cin>>a[i];
	   	if(x-a[i]>=0)
	   	{
	   		x-= a[i];
	   		ans++;
	   	}
	   }
	sort(a,a+n);
	while(1)
	{
		if(x-a[0]>=0)
		{
			x-=a[0];
			ans++;
		}
		else
		break;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
alice = 0
bob = 0
check = 1
for i in range(n):
	if check == 1:
		alice += a[i]
		check = check*(-1)
	else:
		bob += a[i]
		check = check*(-1)
print(alice-bob)

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

void Main()
{
    int64_t H, W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    for(int i = 0; i < H; ++i)
    {
        string temp;
        cin >> temp;
        for(int j = 0; j < W; ++j)
        {
            s[i][j] = temp[j];
        }
    }

    vector<vector<int64_t>> result(H, vector<int64_t>(W));
    result[0][0] = s[0][0] == '#' ? 1 : 0;
    for(int64_t j = 1; j < W; ++j)
    {
        result[0][j] = result[0][j - 1] + (s[0][j - 1] == '.' && s[0][j] == '#' ? 1 : 0);
    }
    for(int64_t i = 1; i < H; ++i)
    {
        result[i][0] = result[i - 1][0] + (s[i - 1][0] == '.' && s[i][0] == '#' ? 1 : 0);
    }

    for(int64_t i = 1; i < H; ++i)
    {
        for(int64_t j = 1; j < W; ++j)
        {
            result[i][j] = min(result[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#' ? 1 : 0), result[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#' ? 1 : 0));
        }
    }

    cout << result[H - 1][W - 1] << endl;
}

int main()
{
    Main();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//Fast io
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//Class shorthands
#define ll long long
#define db long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
//Function Shorthands
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define po pop_back
#define eb emplace_back
//Code Shorthands
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
//Constants
#define hell 1000000007
#define PI acos(-1.0)
using namespace std;

void solve(){
	string s;
	cin>>s;
	int f=true, c = 0, ans = 0;
	for(int i:s){
		if(i=='R'){
			c++;
		}
		else{
			ans  = max(ans, c);
			c = 0;
		}
	}
	cout<<max(ans,c);
}

int main(){
	io;
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3612
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int k,n;
cin>>k>>n;
vector<int> v(n);
FOR(i,0,n) cin>>v[i];
int dist = 1e12;
// debug(-1%n+n);
FOR(i,1,n) {
    dist = min(dist,k-abs(v[i]-v[(i-1)]));
}
dist = min(dist,abs(v[0]-v[n-1]));
cout<<dist;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 1792
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    R = int(input())

    if R < 1200:
        print("ABC")
    elif R < 2800:
        print("ARC")
    else:
        print("AGC")


if __name__ == '__main__':
    main()


Measured memory_bytes: 4328
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC40(void);
void ABC41(void);
void ABC42(void);
void ABC43(void);
void ABC44(void);
void ABC45(void);
void ABC46(void);
void ABC47(void);
void ABC48(void);
void ABC49(void);

int main(void){
    ABC45();
}

void ABC45(){
    int a,b,c,asize,bsize,csize;
    char ch='a',ans;
    string sa,sb,sc;
    cin>>sa>>sb>>sc;
    a=sa.length();
    asize=sa.length();
    b=sb.length();
    bsize=sb.length();
    c=sc.length();
    csize=sc.length();
    while(1){
        if(ch=='a'){
            if(a==0){
                ans='A';
                break;
            }
            ch=sa[asize-a];
            a--;
        }
        if(ch=='b'){
            if(b==0){
                ans='B';
                break;
            }
            ch=sb[bsize-b];
            b--;
        }
        if(ch=='c'){
            if(c==0){
                ans='C';
                break;
            }
            ch=sc[csize-c];
            c--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFiveDishes solver = new BFiveDishes();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFiveDishes {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a[] = new int[5];
            for (int i = 0; i < 5; i++) a[i] = in.nextInt();
            int min = 10;
            for (int i = 0; i < 5; i++) {
                if (a[i] % 10 != 0) min = Math.min(a[i] % 10, min);
            }
            int ans = 0;
            for (int i = 0; i < 5; i++) {
                ans += Math.ceil((double) a[i] / 10) * 10;
            }
            if (min != 0) ans -= 10 - min;
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



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

ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll quickpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans*=a;
		a*=a;b>>=1;
	}
	return ans;
}
int main()
{
	int d,n;
	cin>>d>>n;
	if(d==0)
	{
		if(n==100) cout<<101<<endl;
		else cout<<n<<endl;
	}
	else if(d==1)
	{
		if(n==100) cout<<10100<<endl;
		else cout<<(ll)n*100<<endl;
	}
	else
	{
		if(n==100) cout<<1010000<<endl;
		else cout<<(ll)n*10000<<endl;
	}
	return 0;	
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] str = s.split(" ");
		BigDecimal[] big  = new BigDecimal[4];
		for (int i = 0; i < 4; i++) {
			big[i] = new BigDecimal(str[i]);
		}

		BigDecimal x = big[0].subtract(big[2]);
		BigDecimal y = big[1].subtract(big[3]);
		
		//BigDecimal l = x.multiply(x).add(y.multiply(y));
		
		//int[] in  = new int[4];
		//for (int i = 0; i < 4; i++) {
		//	in[i] = Integer.parseInt(str[i]);
		//}
		
		//int x = in[0] - in[2];
		//int y = in[1] - in[3];
		
		//System.out.println(Math.sqrt(x*x+y*y));

		double dx = x.doubleValue();
		double dy = y.doubleValue();
		
		System.out.println(Math.sqrt(dx*dx+dy*dy));
	}

}

Measured memory_bytes: 26476
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll sum = 0;
    ll minim = 1 << 30;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        ll temp = a[i];
        if (temp < 0)
        {
            sum += -temp;
            cnt++;
        }
        else
        {
            sum += temp;
        }
        minim = min(minim, abs(a[i]));
    }

    ll ans = 0;
    if (0 == cnt % 2)
    {
        ans = sum;
    }
    else
    {
        ans = sum - minim * 2;
    }

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

Measured memory_bytes: 3992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,cnt[9],a,i,ans=0;
	fill(cnt,cnt+9,0);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a;
		++cnt[min(a/400,8)];
	}
	for(i=0; i<8; ++i){
		if(cnt[i]){
			++ans;
		}
	}
	cout << (ans+((cnt[8]&&(!ans))?1:0)) << " " << (ans+cnt[8]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x[4];
  int i,j;
  if(scanf("%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&x[4]) == -1){
    return 0;
  }
 for(i = 0;i<5;i++){
   if(x[i] == 0){
     j = i+1;
   }
 }
  printf("%d",j);
  return 0;
}

Measured memory_bytes: 1732
// A: LCM
// NG
"use strict";
const inputRaw = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .trim()
  .split("\n");
//const inputRaw = "8 3\n7 3 1 8 4 6 2 5".split("\n");

const INPUT_SETTINGS_INDEX = 0;
const INPUT_LIST_INDEX = 1;
const INPUT_SETTINGS_N_INDEX = 0;
const INPUT_SETTINGS_K_INDEX = 1;
const INPUT_DELIMITER = " ";

const inputSettings = inputRaw[INPUT_SETTINGS_INDEX].split(INPUT_DELIMITER);
const N = inputSettings[INPUT_SETTINGS_N_INDEX];
const K = inputSettings[INPUT_SETTINGS_K_INDEX];
const inputList = inputRaw[INPUT_LIST_INDEX].split(INPUT_DELIMITER).map(curr =>
  parseInt(curr)
);

const findMinAndIndex = intList =>
  intList.reduce(
    (acc, curr, index) =>
      curr < acc.item ? { item: curr, index: index } : acc,
    {
      item: intList[0],
      index: 0,
    }
  );



const process = (N, K, inputList) => {
  const output = findMinAndIndex(inputList);

  const minIndex = output.index+1;
  const max2 = Math.max(1, Math.min(N - minIndex, minIndex) - 1)
  const test = K - 1
  const smaller = Math.ceil(max2 / test);
  const done = test * smaller + 1;

  return smaller + Math.ceil((N - done) / test);
};

console.log(process(parseInt(N), parseInt(K), inputList));


Measured memory_bytes: 16716
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int A,B,C,K; cin >> A >> B >> C >> K;
  int ans = 0;
  REP(i,K){
    if(A > 0){ ans += 1; A--; continue;}
    if(B > 0){ B--; continue;}
    if(C > 0){ ans -= 1; C--; continue;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long int
int value[300001]={0};
int tree[4*300000+100]={0};
int max_query(int start,int end,int left,int right,int index)
{
	if(left>end||start>right)
	  return 0;
	if(start>=left&&end<=right)
	  return tree[index];
    else
    {
		int mid=(start+end)/2;
		int x=max_query(start,mid,left,right,2*index);
		int y=max_query(mid+1,end,left,right,2*index+1);
		return max(x,y);
	}
}
void update(int start,int end,int point,int val,int index)
{
	if(point>end||point<start)
	  return ;
	if(start==end)
	{
		tree[index]=val;
		return ;
	}
	else
	{
		int mid=(start+end)/2;
		update(start,mid,point,val,2*index);
		update(mid+1,end,point,val,2*index+1);
		tree[index]=max(tree[2*index],tree[2*index+1]);
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int j,arr[n];
	for(j=0;j<n;j++)
	  cin>>arr[j];
	int dp[n];
	dp[n-1]=1;
	int start=0,end=300000;
	update(start,end,arr[n-1],1,1);
	for(j=n-2;j>=0;j--)
	{
		int left=arr[j]-k;
		int right=arr[j]+k;
		int here=1+max_query(start,end,left,right,1);
		dp[j]=here;
		update(start,end,arr[j],here,1);
	}
	int answer=dp[0];
	for(j=1;j<n;j++)
	  answer=max(answer,dp[j]);
	cout<<answer<<endl;
}


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

flag = 0

for i in range(n + 1):
    x = (5000 * n - m + 5000 * i) / 4000
    y = (m - 1000 * n - 9000 * i) / 4000
    
    if  x >= 0 and y >= 0 and x % 1 == 0 and y % 1 == 0:
        print(int(i), int(y), int(x))
        flag = 1
        break

if flag == 0:
    print(-1, -1, -1)


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

int main()
{
  int L, N, M, X;
  while (cin >> L >> N >> M >> X && L != 0) {
    static pair<int,int> sec[100];
    for (int i = 0; i < N; i++) {
      string s;
      cin >> s >> sec[i].first >> sec[i].second;
    }
    static pair<int,int> sta[100];
    for (int i = 0; i < M; i++) {
      string s;
      cin >> s >> sta[i].first >> sta[i].second;
    }
    sort(sta, sta+M);

    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
        int E = L - sec[i].first;
        int S = sec[i].second;
        if (i != j) {
          E -= sec[j].first;
          S += sec[j].second;
        }
        if (E < X) {
          continue;
        }
        static int dp[1000];
        static int cnt[1000];
        fill_n(dp, E+1, 0);
        fill_n(cnt, E+1, 0);
        int a = 0;
        for (int k = 0; k < M; k++) {
          for (int l = E - sta[k].first; l >= 0; l--) {
            if (dp[l+sta[k].first] < dp[l]+sta[k].second) {
              dp[l+sta[k].first] = dp[l]+sta[k].second;
              cnt[l+sta[k].first] = cnt[l]+1;
              if (cnt[l+sta[k].first] >= X) {
                a = max(a, dp[l+sta[k].first]);
              }
            }
          }
        }
        if (a != 0) {
          ans = max(ans, a+S);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    double A,B,C;
    cin>>A>>B;
    double i = 0;
    while(!(floor(i*0.1)>=B&&floor(i*0.08)>=A&&floor(i*0.1)<B+1&&floor(i*0.08)<A+1)){
      i++;
    if(i>=1300){
      i = -1;
      break;
    }
    }
    cout<<i<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,ll>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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




int main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    vector<int>cnt;
    int now = 0;
    if(s[0]=='1'){
        cnt.push_back(0);
        now++;
    }
    rep(i,n){
        int c = 0;
        while(s[i]-'0'==now){
            i++;
            c++;
        }
        i--;
        cnt.push_back(c);
        now = 1-now;
    }
  //for(auto x : cnt)cout<<x<<endl;
    int count = 0;
    int sum = 0;
    int r = 0;
    int res = 0;
    rep(l,cnt.size()){
        //if(l%2==0)count++;
      //cout<<l<<" "<<r<<" "<<count<<endl;
        while(r<cnt.size() && count+(1-r%2)<=k){
            if(r%2==0)count++;
            //if(count>k)break;
            sum += cnt[r];
            r++;
        }
      //cout<<l<<" "<<r<<" "<<count<<" "<<sum<<endl;
        res = max(res,sum);
        if(l==r)r++;
        else sum -= cnt[l];

        if(l%2==0)count--;
    }
    cout<<res<<endl;
}



Measured memory_bytes: 1020
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;
class Edge{
public:
    int to,from;
    Edge(int f,int t){
        to = t;
        from = f;
    }
};

int main(){
    int N,M;cin >> N >> M;
    vector<vector<Edge>> Edges(N);
    vector<vector<Edge>> uku(N);
    vector<int> deg(N, 0);
    for(int a = 0;a < M;a++){
        int b,c;cin >> b  >> c;
        deg[c-1]++;
        //b--;
        //c--;
        Edges.at(b-1).push_back(Edge(b-1,c-1));
        uku.at(c-1).push_back(Edge(b-1,c-1));
    }
    queue<int> S;
    vector<int> L;
    for(int a = 0;a < N;a++){
        if(deg[a]==0)S.push(a);
    }
    vector<bool> flag(N,true);
    while(!S.empty()){
        int n = S.front();S.pop();
        L.push_back(n);
        for(auto e : Edges.at(n)){
            deg[e.to]--;
            if(deg[e.to] == 0)S.push(e.to);
        }
        flag.at(n)=false;
    }
  //  return 0;
    bool itii =true;
    for(int a = 0;a < L.size()-1;a++){
        bool uk = false;
        for(auto b : Edges.at(L.at(a))){
            if(b.to == L.at(a+1))uk = true;
        }
        if(!uk)itii = false;
    }
    //return 0;
    for(int a = 0;a < L.size();a++){
        cout<<L.at(a)+1<<endl;
    }
    cout<<!itii<<endl;
}



Measured memory_bytes: 5668
N = int(input())
for d in range(64):
  if N < (26**(d+1)-1)//(26-1):
    N = N-(26**d-1)//(26-1)
    break
#print(d, N)
L = []
for i in range(d):
  n = N%26
  c = "abcdefghijklmnopqrstuvwxyz"[n]
  L.append(c)
  N = N//26
r = "".join(reversed(L))
print(r)


Measured memory_bytes: 9164
#include<bits/stdc++.h>
#define IOS                      \
    ios_base::sync_with_stdio(0);\
    cin.tie(0);                  \
    cout.tie(0);
#define eps 1e-6
#define ll long long
//#define int long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
const int mod=1000000007;
using namespace std;
//typedef pair<int ,int> P;
int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a[5];
	forr(i,0,5)
		cin>>a[i];
	forr(i,0,5)
	{
		if(a[i]==0)
			return cout<<i+1,0;
	}
	
	return 0; 	
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    int h,w;
    cin>>h>>w;
    char c[h][w];
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
        }
    }

    rep(i,h){
        rep(cnt,2){
            rep(j,w){
                cout<< c[i][j];
            }
            cout<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int x1, x2, y1, y2;
  cin>>x1>>y1>>x2>>y2;
  cout<<x2-(y2-y1)<<" "<<y2+(x2-x1)<<" "<<x1-(y2-y1)<<" "<<y1+(x2-x1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int INF = 1e15;

int d[500][500]; //d[u][v]は辺e=(u,v)のコスト（存在しない場合はINF、ただしd[i][i]=0とする）
int V; //頂点数

void init() {
    for(int i = 0;i < 500;i++) {
        for(int j = 0;j < 500;j++) {
            if(i == j) {
                d[i][j] = 0;
            }
            else {
                d[i][j] = INF;
            }
        }
    }
}

void warshall_floyd() {
	for(int k = 0;k < V;k++) {
		for(int i = 0;i < V;i++) {
			for(int j = 0;j < V;j++) {
				d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
			}
		}
	}
}

signed main() {
    int M,R;
    cin >> V >> M >> R;
    vector<int> vec(R);
    for(int i = 0;i < R;i++) {
        cin >> vec.at(i);
    }
    init();
    for(int i = 0;i < M;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        d[A - 1][B - 1] = C;
        d[B - 1][A - 1] = C;
    }
    warshall_floyd();
    int ret = INF;
    sort(vec.begin(),vec.end());
    do{
        int cnt = 0;
        for(int i = 0;i < R - 1;i++) {
            cnt += d[vec.at(i) - 1][vec.at(i + 1) - 1];
        }
        ret = min(ret,cnt);
    } while(next_permutation(vec.begin(),vec.end()));
    cout << ret << endl;
}


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


int main() {
  long long a,b,c,k;

  cin >> a >> b >> c >>k;

  long long total = 0;

  while(a>0){
    a--;
    k--;
    total++;
    if(k==0)
      break;

  }
  while(b>0){
    b--;
    if(k==0)
      break;
    k--;

  }
  while(c>0){
    c--;
    if(k==0)
      break;
    k--;
    total--;
  }
  
  cout << total;

}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    ll N, K;
    cin >> N >> K;
    vector<P> t(N);
    REP(i, N) cin >> t[i].first >> t[i].second;
    sort(t.begin(), t.end(), [](P a, P b){return a.second > b.second;});
    priority_queue<ll, vector<ll>, greater<ll>> red;
    set<ll> a;

    ll sum = 0;
    REP(i, K){
        sum += t[i].second;
        if (a.find(t[i].first) != a.end()) red.push(t[i].second);
        else a.insert(t[i].first);
    }
    ll tmp = sum + a.size() * a.size();
    for(int i = K; i < N; i++){
        if (a.find(t[i].first) == a.end() && a.size() != K){
            a.insert(t[i].first);
            sum -= red.top();
            sum += t[i].second;
            red.pop();
            tmp = max(tmp, sum + a.size() * a.size());
        }
    }
    cout << tmp << endl;



    return 0;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    int a[n] = {};
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);
    int ans=0;
    for(int i=n-1; i>=n-k; i--){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define y1 askjdkasldjlkasd
#include <bits/stdc++.h>
#undef y1

using namespace std;

#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)
#define clr(x) memset(x, 0, sizeof(x))
#define cpy(x,y) memcpy(x, y, sizeof(y))
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

#ifdef _DEBUG
#define LOCAL
#endif

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while (0)
#endif

double START_TIME;

void exit() {
#ifdef LOCAL	
	cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl;
#endif	
	exit(0);
}

template<typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
	fi(0, sz(v) - 1) {
		os << v[i] << " ";
	}
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T> t) {
	for (auto z : t) {
		os << z << " ";
	}
	return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
	cerr << endl;
	for (auto z : t) {
		os << "\t" << z.first << " -> " << z.second << endl;
	}
	return os;
}

#ifdef LOCAL
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#define dbg1(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 1; ABC <= n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) while(0){}
#define dbg0(x, n) while(0){}
#define dbg1(x, n) while(0){}
#endif

#ifdef LOCAL
#define ass(x) if (!(x)) { cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); }
#else
#define ass(x) assert(x)
#endif

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

void solve() {

}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	START_TIME = (double)clock();
#endif

	int n, k;	
	scanf("%d %d", &n, &k);
	int can = (n + 1) / 2;
	if (can >= k) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
	solve();

	exit();
	return 0;
}





Measured memory_bytes: 256
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(15);
    // Those who forgive themselves, and are able to accept their true nature...THEY ARE THE STRONG ONES

    int n, m;
    cin >> n >> m;
    vector<int> sign(n + 1, -1);
    sign[1] = 0;
    vector<int> adj[n + 1];
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    queue<int> q;
    q.push(1);
    int signposted = 0;
    while (!q.empty())
    {
        int curr = q.front();
        q.pop();
        for (auto i : adj[curr])
        {
            if (sign[i] == -1)
            {
                signposted++;
                sign[i] = curr;
                q.push(i);
            }
        }
    }
    if (signposted == n - 1)
    {
        cout << "Yes" << endl;
        for (int i = 2; i <= n; i++)
        {
            cout << sign[i] << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

void CountingSort(vector<int> &A, vector<int> &B, int k){
  vector<int> C(k+1, 0);
  for(int i = 1; i < A.size(); i++){
    C[A[i]]++;
  }
  for(int i = 1; i <= k; i++){
    C[i] = C[i] + C[i-1];
  }

  for(int i = A.size()-1; i >= 1; i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int maxv = 0;
  cin >> n;
  vector<int> A(n+1);
  vector<int> B(n+1);
  for(int i = 0; i < n; i++){
    cin >> A[i+1];
    maxv = max(maxv, A[i+1]);
  }
  CountingSort(A, B, maxv);
  for(int i = 1; i <= n; i++){
    cout << B[i];
    if(i == n) cout << '\n';
    else cout << " ";
  }
  return 0;
}

Measured memory_bytes: 16812
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    int ret = 100000;
    vector<int> sixes(1,1);
    vector<int> nines(1,1);
    int temp = 1;
    while(temp <= N){
        temp*= 6;
        sixes.push_back(temp);
    }
    temp = 1;
    while(temp <= N){
        temp*= 9;
        nines.push_back(temp);
    }
    for(int i = 0; i <= N; ++i) {
        temp = 0;
        int six = i;
        int nin = N-i;
        for(auto it = sixes.rbegin(); it != sixes.rend(); ++it) {
            temp += six/(*it);
            six -= six/(*it) * (*it);
        }
        for(auto it = nines.rbegin(); it != nines.rend(); ++it) {
            temp += nin/(*it);
            nin -= nin/(*it) * (*it);
        }
        ret = min(ret, temp);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256