akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stdio.h>

#define TIME 24 * 60 * 60

using namespace std;

int main(){
	int n;
	
	while(1){
		cin >> n;
		if(n == 0)
			break;
		
		int h_dep, m_dep, s_dep, h_arr, m_arr, s_arr;
		vector <int> dep(n), arr(n);
		for(int i = 0; i < n; i++){
			scanf("%d:%d:%d %d:%d:%d", &h_dep, &m_dep, &s_dep, &h_arr, &m_arr, &s_arr);
			dep[i] = s_dep + m_dep * 60 + h_dep * 60 * 60;
			arr[i] = s_arr + m_arr * 60 + h_arr * 60 * 60;
		}
		vector <int> train(TIME, 0);
		for(int i = 0; i < n; i++){
			train[dep[i]]++;
			train[arr[i]]--;
		}
		int max = 0;
		for(int i = 1; i < TIME; i++){
			train[i] += train[i - 1];
			if(train[i] > max)
				max = train[i];
		}
		
		cout << max << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1652
fun main(args: Array<String>) {
  val s = readLine()!!
  val n = s.length
  for (i in 0 until n - 1) {
    if (s[i] == s[i + 1]) {
      println("${i + 1} ${i + 2}")
      return
    }
  }
  for (i in 0 until n - 2) {
    if (s[i] == s[i + 2]) {
      println("${i + 1} ${i + 3}")
      return
    }
  }
  println("-1 -1")
}


Measured memory_bytes: 34104
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int_ N=205;
int_ n,a[N],b[N],c[N],d[N];
vector<int> e[N];
int f[N],vis[N];
bool findPath(int u) {
	vis[u] = 1;
	for (int i = 0; i < e[u].size(); i++) {
		if (f[e[u][i]] == -1 || (!vis[f[e[u][i]]] && findPath(f[e[u][i]]))) {
			f[u] = e[u][i];
			f[e[u][i]] = u;
			return true;
		}
	}
	return false;
}

int main()
{
    scanf("%lld",&n);
    for (int_ i=1;i<=n;i++) {
    	scanf("%lld%lld",a+i,b+i);
    }
    for (int_ i=1;i<=n;i++) {
    	scanf("%lld%lld",c+i,d+i);
    }
    for (int_ i=1;i<=n;i++) {
    	for (int_ j=1;j<=n;j++) {
    		if (a[i]<c[j]&&b[i]<d[j]) e[i].pb(j+n),e[j+n].pb(i);
    	}
    }
    int count = 0;
    memset(f, -1, sizeof(f));
	for (int i = 1; i <= 2*n; i++) {
		memset(vis, 0, sizeof(vis));
		if (f[i] == -1 && findPath(i)) {
			count++;
		}
	}
	cout << count << endl;
}


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

int main () {

	vector<string>s(3);
	
	cin>>s[0]>>s[1]>>s[2];
	
	char now = 'a', ans;
	
	while (true) {
		if(now == 'a') {
			if(s[0] == "") {
				ans = 'A';
				break;
			} else {
				//hapus elemen pertama dari kartu alice
				now = s[0][0];
				s[0].erase(s[0].begin());
			}
		}else if(now == 'b'){
			if(s[1] == ""){
				ans = 'B';
				break;
			}else{
				//hapus elemen pertama dari kartu bob
				now = s[1][0];
				s[1].erase(s[1].begin());
			}
		} else {
			if(s[2] == "") {
				ans = 'C';
				break;
			} else {
				now = s[2][0];
				//hapus elemen pertama carli
				s[2].erase(s[2].begin());
			}
		}
	}
	
	cout<<ans<<endl;
	
	
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    long[][] cake = new long[n][3];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < 3; j++) {
        cake[i][j] = sc.nextLong();
      }
    }
    long ans = 0;
    for(int k = 0; k < 8; k++) {
      long[] sum = new long[n];
      for(int i = 0; i < n; i++) {
        long s = 0;
        for(int j = 0; j < 3; j++) {
          if((k & (1 << j)) == 0) {
            s += cake[i][j];
          } else {
            s += (-1) * cake[i][j];
          }
        }
        sum[i] = s;
      }
      Arrays.sort(sum);
      long t = 0;
      for(int l = n - 1; l >= n - m; l--) {
        t += sum[l];
      }
      ans = Math.max(ans, t);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 28992
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll W;
    cin >> W;

    vl weight;
    weight.pb(1);
    for(ll i = 6; i <= W; i *= 6) {
        weight.pb(i);
    }
    for(ll i = 9; i <= W; i *= 9) {
        weight.pb(i);
    }

    ll n = weight.size();

    vvl dp(n+1, vl(W+1, INF));  // i番目までで重さがjとなるときの価値の総和の最小値
    rep(i, n+1) {
        dp[i][0] = 0;
    }

    rep(i, n) {
        rep(j, W+1) {
            chmin(dp[i+1][j], dp[i][j]);
            if(j >= weight[i]) {
                chmin(dp[i+1][j], dp[i+1][j - weight[i]] + 1);
            }
        }
    }

    out(dp[n][W]);
    re0;
}

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

    using namespace std;
    typedef long long ll;

    #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #define mp make_pair
    #define pb push_back
    #define lp(i,s,f) for(ll i = s; i < ll(f); i++)
    #define inF freopen("input.in", "r", stdin);
    #define outF freopen("output.in", "w", stdout);
    #define endl '\n'
    #define MOD 1000000007
    #define mm(arr) memset(arr, 0, sizeof(arr))
    #define int ll

    int32_t main(){
        FAST
        int n; cin >> n;
        int arr[n];
        for(int i = 0; i < n; i ++){
            cin >> arr[i];
        }
        for(int i = 0; i < n; i++){
            if(arr[i] == 0){
                cout << 0;
                return 0;
            }
        }
        int res = 1;
        for(int i = 0; i < n; i++){
            if(1000000000000000000LL/res >= arr[i]){
                res *= arr[i];
            }
            else{
                cout << -1;
                return 0;
            }
        }
        cout << res;
        return 0;
    }


Measured memory_bytes: 4336
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  vector<bool> s(K + 1);

  for (int i = 0; i < K + 1; i++) {
    for (int j : a) {
      if (i - j < 0) continue;

      s[i] = !s[i - j] | s[i];
    }
  }

  if (s[K]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}

/*
0 1 2 3 4
x x o o o
*/

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_sort = sorted(p, reverse=True)
q_sort = sorted(q, reverse=True)
r_sort = sorted(r, reverse=True)

del p_sort[X:]
del q_sort[Y:]

total_list = p_sort + q_sort + r_sort
total_list_sort = sorted(total_list, reverse=True)
del total_list_sort[(X+Y):]
print(sum(total_list_sort))


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

void search(int x, int y);

int w, h;
char maze[22][22]; //行（y)　列（x）
bool reached[22][22];
int ans;

int main() {
  while(cin >> w >> h) {
    if(w == 0 && h == 0) return 0;

    // 初期化
    for(int k = 0; k < h; k++) {
      for(int l = 0; l < w; l++) {
        maze[k][l] = '#';
        reached[k][l] = false;
      }
    }
    ans = 0;

    //fill(reached, false);
    // スタート座標
    int a, b;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        cin >> maze[i][j];
        if(maze[i][j] == '@') {
          a = i;
          b = j;
          // cout << a << " " << b << endl;
        }
      }
    }

    search(a, b);
    cout << ans << endl;

    // for(int i = 0; i < h; i++) {
    //   for(int j = 0; j < w; j++) cout << maze[i][j];
    //   cout << endl;
    // }
  }
}

void search(int y, int x) {
  // 迷路の外側か壁の場合は何もしない
  if(x < 0 || w <= x || y < 0 || h <= y || maze[y][x] == '#') return;
  // 以前に到達していたら何もしない
  if(reached[y][x]) return;
  ans++;
  reached[y][x] = true;  //　到達したよ

  // ４方向を試す
  search(y, x + 1); //右
  search(y, x - 1); //左
  search(y + 1, x); //下
  search(y - 1, x); //上
}



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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, X;
    cin >> N >> X;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll ans = 0;
    for (ll i = 1; i < N - 1; i++) {
        if (A[i - 1] + A[i] > X && A[i] + A[i + 1] > X) {
            ll t = min({A[i - 1] + A[i] - X, A[i] + A[i + 1] - X, A[i]});
            ans += t;
            A[i] -= t;
        }
    }
    for (ll i = 0; i < N; i++) {
        if (i == 0) {
            if (A[i] + A[i + 1] > X) {
                ll t = min(A[i], A[i] + A[i + 1] - X);
                ans += t;
                A[i] -= t;
            }
        }
        else if (i == N - 1) {
            if (A[i - 1] + A[i] > X) {
                ll t = min(A[i], A[i - 1] + A[i] - X);
                ans += t;
                A[i] -= t;
            }
        }
        else {
            if (A[i] + A[i + 1] > X) {
                ll t = min(A[i], A[i] + A[i + 1] - X);
                ans += t;
                A[i] -= t;
            }
            if (A[i - 1] + A[i] > X) {
                ll t = min(A[i], A[i - 1] + A[i] - X);
                ans += t;
                A[i] -= t;
            }
        }
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3992
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").mapIndexed { i, a -> Pair(i + 1, a.toInt()) }
    val ans = A.sortedBy { it.second }.map { it.first }
    println(ans.joinToString(" "))
}

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

int main() {
	int A,B,X;
	cin >> A >> B >> X;
	if (A + B >= X)
	  if (A <= X)
	    cout << "YES";
	  else
	    cout << "NO";
	else
	  cout << "NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define pa pair<int,int>
const int N=1e6+10;
const int mod=998244353;
using namespace std;

struct point{double x,y;}p[N],s[N];
inline bool cmp2(point a,point b)
{
    double aa=atan2(a.y-p[1].y,a.x-p[1].x);
    double bb=atan2(b.y-p[1].y,b.x-p[1].x);
    if(fabs(aa-bb)<=1e-10||aa==bb) return a.x<b.x;
    return aa<bb;
}
inline double cross(point a,point b,point c){return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x); }
inline int get(int n)
{
    p[0].x=p[0].y=2e9; int k;  
    for(int i=1;i<=n;i++) if(p[0].y>p[i].y||(p[0].y==p[i].y&&p[0].x>p[i].x)){p[0]=p[i]; k=i;}
    swap(p[k],p[1]);
    sort(p+2,p+1+n,cmp2);
    s[1]=p[1],s[2]=p[2]; int top=2;
    for(int i=3;i<=n;i++)
    {
        while(top>1&&cross(s[top-1],p[i],s[top])>=0) top--;
        s[++top]=p[i];
    }
    return top;
}
inline double dis(point a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); }
double get_d(int top)
{
    if(top==2) return dis(s[1],s[2]);
    s[++top]=s[1];
    double d=0; int j=3;
    for(int i=1;i<top;i++)
    {
        while(cross(s[j],s[i],s[i+1])<cross(s[j+1],s[i],s[i+1])) j=j%(top-1)+1;
        d=max(d,max(dis(s[i],s[j]),dis(s[i+1],s[j])));
    }
    return d;
}
int main()
{     
     int n; scanf("%d",&n);
     for(int i=1;i<=n;i++)  scanf("%lf%lf",&p[i].x,&p[i].y);
     int top=get(n);   
     double d=get_d(top);
     printf("%.10f\n",d);
return 0;   
}
/*
*/


Measured memory_bytes: 4640
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    string s; cin >> s; s += "@@";
    rep(i, s.size() - 2){
      if(s[i] == s[i + 1]){
        pri2(i + 1, i + 2);
        break;
      }
      if(s[i] == s[i + 2]){
        pri2(i + 1, i + 3);
        break;
      }
    }
    if(i == s.size() - 2)pri2(-1, -1);

/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <set>
#include <vector>
#include <list>
#include <deque>
#include <algorithm>
#include <stack>
#include <numeric>
#include <time.h>
#include<iomanip>
#pragma warning(disable:4996)
using namespace std;
const int inf = 0x7f7f7f7f;
const long long mod = 1e9 + 7;
int main()
{
	int n;
	cin >> n;
	double T, A;
	cin >> T >> A;
	double a[1200];
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] = T - a[i] * 0.006;
	}
	int t = 1;
	double minn = abs(a[1] - A);
	for (int i = 2; i <= n; i++)
		if (minn > abs(a[i] - A))
			t = i, minn = abs(a[i] - A);
	cout << t << endl;
}
// 运行程序: Ctrl + F5 或调试 >“始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门提示:
//   1. 使用解决方案资源管理器窗口添 加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件

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

public class Main implements Runnable {
	public static void main(String[] args) {
		// long t = System.currentTimeMillis();
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
		// System.err.println(System.currentTimeMillis() - t);
	}

	class BIT {
		int n;
		long[] v;

		public BIT(int n_) {
			n = n_;
			v = new long[n + 1];
		}

		void add(int k, int val) {
			++k;
			while (k <= n) {
				v[k] += val;
				k += k & -k;
			}
		}

		long sum(int k) {
			++k;
			long ret = 0;
			while (k > 0) {
				ret += v[k];
				k -= k & -k;
			}
			return ret;
		}
	}

	@SuppressWarnings("unchecked")
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		BIT bit = new BIT(n);
		while (q-- > 0) {
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (com == 0) {
				--x;
				bit.add(x, y);
			} else {
				--x;
				--y;
				System.out.println(bit.sum(y) - bit.sum(x - 1));
			}
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 104460
Option Infer On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Dim N, M As Integer
    Dim A, B As String()

    Sub Main()
        N = NextInt()
        M = NextInt()
        A = New String(N - 1) {}
        B = New String(M - 1) {}

        For i = 0 To N - 1
            A(i) = ReadLine()
        Next

        For i = 0 To M - 1
            B(i) = ReadLine()
        Next

        Dim ans = "No"

        For Ni = 0 To N - 1
            For Nj = 0 To N - 1
                If Judge(Ni, Nj) Then
                    ans = "Yes"
                    Exit For
                End If
            Next
            If ans = "Yes" Then Exit For
        Next

        WriteLine(ans)
    End Sub

    Function Judge(Ni As Integer, Nj As Integer) As Boolean
        For i = 0 To M - 1
            For j = 0 To M - 1
                If Ni + i >= N OrElse Nj + j >= N Then Return False
                If B(i)(j) <> A(Ni + i)(Nj + j) Then Return False
            Next
        Next

        Return True
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#pragma region defins
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
#pragma endregion
int n, s, ans;
int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
void dfs(int num, int sum, int count)
{
	//cout << "num:" << num << " sum:" << sum << " count:" << count << endl;
	if (sum == s&&count == n)
	{
		ans++;
		//cout << "ans: " << ans << endl;
	}
	if (sum > s || num == 10 || count == n)return;
	dfs(num + 1, sum + a[num], count + 1);
	dfs(num + 1, sum, count);
}

int main()
{
	while (1)
	{
		cin >> n >> s;
		if (n == 0 && s == 0)break;
		else
		{
			ans = 0;
			dfs(0, 0, 0);
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 3100
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    string A, B;
    cin >> A >> B;
    int N = A.size();
    int M = B.size();
    if(N > M) puts("GREATER");
    else if(N < M) puts("LESS");
    else{
        if(A > B) puts("GREATER");
        else if(A < B) puts("LESS");
        else puts("EQUAL");
    }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
  string N;
  cin >> N;
  rep(i, 3){
    if (N[i] == '1') {
      cout << '9';
    }else{
      cout << '1';
    }
  }
  cout << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int i, x, m, N;
    string S;
    cin >> N >> S;

    x = 0; m = 0;
    for (i=0;i<N;i++) {
        if (S[i] == 'I') x++;
        else x--;
        if (m<x) m = x;
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c; string s;
void f() {
	int flag = 0; c = 0;
	for (char ch : s) {
		if (ch == ',')return;
		c *= 10; c += ch - '0';
	}
}
int a[1100], b[1100]; set<int>st;
signed main() {
	int flag = 0;
	while (getline(cin, s)) {
		if (s == "")flag++;
		else {
			f();
			a[c]++;
			if (!flag)st.insert(c);
			else if (st.count(c))b[c] = 1;
		}
	}
	for (int t : st)if (b[t])cout << t << ' ' << a[t] << endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	fast_io();
	string s,t;
	cin >> s >> t;
	vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1));
	vector<vector<pii>> prior(s.length() + 1, vector<pii>(t.length() + 1, {0,0}));
	int n = s.length();
	int m = t.length();
	fu(i,1,n){
		fu(j,1,m){
			if(s[i-1] == t[j-1]){
				dp[i][j] = (s[i-1] == t[j-1]) + dp[i-1][j-1];
				prior[i][j] = {i,j};
			}
			else if(dp[i-1][j] > dp[i][j-1]){
				dp[i][j] = dp[i-1][j];
				prior[i][j] = prior[i-1][j];
			}
			else {
				dp[i][j] = dp[i][j-1];
				prior[i][j] = prior[i][j-1];
			}
		}
	}
	vector<char> v;
	pii p = prior[n][m];
	while(p.F != 0){
		v.pb(s[p.F-1]);
		p = prior[p.F-1][p.S-1];
	}
	cd(i,(int)v.size(),0){
		cout << v[i];	
	}cout << endl;
}


Measured memory_bytes: 106112
#include <iostream>
using namespace std;
int main() {
int A,B,K,ans;
  ans=0;
  cin >>K>>A>>B;
  for(int i=A;i<=B;i++){
  if(i%K==0){ans=1;}
  }
  if(ans==0){cout<<"NG";}else{cout<<"OK";}
}


Measured memory_bytes: 3128
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
  int q, a, b;
  string s, p, i;

  cin >> s >> q;

  while (q --> 0) {
    cin >> i >> a >> b;

    if (i == "replace") {
      cin >> p;
      s = s.replace(a, b - a + 1, p);
    } else if (i == "reverse") {
      reverse(s.begin() + a, s.begin() + b + 1);
    } else if (i == "print") {
      cout << s.substr(a, b - a + 1) << endl;
    }
  }

  return 0;
}

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

int main()
{
    string s,t;
    cin>>s>>t;
    vector<long int> x[26];
    //cout<<s<<endl;
    for(long int i=0;i<s.length();i++)
    {
        //cout<<s[i]<<endl;
        x[s[i]-'a'].push_back(i+1);
    }
    long long int ans=0;
    long int temp1=1;
    long int ans1=INT_MAX;
    for(long int i=0;i<t.length();i++)
    {
        ans1=INT_MAX;
        long int l=0,r=x[t[i]-'a'].size()-1;
        while(l<=r)
        {
            long int mid=(l+r)/2;
            if(x[t[i]-'a'][mid]>=temp1)
            {
                ans1=min(ans1,x[t[i]-'a'][mid]);
                r=mid-1;
            }
            else
            l=mid+1;
        }
        //cout<<ans1<<endl;
        if(ans1==INT_MAX)
        {
            ans+=temp1-1;
            ans=((ans-1)/s.length()+1)*s.length();
            temp1=1;
            long int l=0,r=x[t[i]-'a'].size()-1;
        while(l<=r)
        {
            long int mid=(l+r)/2;
            if(x[t[i]-'a'][mid]>=temp1)
            {
                ans1=min(ans1,x[t[i]-'a'][mid]);
                r=mid-1;
            }
            else
            l=mid+1;
        }
        }
        if(ans1==INT_MAX)
        break ;
        temp1=ans1;
        temp1++;
       // cout<<ans1<<" "<<ans<<endl;
    }
    if(ans1==INT_MAX)
    cout<<"-1";
    else
    cout<<ans+temp1-1;
}

Measured memory_bytes: 1724
let n, a, b, c = Scanf.scanf " %d %s %s %s" @@ fun a b c d -> a, b, c, d
let _ = Array.(fold_left (+) 0 @@ init n (fun i -> List.(length @@ sort_uniq compare [a.[i]; b.[i]; c.[i]]) - 1)) |> Printf.printf "%d\n"

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<int> d(c);
  fo(i,c)
    cin>>d[i];
  vector<int> e;
  for(int i=0;i<c;i++){
    for(int j=0;j<d[i];j++){
      e.push_back(i);
    }
  }
  vector<vector<int>> f(a,vector<int>(b));
  fo(i,a){
    fo(j,b){
      if(i%2==0)
        f[i][j]=e[i*b+j];
      else
        f[i][j]=e[(i+1)*b-j-1];
    }
  }
  fo(i,a){
    fo(j,b){
      cout<<f[i][j]+1;
      if(j==b-1)
        cout<<endl;
      else
        cout<<" ";
    }
  }
  /*    if(i%2==0){
      cout<<e[i*b+j]+1;
      if(j==b-1)
        cout<<endl;
      else
        cout<<" ";
      }
      else{
        fo(k,b)
          f[k]==e[i*b+k];
        rev(f);
        cout<<f[j]+1;
        if(j==b-1)
        cout<<endl;
        else
        cout<<" ";
      }
    }
  }*/
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    ll f[MAX_N] = {};
    rep(i,n){
        int a;
        cin >> a;
        f[a]++;
    }
    ll ans = 0;
    for(ll i = 0; i < MAX_N; i++){
        ans += f[i] * i;
    }
    int Q;
    cin >> Q;
    rep(_,Q){
        int b, c;
        cin >> b >> c;
        int tmp = f[b];
        ans -= f[b] * b;
        ans += f[b] * c;
        f[b] = 0;
        f[c] += tmp;
        cout << ans << endl;
    }

    return 0;
}




Measured memory_bytes: 5192
from heapq import heapify, heappushpop
import sys
sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * (N+1)
    C = [0] * (N+1)
    H = [a for a in A[:N]]
    heapify(H)
    B[0] = sum(A[:N])
    for i in range(N):
        x = heappushpop(H, A[N+i])
        B[i+1] = B[i] + A[N+i] - x
    H = [-a for a in A[2*N:]]
    heapify(H)
    C[0] = sum(A[2*N:])
    for i in range(N):
        x = -heappushpop(H, -A[2*N-i-1])
        C[i+1] = C[i] + A[2*N-i-1] - x
    print(max(b-c for b,c in zip(B, C[::-1])))

if __name__ == "__main__":
    main()

Measured memory_bytes: 37212
from math import atan2, degrees

if __name__ == "__main__":
    a, b, x = map(float, input().split())

    h = 2 * (b - x / a**2)

    if h > b:
        h = 2 * x / (a * b)
        ans = degrees(atan2(b, h))
    else:
        ans = degrees(atan2(h, a))

    print(ans)


Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        n: usize,
        p: [usize;n],
    }

    // let mut flag: bool = true;
    // let mut p_tmp:Vec<usize> = Vec::new();

    // for &value in &p{
    //     p_tmp.push(value);
    // }
    
    // for i in 0..n-1{
    //     for j in i..n{
    //         p_tmp.swap(i,j);
    //         flag = true;
    //         for k in 0..n-1{
    //             if p_tmp[k+1] < p_tmp[k]{
    //                 flag = false;  
    //                 break;
    //             }
    //         }   
    //         if flag == true {
    //             println!("YES");
    //             return;
    //         }
    //         p_tmp.swap(j,i);
    //     }
    // }

    // if flag == false{
    //     println!("NO");
    // }

    let mut cnt = 0;
    for i in 0..n{
        if p[i]!=i+1 {
            cnt+=1;
        }
    }

    if cnt > 2 {
        println!("NO");
    } else {
        println!("YES");
    }

}

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

// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000007LL
#define OO 1000000000000000007LL
#define maxN 17

// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)

// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;

// operation
#define mp make_pair
#define pb push_back
#define pf push_front
#define mt make_tuple

// structure
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vi>
#define iii pair <ii, int>

// get value
#define FF first
#define SS second
#define get(x, a) get<(x)>(a)

// data type
#define ll long long
#define ull unsigned long long

// function
#define lb lower_bound
#define ub upper_bound

// const value
#define pi 3.14159265358979323846264338327950288419716939937510

using namespace std;

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T min(T a, T b, T c, T d) {
    return min(a, min(b, min(c, d)));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template <class T>
T max(T a, T b, T c, T d) {
    return max(a, max(b, max(c, d)));
}

bool cmp(const int& a, const int& b) {return a > b;}

string s[107];
string t[107];

int main() {
//    #ifndef ONLINE_JUDGE
//        freopen("tmp.inp", "r", stdin);
//        freopen("tmp.out", "w", stdout);
//    #endif // ONLINE_JUDGE

    int n, m;
    scanf("%d%d", &n, &m);

    fto (i, 1, n) {
        cin >> s[i];
    }

    fto (i, 1, m) {
        cin >> t[i];
    }

    bool ans = 0;
    fto (i, 1, n-m+1) {
        fto (j, 0, n-m) {
            bool check = 1;
            fto (u, i, i+m-1) {
                fto (v, j, j+m-1) {
                    if (t[u-i+1][v-j] != s[u][v]) check = 0;
                }
            }
            ans |= check;
        }
    }

    if (ans) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h> 
#include<algorithm> 
#include<sstream>
#include<fstream>  
using namespace std; 
typedef long long ll; 
typedef long double ld; 

int ceil(int a, int m){
    // division of a and m
    if(a % m == 0){
        return a/m; 
    }
    else{
        return a/m + 1; 
    }
}

vector<int> sort(vector<int> arr){
    sort(arr.begin(), arr.end()); 
    return arr; 
}





int main(){

char nl = '\n'; 
char bl = ' ';
/*
For array arr use the following preamble to sort
int diff = sizeof(arr)/sizeof(arr[0]); 
sort(arr, arr + diff); 

*/

int a,b,c,l; 
cin >> a >> b >> c >> l; 
    bool ok = false; 

    for(int i = 0; i<=l; i++){
        for(int j = 0; j<=l; j++){
            for(int k = 0; k<=l; k++){
                if(i + j + k == l){
                    int fi = a * pow(2,i); 
                    int se = b*pow(2,j); 
                    int la = c * pow(2,k); 
                    if(se > fi && la > se){
                        ok = true; 
                    }
                }
            }
        }
    }
    if(ok){
        cout << "Yes"; 
    }
    else{
        cout << "No"; 
    }

}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> hi(n);
  for(int i =0; i<n ; i++)
    cin>>hi.at(i);
  bool ok =true;
  int r=hi.at(n-1);
  for(int j =n-1; j>0; j--){
    int c=hi.at(j-1);
    if(c-r>1)  ok =false;
    else if(c-r==1) hi.at(j-1)--;
    r = hi.at(j-1);
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
  
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long int
#define ss second
#define ff first
#define pb push_back
using namespace std;
const int MAX_N = 2 * 1e5 + 10, inf = 1e13 + 10, mod = 1000ll * 1000 * 1000 + 7ll;
vector <int> adj[MAX_N];
int dp[MAX_N];
int a[MAX_N];

int32_t main()
{
    //ios :: sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i =2; i < n; i++)
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));

    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int N=500005;char s[N];int a[N<<1],n,sum;
int main()
{
	int x=0;scanf("%s",s+1);n=strlen(s+1);
	for(RI i=1;i<=n;++i) a[i]=(s[n-i+1]-'0')*9;
	for(RI i=1;i<=n;++i) a[i]+=x,x=a[i]/10,a[i]%=10;
	while(x) a[++n]=x%10,x/=10;
	for(RI i=1;i<=n;++i) sum+=a[i];
	for(RI i=1,j;;++i) {
		a[1]+=9,sum+=9,j=1;
		while(a[j]>9) {
			sum-=a[j+1],a[j+1]+=a[j]/10,sum+=a[j+1];
			sum-=a[j],a[j]%=10,sum+=a[j];
			++j;if(j>n) n=j;
		}
		if(sum<=9*i) {printf("%d\n",i);return 0;}
	}
	return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define vi vector<int>
#define P push_back
#define F first
#define S second
#define debug(x) cout<<x<<" "
#define pi vector<pair<int,int> >
#define FOR(i,x,n) for(int i=x;i<n;i++)
using namespace std;
int main(){
    boost;
    int n,x;
    cin>>n>>x;
    vi l(n);
    //cin>>l[0];
    for(int i=1;i<=n;i++)cin>>l[i],l[i]+=l[i-1];
    int f=lower_bound(l.begin(),l.end(),x)-l.begin();
    if(l[f]>x)f--;
    cout<<f+1;


    return 0;
}


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

const int nmax = 8;
bool to[nmax][nmax];

int dfs(int v,int n,bool visited[nmax]){
  bool all_visited = true;

  rep(i,n){//全ての頂点を訪れたか調べる
    if(visited[i]==false) all_visited = false;
  }

  /*ベースケース*/
  if(all_visited) return 1;//全て訪れたなら

  /*再帰ステップ*/
  int res = 0;

  rep(i,n){//隣接する頂点について調べる
    if(to[v][i]==false) continue;//隣接していない頂点ならとばす
    if(visited[i]) continue;//訪問済み頂点ならとばす

    visited[i] = true;//一旦訪問済みにする
    res += dfs(i,n,visited);//さらに先の頂点について調べる
    visited[i] = false;//未訪問に戻す
  }

  return res;
}

int main(){
  int n,m;
  cin >> n >> m;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    to[a][b] = true;
    to[b][a] = true;
  }

  bool visited[nmax];
  rep(i,n) visited[i] = false;

  visited[0] = true;
  cout << dfs(0,n,visited) << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

const int INF = INT_MAX / 2;

struct Edge
{
	int from, to, cost;

	Edge( const int f, const int t, const int c ) : from( f ), to( t ), cost( c )
	{
		return;
	}
};

int bellmanford1( const int V, const vector< Edge > E, const int s, const int t )
{
	vector<int> dist( V, INF );
	dist[s] = 0;

	while ( true )
	{
		bool update = false;

		for ( int i = 0; i < E.size(); i++ )
		{
			if ( dist[ E[i].from ] != INF && dist[ E[i].from ] + E[i].cost < dist[ E[i].to ] )
			{
				dist[ E[i].to ] = dist[ E[i].from ] + E[i].cost;
				update = true;
			}
		}

		if ( !update )
		{
			break;
		}
	}

	return dist[t];
}

int bellmanford2( const int V, const vector< Edge > E, const int s, const int t )
{
	vector<int> dist( V, INF );
	dist[s] = 0;

	for ( int i = 1; i < V; i++ )
	{
		for ( int j = 0; j < E.size(); j++ )
		{
			dist[ E[j].to ] = min( dist[ E[j].to ], dist[ E[j].from ] + E[j].cost );
		}
	}

	return dist[t];
}

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

	vector< Edge > E;

	for ( int i = 0; i < m; i++ )
	{
		int a, b, ab, ba;
		char d;

		cin >> a >> d >> b >> d >> ab >> d >> ba;

		a--;
		b--;

		E.push_back( Edge( a, b, ab ) );
		E.push_back( Edge( b, a, ba ) );
	}

	int s, t, money, price;
	char d;

	cin >> s >> d >> t >> d >> money >> d >> price;

	s--;
	t--;

	cout << money - price - bellmanford1( n, E, s, t ) - bellmanford2( n, E, t, s ) << endl;

	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <tuple>

using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int x, y;
    cin >> x >> y;
    string s, t;
    cin >> s;
    cin >> t;
    vector<int> counts = {1, w, 1, h};
    for (int i = n - 1; i >= 0; i--) {
        if (t[i] == 'L') {
            counts[1] = min(w, counts[1] + 1);
        } else if (t[i] == 'R') {
            counts[0] = max(1, counts[0] - 1);
        } else if (t[i] == 'U') {
            counts[3] = min(h, counts[3] + 1);
        } else {
            counts[2] = max(1, counts[2] - 1);
        }
        if (s[i] == 'L') {
            counts[0]++;
        } else if (s[i] == 'R') {
            counts[1]--;
        } else if (s[i] == 'U') {
            counts[2]++;
        } else {
            counts[3]--;
        }
        if (counts[0] > counts[1] || counts[2] > counts[3]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (y < counts[0] || y > counts[1] || x < counts[2] || x > counts[3]) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define int long long
// const int MOD=1e9+7;
template <class Q>
void clearQueue(Q & q) {
    q = Q();
}
vector<int>adj[200005];
int maxx=-1;
bool visited[200005];
int dfs(int src){
    visited[src]=true;
    int cnt=1;
    for(auto edge:adj[src]){
        if(!visited[edge]){
            cnt+=dfs(edge);
        }
    }
    return cnt;
}
void solve(){
    int n,m;cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(int i=1;i<=n;i++){
        if(!visited[i]){
            int val=dfs(i);
            maxx=max(maxx,val);
        }
    }
    cout<<maxx;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

int main() {
    int n, a, temp;
    cin >> n >> a;
    temp = n % 500;
    if(temp <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct list{
  struct list *next;
  struct list *prev;
  int n;
};
struct list *ls;
void init();
void insert(int,int);
void delete(int);
void print();
void deleteFirst();
void deleteLast();
int main(){
  int n,i,com;
  char command[13];
  init();
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    if(!strcmp(command,"deleteFirst"))deleteFirst();
    else if(!strcmp(command,"deleteLast"))deleteLast();
    else{
      scanf("%d",&com);
        if(!strcmp(command,"insert")) insert(com,i);
        else if(!strcmp(command,"delete"))  delete(com);
    }
  }
  print();

  return 0;
}
void init(){
  ls=(struct list *)malloc(sizeof(struct list));
  ls->next=ls;
  ls->prev=ls;
}
void insert(int com,int i){
  struct list *array;
  array=(struct list *)malloc(sizeof(struct list));
  array->n=com;
  ls->next->prev=array;
  array->next=ls->next;
  array->prev=ls;
  ls->next=array;
  if(i==0)ls->prev=array;
}
void print(){
  struct list *a=ls->next;
  while(1){
    printf("%d",a->n);
    if(a->next==ls){
        printf("\n");
        return;
    }
    printf(" ");
    a=a->next;
    free(a->prev);
  }
}
void delete(int x){
  struct list *a=ls->next;
  while(1){
    if(a==ls)return;
    if(a->n==x){
      a->prev->next=a->next;
      a->next->prev=a->prev;
      free(a);
      return;
    }
    a=a->next;
  }
}

void deleteFirst(){
  ls->next=ls->next->next;
  ls->next->prev=ls;
}
void deleteLast(){
  ls->prev->prev->next=ls;
  ls->prev=ls->prev->prev;
}


Measured memory_bytes: 36204
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x=i;
        if(x%3==0){
            cout<<" "<<i;
        }else{
            while(x){
                if(x%10==3){
                    cout<<' '<<i;
                    break;
                }else{
                    x=x/10;
                }
            }
        }
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 3108
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int get_id(char c){
	if(c>='a'&&c<='z')return c-'a';
	if(c>='A'&&c<='Z')return c-'A'+26;
	return c-'0'+52;
}
char rev(int x){
	if(x<26)return 'a'+x;
	if(x<52)return 'A'+x-26;
	return '0'+x-52;
}
int cnt[66],func[66],n,tot_ask;
string cmp="";
int dp[199][199];
int dist(string s){
	memset(dp,inf,sizeof dp);
	dp[0][0]=0;tot_ask++; 
	for(int i=0;i<=s.size();i++){
		for(int j=0;j<=cmp.size();j++){
			if(j)dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
			if(i)dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
			if(i&&j)dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(s[i-1]!=cmp[j-1]));
		}
	}
	return dp[s.size()][cmp.size()];
}
int ask(string s){
	#ifdef LOCAL
		return dist(s);
	#endif
	cout<<"? "<<s<<endl;
	fflush(stdout);int x;cin>>x;return x;
}
int Get(string ret,string s,int pos,char c){
	int tot=ret.size()+1+s.size()-pos;
	string ss=ret+c+getstr(s,pos,s.size()-1);
	tot=ss.size();
	#ifdef LOCAL
		return dist(ss)==n-tot;
	#endif
	return n-tot==ask(ss);
}
string merge(string s1,string s2){
	int pos=0;
	string ret="";
	if(rand()&1)swap(s1,s2);
	for(int i=0;i<s1.size();i++){
		while(pos<s2.size()&&Get(ret,s2,pos,s1[i])==0)
		ret.push_back(s2[pos]),pos++;
		ret.push_back(s1[i]);
	}
	while(pos<s2.size())ret.push_back(s2[pos++]);
	return ret;
}
int main(){
	srand(time(0));
	for(int i=0;i<128;i++)cmp.push_back(rev(rand()%62));
	for(int i=0;i<62;i++){
		string s="";s.push_back(rev(i));
		for(int i=0;i<7;i++)s=s+s;
		int got=ask(s);
		cnt[i]=128-got;
	}
	for(int i=0;i<62;i++)n+=cnt[i];
	set<pair<int,string> >s;
	for(int i=0;i<62;i++){
		if(cnt[i]){
			string ins="";
			for(int j=0;j<cnt[i];j++)ins.push_back(rev(i));
			s.insert(make_pair(cnt[i],ins));
		}
	}
	while(s.size()>1){
		string s1=s.begin()->second;s.erase(s.begin());
		string s2=s.begin()->second;s.erase(s.begin());
		string s3=merge(s1,s2);
		s.insert(make_pair(s3.size(),s3));
	}
	cout<<"! "<<s.begin()->second<<endl;
	if(tot_ask>=855-128)assert(1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3704