akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
from decimal import *

def solve(N: int, K: int):
    N = Decimal(str(N))
    K = Decimal(str(K))
    print(abs(N - K*round(N/K)))


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N, K;
  cin >> N >> K;

  N %= K;
  cout << min(N, K-N) << endl;

  return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string s;
    cin >> s;
    if (s <= "2019/04/30") {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using namespace std;


int main(){
	int A, B;
	cin >> A >> B;

	int a = A+B, b = A-B, c = A*B;
	cout << max({ a, b, c }) << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace cswork {
    class Program {
        static void Main (string[] args) {
                        List<string> ss = ReadListStr();
            string a = ss[0];
            string b = ss[1];
            string c = ss[2];

            string x = a + b + c;

            if(x.Equals("755") || x.Equals("575") || x.Equals("557")){
                Write("YES");
            }else{
                Write("NO");
            }
            Exit ();
        }

        public static void Write (string str) {
            Console.WriteLine (str);
        }

        public static void Write (int i) {
            Console.WriteLine (i);
        }

        public static void Write (double d) {
            Console.WriteLine (d);
        }

        public static string ReadStr () {
            return Console.ReadLine ();
        }

        public static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }

        public static long Read () {
            return long.Parse (Console.ReadLine ());
        }

        public static double ReadDouble () {
            return double.Parse (Console.ReadLine ());
        }

        public static void Exit () { }

        public static List<string> ReadListStr () {
            return new List<string> (ReadStr ().Split (" "));
        }

        public static List<long> ReadList () {
            return ReadListStr ().ConvertAll (x => long.Parse (x));
        }

        public static List<int> ReadListInt () {
            return ReadListStr ().ConvertAll (x => int.Parse (x));
        }
    }
}

Measured memory_bytes: 25944
(* --------------Encoder-------------- *)
(* -----function----- *)
(*
let encoder = 0
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Decoder-------------- *)
(* -----function----- *)
(*
let decoder ans = ""
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Processor-------------- *)
(* -----function----- *)
(*
let processor dat = 0
*)

(* -------test------- *)
(* ----------------------------------- *)


(* ----------------main---------------- *)
(*
let () = print_endline (decoder (processor encoder))
*)
(* ------------------------------------ *)
let () = Scanf.scanf "%1d %1d %1d" (fun a b c -> a + b + c)
|> Printf.printf "%d\n"


Measured memory_bytes: 384
k=int(input())
if k%2==0 or k%5==0:
    print(-1)
else:
    if k==7 or k==1:
        print(1)
    else:
        a=7
        for i in range(1,10**6):
            a=10*a+7
            if a%k==0:
                print(i+1)
                break
            else:
                a=a%k

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

using namespace std;

int gcd(int l, int r) {

  if (r > l) swap(l, r);
  int m = l - r;
  if ( l%m == 0 and r%m == 0 ) return m;
  else return gcd(r, m);

}

#define MAX 405
#define INF (1<<21)
typedef long long ll;

int N, Ma, Mb;
int a[55], b[55], c[55];

int main() {

  cin >> N >> Ma >> Mb;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<vector<vector<int> > > 
	dp(N+1, vector<vector<int> >(MAX, vector<int>(MAX, INF)));

  /*
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++) {
      dp[0][i][j] = 0;
    }
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < MAX; j++) {
      dp[i][0][j] = 0;
      dp[i][j][0] = 0;
    }
  }
  */
  dp[0][0][0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < MAX; j++) {
      for (int k = 0; k < MAX; k++) {
        if ( j+a[i] >= MAX || k+b[i] >= MAX ) continue;
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
          // cout << dp[i][j][k] << endl;
      }
    }
  }

  int res = INF;
  for(int ma = Ma, mb = Mb; ma < MAX && mb < MAX; ma+=Ma, mb+=Mb) {
    res = min(res, dp[N][ma][mb]);
  }

  if( res == INF) res = -1;
  cout << res << endl;

  return 0;

}


Measured memory_bytes: 27776
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b){
    return a.second < b.second;
}

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    for(int i = 0; i < n; i++){
        int a;
//        cin >> a;
        scanf("%d", &a);
        q.push(a);
    }

    vector<pair<int, int> > v;
    for(int i = 0; i < m; i++){
        int b, c;
//        cin >> b >> c;
        scanf("%d %d", &b, &c);
        v.push_back(make_pair(b, c));
    }

    sort(v.begin(), v.end(), cmp);

    for(int i = 0; i < n && !v.empty();){
        int b = v.back().first;
        int c = v.back().second;
        v.pop_back();
//        cerr << b << " " << c << endl;
        for(int j = 0; j < b; j++){
            q.push(c);
        }
        i+=b;
    }

    long long int s = 0;
    for(int i = 0; i < n; i++){
//    while(!q.empty()){
        s += q.top();
//        cerr << q.top() << endl;
        q.pop();
    }

    cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 2164
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e5+4;
const int M=2e5+4;
int n,m;
struct Edge {
	int v,nxt;
}e[M<<1];
int head[N],etot;
inline void adde(int u,int v) {
	e[++etot].nxt=head[u],e[etot].v=v,head[u]=etot;
}
inline int read() {
	int x=0;char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x;
}
bool vis[N];
int pre[N];
inline void bfs() {
	queue<int> q;
	q.push(1);
	vis[1]=true;
	while (!q.empty()) {
		int p=q.front();
		q.pop();
		for (int i=head[p];~i;i=e[i].nxt) {
			int v=e[i].v;
			if (!vis[v]) {
				vis[v]=true;
				pre[v]=p;
				q.push(v);
			}
		}
	}
}
int main() {
	memset(head,-1,sizeof(head));
	n=read(),m=read();
	for (register int i=0;i<m;++i) {
		int u=read(),v=read();
		adde(u,v);
		adde(v,u);
	}
	bfs();
	for (register int i=2;i<=n;++i)
		if (!vis[i]) {
			puts("No");
			return 0;
		}
	puts("Yes");
	for (register int i=2;i<=n;++i)
		printf("%d\n",pre[i]);
	return 0;
}

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



int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    auto solve = [&](vector<int> a) {
        int n = a.size();
        sort(a.begin(), a.end());
        if (a[n - 1] - a[0] > 1) return false;
        if (a[n - 1] == a[0]) return a[0] != 0 && a[0] * 2 <= n || a[0] == n - 1;
        int cnt = 0;
        while (a[cnt] == a[0]) cnt++;
        return (a[n - 1] - cnt) * 2 <= n - cnt && a[n - 1] - cnt > 0;
    };

    int n;
    while (scanf("%d", &n) == 1) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]);

        auto f = solve(a);
        const string s[] = {"No", "Yes"};
        cout << s[f] << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


Measured memory_bytes: 1024
S = input()
N = len(S)

dp = [[0 for _ in range(13)] for _ in range(N+1)]
dp[0][0] = 1
MOD = 10**9 + 7
mul = 1
# n桁目の?は10^nを13で割った余り(mul)と掛け合わせて足される

for i in range(N):
    for k in range(10):
        if S[-i-1] != '?' and S[-i-1] != str(k):
            continue
        for j in range(13):
            dp[i+1][(j + mul * k) % 13] += dp[i][j]
    mul = (mul * 10) % 13
    for j in range(13):
        dp[i+1][j] %= MOD

res = dp[N][5]
print(res)


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

int N, M;
vector<vector<int>> switches(11);
vector<int> kiguu(11);
vector<bool> switchs(11);
int counter = 0;

void dfs(int a) {
  if (a == N) {
    for (int i = 0; i < M; i++) {
      int flag = 0;
      for (int j = 0; j < switches.at(i).size(); j++) {
        if (switchs.at(switches.at(i).at(j))) {
          flag++;
        }
      }
      if (flag % 2 != kiguu.at(i)) {
        break;
      }
      if (i == M - 1) {
        counter++;
      }
    }
    return;
  }
  switchs.at(a) = true;
  dfs(a + 1);
  switchs.at(a) = false;
  dfs(a + 1);
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      a--;
      switches.at(i).push_back(a);
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> kiguu.at(i);
  }
  dfs(0);
  cout << counter << endl;
}


Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))

INF = float('inf')
dp = [INF] * N
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,N):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

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

int main()
{
  size_t k;
  cin >> k;
  vector<int64_t> v = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  for (size_t p = 0; v.size() < k; p++) {
    for (int64_t i : vector<int64_t>({-1, 0, 1})) {
      int64_t d = v[p] % 10 + i;
      if (0 <= d && d <= 9) {
        v.push_back(v[p] * 10 + d);
      }
    }
  }
  cout << v[k - 1] << endl;
}


Measured memory_bytes: 1464
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int P = 1 << 11;
const int INF = 1 << 22;
int main(){
  int N;
  cin >> N;
  vector<int> V(N), W(N);
  for (int i = 0; i < N; i++){
    cin >> V[i] >> W[i];
  }
  int Q;
  cin >> Q;
  vector<int> query_v(Q);
  vector<int> query_L(Q);
  set<int> qv;
  for (int i = 0; i < Q; i++){
    cin >> query_v[i] >> query_L[i];
    qv.insert(query_v[i]);
  }
  vector<vector<pair<int, int>>> t2(N);
  for (int i = 0; i < N; i++){
    vector<int> V2, W2;
    int v = i + 1;
    V2.push_back(V[i]);
    W2.push_back(W[i]);
    if (v < P){
      while (v > 1){
        v /= 2;
        V2.push_back(V[v - 1]);
        W2.push_back(W[v - 1]);
      }
    } else {
      if (!qv.count(v)){
        continue;
      }
      while (v >= P * 2){
        v /= 2;
        V2.push_back(V[v - 1]);
        W2.push_back(W[v - 1]);
      }
    }
    int cnt = V2.size();
    vector<pair<int, int>> t;
    for (int j = 0; j < (1 << cnt); j++){
      int v_t = 0;
      int w_t = 0;
      for (int k = 0; k < cnt; k++){
        if ((j >> k) & 1){
          v_t += V2[k];
          w_t += W2[k];
        }
      }
      t.emplace_back(w_t, v_t);
    }
    sort(t.begin(), t.end());
    t2[i].push_back(t[0]);
    int cnt2 = t.size();
    for (int j = 1; j < cnt2; j++){
      if (t2[i].back().first == t[j].first){
        t2[i].back().second = t[j].second;
      } else {
        if (t2[i].back().second < t[j].second){
          t2[i].push_back(t[j]);
        }
      }
    }
  }
  /*
  for (int i = 0; i < N; i++){
    cout << "i = " << i << endl;
    for (auto p : t2[i]){
      cout << "(" << p.first << "," << p.second << ") ";
    }
    cout << endl;
  }
  */
  for (int i = 0; i < Q; i++){
    int v = query_v[i];
    int L = query_L[i];
    if (v < P){
      auto itr = upper_bound(t2[v - 1].begin(), t2[v - 1].end(), make_pair(L, INF)) - 1;
      cout << (*itr).second << endl;
    } else {
      int w = v;
      while (w >= P){
        w /= 2;
      }
      int ans = 0;
      for (auto p : t2[v - 1]){
        if (L - p.first >= 0){
          auto itr = upper_bound(t2[w - 1].begin(), t2[w - 1].end(), make_pair(L - p.first, INF)) - 1;
          ans = max(ans, p.second + (*itr).second);
        }
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 140188
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        int n,m,x;cin>>n>>m>>x;
        int ans=INT_MAX;
        int c[n],a[n][m];
        rep(i,n){
        	cin>>c[i];
        	rep(j,m)cin>>a[i][j];
        }
        for(int i=1;i<(1<<n);i++){
        	int temp=0;
        	int arr[m]={0};
        	for(int j=0;j<n;j++){
        		if(i&(1<<j)){
        			temp+=c[j];
        			rep(k,m)arr[k]+=a[j][k];
        		}
        		int f=1;
        		rep(k,m){
        			if(arr[k]<x)f=0;
        		}
        		if(f){
        			ans=min(ans,temp);
        		}
        	}
        }
        if(ans==INT_MAX)ans=-1;
        cout<<ans;
    }   
    timecalculater();
    return 0;   
} 

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

const int N = 2020;

int n, m, q, cnt[N][N], l[N][N], u[N][N];
char c[N][N];

int get(int a[][N], int x1, int y1, int x2, int y2) {
	return a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			cin >> c[i][j];
			cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + (c[i][j] == '1');
			l[i][j] = l[i - 1][j] + l[i][j - 1] - l[i - 1][j - 1] + (c[i][j] == '1' && c[i][j - 1] == '1');
			u[i][j] = u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1] + (c[i][j] == '1' && c[i - 1][j] == '1');
		}
	while (q--) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int ans = get(cnt, x1, y1, x2, y2);
		if (x2 > x1)
			ans -= get(u, x1 + 1, y1, x2, y2);
		if (y2 > y1)
			ans -= get(l, x1, y1 + 1, x2, y2);
		cout << ans << '\n';
	}
}

Measured memory_bytes: 53504
#if 0
2019.07.08

震惊，这题我竟然一遍过。
要求所有边被覆盖，对于这个条件，考虑用容斥处理，
对于每个边集 E ，钦定 E 不被覆盖后其他边随意的方案数为 f(E) ，
则 E 对答案的贡献为 f(E) * -1^|E| 。

钦定一些边不被覆盖相当于把树切成森林，每颗新的树独立。
考虑 DP ，设 f[u][i] 表示 u 的子树中，
去掉 u 在内的 i 个点的新树（这些点相互配对）的方案。
u -> v 转移时即 f[u][i + j] += f[u][i] * f[v][j] 。
特别地，对于 f[u][0] ，枚举 u 所在的新树大小 i ，f[u][0] -= f[u][i] * g[i] ，
其中 g[i] 表示大小为 i 的新树中随意配对的方案数，
为什么是 -= ？，因为要考虑容斥系数。
#endif
#include <cstdio>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 5005, mod = 1000000007;
lolong f[maxn][maxn], fu[maxn], g[maxn];
int size[maxn];
std::vector<int> G[maxn];

void dp(int u, int fa) {
	size[u] = 1;
	f[u][1] = 1;
	for(int v : G[u])
		if(v != fa) {
			dp(v, u);
			for(int i = 0; i <= size[u]; i ++) {
				fu[i] = f[u][i];
				f[u][i] = 0;
			}
			for(int i = 0; i <= size[u]; i ++)
				for(int j = 0; j <= size[v]; j ++)
					(f[u][i + j] += fu[i] * f[v][j]) %= mod;
			size[u] += size[v];
		}
	if(f[u][0]) puts("FUCK");
	for(int i = 1; i <= size[u]; i ++)
		(f[u][0] -= f[u][i] * g[i]) %= mod;
}

int main() {
	int n = input();
	for(int i = 1; i < n; i ++) {
		int u = input(), v = input();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	g[0] = 1;
	for(int i = 2; i <= n; i ++)
		g[i] = g[i - 2] * (i - 1) % mod;
	dp(1, 0);
	printf("%lld\n", (mod - f[1][0]) % mod);
}

Measured memory_bytes: 195328
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int ans = 1010;
  int N, T;
  scanf("%d%d", &N, &T);
  for(int i=0; i<N; ++i)
  {
    int c, t;
    scanf("%d%d", &c, &t);
    if(t>T) continue;
    ans = min(ans, c);
  }
  if(ans == 1010) puts("TLE");
  else printf("%d\n", ans);
  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 P = pair<int,int>;

int main(){
  int x,n;
  cin >> x >>n;
  vector<int> d(102);
  rep(i,n){
    int p;
    cin >> p;
    d[p] = 1;
  }
  
  P ans(99999,-1);
  for (int i = 0; i <= 101; ++i){
    if (d[i] == 1) continue;
    int dif = abs(x-i);
    ans = min(ans, P(dif,i));
  }
  cout << ans.second << endl;
}

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

using namespace std;

const int N = 51;

int n;
string a[N];
int alphaHash[26][N];

void readInput() {
    
    cin >> n;

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

int main(int argc, char const *argv[]) {
    
    readInput();

    for(int i = 0; i < n; i ++) {
        for(int j = 0; j < a[i].size(); j ++) {
            alphaHash[a[i][j] - 'a'][i] ++;
        }
    }

    string ans;

    for(int i = 0; i < 26; i ++) {
        int mina = 100;
        for(int j = 0; j < n; j ++) {
            mina = min(mina, alphaHash[i][j]);
        }
        while(mina --) {
            ans += (char) ('a' + i);
        }
    }

    sort(ans.begin(), ans.end());

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        System.out.println(((fsc.nextInt()+fsc.nextInt())*fsc.nextInt())/2);
        fsc.close();
        
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 22356
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String answer = "Good";
    String s = sc.next();
    for(int i=0;i<3;i++){
      if(s.charAt(i)==s.charAt(i+1)){
        answer="Bad";
      }
    }
     System.out.println(answer);    
 
  }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define show(x, y); cout << x << " " << y << endl;
using namespace std;

int n, m;
vector<int> g[100001];
bool vis[100001];
int path[100001];
int inDegree[100001];

void dfs(int u){
    vis[u] = true;
    for(auto v : g[u]){
        path[v] = max(path[v], path[u] + 1);
        inDegree[v]--;
        if(inDegree[v] == 0){
            dfs(v);
        }
    }
}

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

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        inDegree[y]++;
    }
    for(int i = 1;i <= n; i++){
        if(vis[i] == false && inDegree[i] == 0){
            dfs(i);
        }
    }
    int ans = 1;
    for(int i = 1 ; i <= n; i++){
        ans = max(ans, path[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 3e5+100;

ll l[MAX],r[MAX];

int main(){
	fastio;
	ll tc,n,k,c,w,ind;
	string s;
	cin>>n>>k>>c>>s;
	ind=0,w=0;
	while(w<k){
		if(s[ind]=='x') ind++;
		else{
			l[w++]=ind;
			ind+=(c+1);
		}
	}
	ind=n-1,w=k-1;
	while(w>=0){
		if(s[ind]=='x') ind--;
		else{
			r[w--]=ind;
			ind-=(c+1);
		}
	}
//	f(i,0,k) cout<<l[i]<<" "<<r[i]<<endl;
	f(i,0,k) if(l[i]==r[i]) cout<<l[i]+1<<endl;
  	return 0;	
}

Measured memory_bytes: 5396
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
  int a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
  if(b-a>k or c-b > k or d-c >k or e-d > k or e-a > k) cout<<":("<<endl;
  else cout<<"Yay!"<<endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N, M, K=map(int, input().split())
    friend_or_block = [0] * N
    friends_chain = UnionFindTree(N)

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        friends_chain.unite(a, b)
        friend_or_block[a] += 1
        friend_or_block[b] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if friends_chain.same(c, d):
            friend_or_block[c] += 1
            friend_or_block[d] += 1

    print(*[friends_chain.count(i) - friend_or_block[i] - 1 for i in range(N)])

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def root(self, x):
        p, s = self.parent[x], list()
        while p >= 0:
            s.append(x)
            x, p = p, self.parent[p]
        for c in s: self.parent[c] = x
        return x

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

    def count(self, x): return -self.parent[self.root(x)]

    def unite(self, x, y):
        xr, yr = self.root(x), self.root(y)
        if xr == yr: return
        if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr
        self.parent[xr] += self.parent[yr]
        self.parent[yr] = xr

if __name__ == '__main__':
    main()



Measured memory_bytes: 62296
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<pii> re;
  rep(i,n)if(i%3==1)rep(j,n)if((i+j)%2) re.eb(i,j);
  rep(i,n)if(i%2) re.eb(i,0);
  if(n%3==1)rep(j,n)if((n-1+j)%2) re.eb(n-1,j);
  sort(all(re)); UNIQUE(re);
  cout<<re.size()<<endl;
  for(pii p:re) cout<<p.X<<" "<<p.Y<<endl;
  return 0;
}


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

using namespace std;

vector<int> calc(int t, string &num, int key){
	vector<int> sum;
	string::reverse_iterator it = num.rbegin();
	int temp = *it - '0';
	int mlt = 10;
	it++;
	for(int i = 1; i <= 1 << (num.size() -2); i <<= 1){
		if((key & i) == i){
			sum.push_back(temp);
			temp = *it - '0';
			mlt = 10;
		}
		else{
			temp += (*it - '0')*mlt;
			mlt *= 10;
		}
		it++;
	}
	sum.push_back(temp);
	/*
	for(int i = 0; i < sum.size(); i++){
		cout << sum[i] << " ";
	}
	cout << endl;
	*/
	return sum;
}

int main(){
	while(true){
		int t;
		string num;
		cin >> t >> num;
		if(t == 0 )break;
		vector<int> ans(1);
		ans[0] = atoi(num.c_str());
		int anssum = t >= ans[0] ? ans[0] : 0;
		bool flag = false;
		for(int i = 1; i < (1 << (num.size()-1)); i++){
			vector<int> temp = calc(t,num,i);
			int sum = accumulate(temp.begin(),temp.end(),0);
			if(sum > t)continue;
			if(sum > anssum){
				anssum = sum;
				swap(ans,temp);
				flag = false;
			}
			else if(sum == anssum){
				flag = true;
			}
		}
		if(anssum == 0){
			cout << "error" << endl;
		}
		else if(flag){
			cout << "rejected" << endl;
		}
		else {
			cout << anssum << " ";
			for(int i = ans.size()-1; i >= 0; i--){
				cout << ans[i];
				if(i != 0){
					cout << " ";
				}
			}
			cout << endl;
		}
	}
		
	return 0;
}

Measured memory_bytes: 2996
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 1000000000000000000
using namespace std;
typedef long long ll;


int main() {
	unsigned long long x, y;
	cin >> x >> y;
	if (x > y)x -= y;
	else x = y - x;
	if (x > 1)cout << "Alice" << endl;
	else cout << "Brown" << endl;
	return 0;
}

Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let rec f cnt curr line =
    if curr >= line then
        cnt
    else
        f (cnt + 1) (curr * 2) line

[<EntryPoint>]
let main _ =
    let [n;k] = reads int
    [1 .. n]
    |> List.map (fun x -> (1. / float n) * 0.5 ** float (f 0 x k))
    |> List.sum
    |> printfn "%0.12f"
    0

Measured memory_bytes: 22360
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
using namespace std;
signed main()
{
	cin.tie(0); ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int a[100005];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int num[100005] = { 0 };
	int num2[100005] = { 0 };
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0)num[a[i]] += 1;
	}
	int ans = 0;
	int maxi = 0;
	int maxinum = 0;
	for (int i = 0; i < 100005; i++) {
		if (num[i] > maxi) { maxi = num[i]; maxinum = i; }
	}
	for (int i = 0; i < n; i++) {
		if (i% 2 == 1)num2[a[i]] += 1;
	}
	int maxi2 = 0;
	int maxi2num = 0;
	for (int i = 0; i < 100005; i++) {
		if (num2[i] > maxi2) { maxi2 = num2[i]; maxi2num = i; }
	}
	if(maxinum==maxi2num){
		if (maxi > maxi2) {
			sort(num2, num2 + 100005);
			ans = n - maxi - num2[100003];
		}
		else {
			if(maxi==maxi2){
				sort(num2, num2 + 100005);
				sort(num, num + 100005);
				ans = n - maxi - max(num2[100003], num[100003]);
			}
			else {
				sort(num, num + 100005);
				ans = n - maxi2 - num[100003];
			}
		}
	}
	else ans = n - maxi - maxi2;
	cout << ans;
}

Measured memory_bytes: 1408
# from operator import mul
# from functools import reduce

n=int(input())
a=list(map(int, input().split()))

ans = 1
# ans = reduce(mul, a) #=> 1320
if 0 in a:
  ans = 0

for i in range(n):
  ans *= a[i]
  if ans > 10 ** 18:
  # if a[i] == 0:
  #   break
  # elif (ans*a[i]) > limit:
    ans = -1
    break

# for i in range(n):
#   if a[i] == 0:
#       ans = 0

# # if ans > limit:
# #   print(-1)
# # else:
print(ans)


Measured memory_bytes: 21648
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int f[100000];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main(){
	int n,m;
	scanf("%d%d", &n,&m);
	if (n*m % 2 == 1) {
		puts("Yes");
	}
	else {
		puts("No");
	}
}

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

int main (void){
  int n = 0,t = 0, min = 10000;

  cin >> n >> t;

  vector<int> c(n,0);
  vector<int> h(n,0);

  for(int i = 0;i < n;i++){
    cin >> c[i];
    cin >> h[i];
  }

  for(int i = 0;i < n;i++){
    if(h[i] <= t){
      if(min > c[i]){
        min = c[i];
      }
    }
  }
  if(min <= 1000){
    cout << min << endl;
  }else{
    cout << "TLE\n";
  }

  return 0;
}

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

double distance_between_two_coordinates(pair<double,double> A, pair<double,double> B) {
  double forX = (A.first-B.first);
  double forY = (A.second-B.second);
  return sqrt((forX * forX) + (forY * forY));
}

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

  vector<pair<double,double>> coordinates;

  for (int i = 0; i < N; i++){
    double x,y; cin >> x >> y;

    coordinates.push_back({x,y});
  }

  sort(coordinates.begin(), coordinates.end());

  double ways = 0;
  double total_sum = 0;
  do {
    for (int i = 1; i < coordinates.size(); i++) {
      total_sum+= distance_between_two_coordinates(coordinates[i-1], coordinates[i]);
    }

    ways+=1;
  } while(next_permutation(coordinates.begin(), coordinates.end()));

  // cout << ways << endl;
  // cout << fixed << endl;
  cout.precision(17);
  double answer = total_sum / ways;
  cout <<  fixed << answer << endl;
  return 0;
}


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int n;
int k;
set<int> megh;
int poss(int x)
{  int f=1;
    while(x)
   {   int y=x%10;
      if(megh.find(y)!=megh.end())
      {   f=0;
          break;
	  }
	  x/=10;
   }
   return f;
}
int main()
{   scanf("%d %d",&n,&k);
   int i;
   for(i=1;i<=k;i++)
   {  int x;
      scanf("%d",&x);
      megh.insert(x);
   }
   for(i=n;;i++)
   {   if(poss(i))
      {   printf("%d\n",i);
          return 0;
	  }
   }
   return 0;
}

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

typedef int Cost;
const Cost INF = 1 << 28;

struct Edge {
	int src, dst;
	Cost cost;
	Edge() {}
	Edge(int src, int dst, Cost cost = 1): src(src), dst(dst), cost(cost) {}
};

typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;

void addEdge(Graph &g, int src, int dst, int cost = 1)
{
	g[src].push_back(Edge(src, dst, cost));
};

Graph transpose(const Graph &g)
{
	Graph rg(g.size());
	for (int i = 0; i < g.size(); i++){
		for (int j = 0; j < g[i].size(); j++){
			addEdge(rg, g[i][j].dst, g[i][j].src, g[i][j].cost);
		}
	}
	return rg;
}

std::vector<Cost> dijkstra(const Graph &g, int src){
	std::vector<Cost> dist(g.size(), INF);
	std::priority_queue<std::pair<Cost, int>,
	                    std::vector<std::pair<Cost, int> >,
						std::greater<std::pair<Cost, int> > > pq;
	
	dist[src] = Cost(0);
	pq.push(std::make_pair(Cost(0), src));
	
	while (pq.size()){
		int cur = pq.top().second;
		Cost sum = pq.top().first;
		pq.pop();
		if (dist[cur] < sum) continue;
		
		for (int i = 0; i < g[cur].size(); i++){
			const Edge &e = g[cur][i];
			if (dist[e.dst] > sum + e.cost){
				dist[e.dst] = sum + e.cost;
				pq.push(std::make_pair(sum + e.cost, e.dst));
			}
		}
	}
	
	return dist;
}

void dfs_(const Graph &g, int v, bool *used, std::vector<int> &vs)
{
	used[v] = true;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i].dst;
		if (!used[to]) dfs_(g, to, used, vs);
	}
	vs.push_back(v);
}

void rdfs_(const Graph &g, int v, int k, bool *used, std::vector<int> &cmp)
{
	used[v] = true;
	cmp[v] = k;
	for (int i = 0; i < g[v].size(); i++){
		int to = g[v][i].dst;
		if (!used[to]) rdfs_(g, to, k, used, cmp);
	}
}

int scc(const Graph &g, std::vector<int> &cmp)
{
	Graph rg = transpose(g);
	std::vector<int> vs;
	bool *used = new bool[g.size()];
	cmp.resize(g.size());
	
	memset(used, false, g.size());
	for (int v = 0; v < g.size(); v++){
		if (!used[v]) dfs_(g, v, used, vs);
	}
	
	memset(used, false, g.size());
	int k = 0;
	for (int i = vs.size() - 1; i >= 0; i--){
		if (!used[vs[i]]) rdfs_(rg, vs[i], k++, used, cmp);
	}
	
	delete used;
	return k;
}

int main()
{
	int v, e;
	std::scanf("%d %d", &v, &e);
	
	Graph g(v);
	
	for (int i = 0; i < e; i++){
		int s, t;
		std::scanf("%d %d", &s, &t);
		addEdge(g, s, t);
	}
	
	std::vector<int> cmp;
	scc(g, cmp);
	
	int q;
	std::scanf("%d", &q);
	for (int i = 0; i < q; i++){
		int u, v;
		std::scanf("%d %d", &u, &v);
		int r = cmp[u] == cmp[v];
		std::printf("%d\n", r);
	}
	
	return 0;
}

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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		sum += v[i];
	}
	int add = 0;
	int ans = 1e9;
	for (int i = 0; i < n; ++i) {
		add += v[i];
		ans = min(ans,abs(add-(sum - add)));
	}
	cout << ans;
}



Measured memory_bytes: 256
#include <cstdio>
#include <utility>

using namespace std;
typedef pair<int,int> P;

int main() {
	P land[25];
	int n;
	while(scanf("%d",&n),n) {
		for(int i=0;i<n;i++) {
			scanf("%d %d",&land[i].first,&land[i].second);
		}
		for(int i=0;i<(n-1);i++) {
			for(int j=i+1;j<n;j++) {
				if(land[i].second>land[j].second) {
					P tmp=land[i];
					land[i]=land[j];
					land[j]=tmp;
				}
			}
		}
		int i,w=0;
		for(i=0;i<n;i++) {
			if((w+=land[i].first)>land[i].second) break;
		}
		printf(i==n?"Yes\n":"No\n");
	}
}

Measured memory_bytes: 1012
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using namespace std;
struct mInfo{
  ll rowNum;
  ll columnNum;
};
int main(){
  ll h,w,ii,jj,kk;
  cin >> h >> w;
  string str[h+2];
  vector<ll> ww[h+2],hh[w+2];
  for(ii=1;ii<=h;ii++){
    cin >> str[ii];
    str[ii] = "#" + str[ii] + "#";
  }
  str[0] = string(w+2,'#');
  str[h+1] = string(w+2,'#');
  //memset(str[0],"#",(w+2));

  ll matrix[h+2][w+2];
  mInfo mInfo[h+2][w+2];
  
  for(ii=0;ii<=h+1;ii++){
    for(jj=0;jj<=w+1;jj++){
      //cout << ii << endl;
      //cout << str[ii][jj] ;
      if(str[ii][jj] == '.'){
	matrix[ii][jj] = 0;
      }
      else{
	matrix[ii][jj] = 1;
	
	ww[ii].push_back(jj);
	hh[jj].push_back(ii);
	
      }
      
      mInfo[ii][jj].rowNum = 0;
      mInfo[ii][jj].columnNum = 0;      
    }
    //cout << endl;
  }

//  for(ii=0;ii<h;ii++){
//    for(jj=0;jj<w;jj++){
//      if(matrix[ii][jj] != 1){
//	
//      }
//    }
//  }
  ll len;
  for(ii=1;ii<=h;ii++){

    for(jj=0;jj<ww[ii].size()-1;jj++){
      //cout << ww[ii][jj];

      len = ww[ii][jj+1] - ww[ii][jj] - 1;
      
      for(kk=ww[ii][jj];kk<=ww[ii][jj+1];kk++){

	if(matrix[ii][kk] != 1){
	  mInfo[ii][kk].rowNum = len;
	}

      }
    }
    //cout << endl;
  }

  for(ii=1;ii<=w;ii++){
    for(jj=0;jj<hh[ii].size()-1;jj++){
      //cout << hh[ii][jj];
      
      len = hh[ii][jj+1] - hh[ii][jj] -1 ;

      for(kk=hh[ii][jj];kk<=hh[ii][jj+1];kk++){

	if(matrix[kk][ii] != 1){
	  mInfo[kk][ii].columnNum = len;
	}
	
      }
    }
  }

  //cout << endl << "--------" << endl;
  ll max = 0,tmp;
  for(ii=1;ii<=h;ii++){
    for(jj=1;jj<=w;jj++){
      //cout << " " << mInfo[ii][jj].rowNum << " " << mInfo[ii][jj].columnNum;
      tmp = mInfo[ii][jj].rowNum + mInfo[ii][jj].columnNum - 1;
      if(tmp > max){
	max = tmp;
      }
    }
    //cout << endl;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 168832
while True:
    a, length = map(int, input().split())
    if length == 0:
        break
    mem = dict()
    mem[a] = 0
    cnt = 0
    while True:
        cnt += 1
        sa = list(str(a).zfill(length))
        sa.sort()
        under = int("".join(sa))
        sa.reverse()
        top = int("".join(sa))
        a = top - under
        if a in mem:
            print(mem[a], a, cnt - mem[a])
            break
        else:
            mem[a] = cnt



Measured memory_bytes: 5596
/**
 *    author:  tourist
 *    created: 12.12.2019 13:27:17       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> w(n);
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> d[i];
  }
  long long low = 0, high = (long long) 9e18;
  while (low < high) {
    long long mid = (low + high) >> 1;
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      if (mid >= w[i]) {
        cnt += (mid - w[i]) / d[i] + 1;
        if (cnt >= k) {
          break;
        }
      }
    }
    if (cnt >= k) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << low << '\n';
  return 0;
}


Measured memory_bytes: 1408
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		if(Math.abs(c-a)<=d){
			System.out.println("Yes");
		}else if(Math.abs(c-b)<=d && Math.abs(b-a)<=d){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 21460
import java.util.*

private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

class Island {
    val rejectionsEast: MutableSet<Int> = HashSet()
}

fun main(args: Array<String>) {
    val (N, M) = readInts()
    val intervals = (1..M).map { readInts() }.map { ints -> ints[0] to ints[1] }
    val islands = (1..N).map { Island() }

    intervals.forEach { islands[it.first - 1].rejectionsEast.add(it.second - 1) }
    var brokenCount = 0
    val inclusions = mutableSetOf<Int>()

    (0 until N-1).forEach { bridgeIndex ->
        inclusions.addAll(islands[bridgeIndex].rejectionsEast)
        if (inclusions.contains(bridgeIndex + 1)) {
            inclusions.clear()
            brokenCount += 1
        }
    }
    println(brokenCount)
}

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

bool kaibun(int n) {
  int a = n / 10000;
  int b = (n - a * 10000) / 1000;
  int c = (n - a * 10000 - b * 1000) / 100;
  int d = (n - a * 10000 - b * 1000 - c * 100) / 10;
  int e = n % 10;
  if(a == e && b == d) return 1;
  else return 0;
}

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; i++) {
    if(kaibun(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
      BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
      
      while(true){
      String[] num=buf.readLine().split(" ");
      int  x=Integer.parseInt(num[0]);
      int y=Integer.parseInt(num[2]);
      
          if(num[1].equals("+"))
              System.out.println(x+y);
          else if(num[1].equals("-"))
              System.out.println(x-y);
          else if(num[1].equals("*"))
              System.out.println(x*y);
          else if(num[1].equals("/"))
              System.out.println(x/y);
          else 
                    break;
            }
        }
    }

Measured memory_bytes: 24164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
ll Mod = 1000000007;

vector<p> pri(ll n) {
  vector<p> Pr;
  for (ll i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt != 0) {
      Pr.push_back(make_pair(i,cnt));
    }
  }
  if (n != 1) Pr.push_back(make_pair(n,1LL));
  return Pr;
}

int main() {
  ll N,P;
  cin >> N >> P;
  vector<p> S = pri(P);
  ll ans = 1;
  for (int i = 0; i < S.size(); i++) {
      for (int j = 0; j < S[i].second / N; j++) {
        ans *= S[i].first;
      }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256