akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t;  using i64 = int64_t;  using str = string;
using u32 = uint32_t; using u64 = uint64_t; using usize = size_t;
using f64 = double_t; template <typename T> using vec = vector<T>;
#define times(n, i) for (i64 i = 0; i < (n); ++i)
#define range(n, m, i) for (i64 i = (n); i < (m); ++i)
#define upto(n, m, i) for (i64 i = (n); i <= (m); ++i)
#define downto(n, m, i) for (i64 i = (n); i >= (m); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

str s;

i32 main()
{
    cin >> s;

    times(s.size()-1, i) {
        if (s[i] == s[i+1]) {
            cout << i+1 << ' ' << i+2 << endl;
            return 0;
        }
    }

    times(s.size()-2, i) {
        if (s[i] == s[i+2]) {
            cout << i+1 << ' ' << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << ' ' << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int k, n;
    cin >> n >> k;
    if(k == 1) cout << 0 << "\n";
    else cout << n-k << "\n";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
dist = []
for a in A:
    if dist and dist[-1] == a:
        continue
    dist.append(a)
ans = 0
next = 0
for i in range(1, len(dist)-1):
    if (dist[i-1] < dist[i]) == (dist[i] > dist[i+1]) and i != next:
        next = i + 1
        ans += 1
print(ans + 1)

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n,0);
    for(ll i = 0;i < n;++i)cin >> a[i];
    for(ll i = k;i < n;++i){
        cout << (a[i] > a[i - k] ? "Yes" : "No") << endl;
    }
}




Measured memory_bytes: 4408
def main():
    a, b, c, d = map(int, input().split())
    distance = [a, b, c]
    a_c_distance = [a, c]
    a_c_distance.sort()
    if a_c_distance[1] - a_c_distance[0] <= d:
        print('Yes')
        return
    distance.sort()
    if distance[2] - distance[1] <= d and distance[1] - distance[0] <= d:
        print('Yes')
    else:
        print('No')
    
main()

Measured memory_bytes: 9100
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 2005; 
using namespace std; 

int n, m, a[N][N], up[N][N], stk[N], top, f[N][N], g[N][N], ans; 
char s[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> (), m = read <int> (); 
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", s + 1); 
		for(int j = 1; j <= m; j++) a[i][j] = s[j] == '.'; 
	}
	n--, m--; 
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) a[i][j] ^= a[i][j + 1] ^ a[i + 1][j] ^ a[i + 1][j + 1]; 
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			if(i == 1) up[i][j] = a[i][j] == 0;
			else up[i][j] = (a[i][j] == 0 ? up[i - 1][j] + 1 : 0); 
		}
	for(int i = 1; i <= n; i++)
		for(int k, j = 1; j <= m; j = k)
		{
			if(a[i][j]) { k = j + 1; continue; }
			k = j, top = 0; 
			while(k <= m && !a[i][k]) k++; 
			for(int l = j; l < k; l++)
			{
				while(top && up[i][stk[top]] >= up[i][l]) top--; 
				f[i][l] = top ? stk[top] + 1 : j, stk[++top] = l; 
			}
			top = 0;
			for(int l = k - 1; l >= j; l--)
			{
				while(top && up[i][stk[top]] >= up[i][l]) top--; 
				g[i][l] = top ? stk[top] - 1 : k - 1, stk[++top] = l; 
			}
		}
	ans = max(n, m) + 1; 
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(!a[i][j]) ans = max(ans, (up[i][j] + 1) * (g[i][j] - f[i][j] + 2));
	printf("%d\n", ans); 
	return 0; 
}


Measured memory_bytes: 66496
import sys
input = sys.stdin.readline


class BIT:
    def __init__(self, n):
        self.array = [0] * (n + 1)
        self.size = n

    def sum(self, i):
        s = 0
        tmp = i
        while tmp > 0:
            s += self.array[tmp]
            tmp -= tmp & -tmp
        return s

    def add(self, i, x):
        tmp = i + 1
        while tmp <= self.size:
            self.array[tmp] += x
            tmp += tmp & -tmp


def main():
    n, q = map(int, input().split())
    *C, = map(lambda x: int(x) - 1, input().split())
    P = [0] * n
    N = [None] * n
    for i in range(n)[::-1]:
        if P[C[i]]:
            N[i] = P[C[i]]
        P[C[i]] = i
    F = [0] * n
    B = BIT(n)
    for i in range(n):
        if F[C[i]] == 0:
            B.add(i, 1)
            F[C[i]] = 1
    XY = [tuple(map(int, input().split())) for j in range(q)]
    ids = list(range(q))
    ids.sort(key=lambda j: XY[j][0])
    a = 0
    lst = [0] * q
    for j in ids:
        x, y = XY[j]
        for i in range(a, x - 1):
            if N[i]:
                B.add(N[i], 1)
        a = x - 1
        lst[j] = B.sum(y) - B.sum(x - 1)
    print(*lst, sep="\n")


main()


Measured memory_bytes: 233972
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int a,b,c,d;

int main(){
  cin>>a>>b>>c>>d;

  cout<<min(a,b)+min(c,d)<<endl;

  return 0;
}


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

using namespace std;

int main(){
  string S;

  cin >> S;
  int ans = 0;
  for(auto itr=S.begin();itr!=S.end();itr++){
    if(*itr == '+'){
      ans++;
    }else if(*itr == '-'){
      ans--;
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    ll n = s.size();
    vi cnt(3, 0), req(3, (ll)(n/3));
    rep(i, n) cnt[(ll)(s[i]-'a')]++;
    sort(all(cnt));
    n %= 3;
    for(ll i=0; i<n; i++) req[2-i]++;
    bool ans = true;
    rep(i, 3) if(req[i] != cnt[i]) ans = false;
    ans ? YES() : NO();
}

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

typedef long long ll;

ll X, K;
typedef tuple<ll, ll, ll, ll> State;
map<ll, State> States;
vector<ll> R;
ll Q;

void simulate() {
  State state = make_tuple(0, 0, X, X);
  ll gravity = -1;
  ll t = 0;
  for (ll i = 0; i < R.size(); ++i) {
    if (gravity == -1) {
      ll t1 = min(t + get<1>(state), R[i]);
      get<1>(state) -= t1 - t;
      get<3>(state) -= t1 - t;
      States[t1] = state;
      t = t1;
      ll t2 = min(t + get<3>(state), R[i]);
      get<0>(state) += t2 - t;
      get<3>(state) -= t2 - t;
      States[t2] = state;
      t = t2;
      States[R[i]] = state;
      t = R[i];
    } else {
      ll t1 = min(t + X - get<3>(state), R[i]);
      get<3>(state) += t1 - t;
      get<1>(state) += t1 - t;
      States[t1] = state;
      t = t1;
      ll t2 = min(t + X - get<1>(state), R[i]);
      get<2>(state) -= t2 - t;
      get<1>(state) += t2 - t;
      States[t2] = state;
      t = t2;
      States[R[i]] = state;
      t = R[i];
    }
    gravity *= -1;
  }
}
ll interpolate(ll us[2], ll ps[2], ll t) {
  return ps[0] + (ps[1] - ps[0]) / (us[1] - us[0]) * (t - us[0]);
}
State interpolate(pair<ll, State> ustates[2], ll t) {
  ll us[2], ps[4][2], qs[4];
  for (ll i : {0, 1}) {
    us[i] = ustates[i].first;
    tie(ps[0][i], ps[1][i], ps[2][i], ps[3][i]) = ustates[i].second;
  }
  assert(us[0] <= t && t <= us[1]);
  for (ll j : {0, 1, 2, 3}) qs[j] = interpolate(us, ps[j], t);
  return make_tuple(qs[0], qs[1], qs[2], qs[3]);
}
int main() {
  cin >> X >> K;
  for (ll i = 0; i < K; ++i) {
    ll r;
    cin >> r;
    R.push_back(r);
  }
  R.push_back(1e9 + 1);
  simulate();
  cin >> Q;
  for (ll i = 0; i < Q; ++i) {
    ll t, a;
    cin >> t >> a;
    auto to = States.upper_bound(t);
    auto from = prev(to);
    pair<ll, State> ustates[2] = {*from, *to};
    auto state = interpolate(ustates, t);
    ll x0, y0, x1, y1;
    tie(x0, y0, x1, y1) = state;
    cout << (a <= x0 ? y0 : x1 <= a ? y1 : (a - x0) + y0) << endl;
  }
  return 0;
}


Measured memory_bytes: 16884
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R  = sc.nextInt();
        if (R < 1200){
            System.out.println("ABC");
        }
        else if (1200 <= R && R < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }

}


Measured memory_bytes: 21716
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,a,b = map(int,ipt().split())
    if a*b < n or a+b-1 > n:
        print(-1)
        exit()
    ans = [str(b-i) for i in range(b)]
    si = n-a+2
    ue = n+1
    i = 0
    while True:
        if si <= b or a == 1:
            break
        ans[i] += " "+" ".join(map(str,range(si,ue)))
        ue = si
        si -= a-1
        i += 1
    if i < b and b+1 < ue:
        ans[i] += " "+" ".join(map(str,range(b+1,ue)))
    print(" ".join(ans))
    return

if __name__ == '__main__':
    main()


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = min(a,b) + min(c,d);
    cout << ans << endl;

    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>;
 
 
int main() {
     int N,T;
    cin >> N >> T;
    vector<int>c(N);
    vector<int>t(N);
    int a=30000;
    rep(i,N){
        cin >> c.at(i) >> t.at(i);
        if(t.at(i)<=T){
            a=min(a,c.at(i));
        }
    }
    if(a==30000)cout << "TLE" << endl;
    else {
    cout << a << endl;}
 
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main() {
    int n, m;
    int a[51], b[51];
    int c[51], d[51];
    int min[51];
    int ans[51];
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        min[i] = 2000000000;
    }
    for(int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    int ch[n][m];

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            ch[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(ch[i][j] < min[i]) {
              min[i] = ch[i][j];
              ans[i] = j + 1;
            }
        }
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    int n, m, c, ans=0;
    R n >> m >> c;
    int B[m];
    rep(i, m)R B[i];
    rep(i, n){
        int ret = c;
        rep(j, m){
            int a;
            R a;
            ret += B[j] * a;
        }
        if(ret > 0)ans += 1;
    }
    co(ans);
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

template<int N=1000001>
struct UnionFindTree {
  LL cnt;
  A<LL, N> uftq{}, s{}, rank{};

  UnionFindTree() {
    cnt = N;
    FOR(i,0,N) { uftq[i] = i; s[i] = 1; rank[i] = 1; }
  }
  UnionFindTree(LL n) : cnt(n) {
    FOR(i,0,n) { uftq[i] = i; s[i] = 1; rank[i] = 1; }
  }
  LL find(LL x) {
      LL xParent = uftq[x];
      V<LL> v;
      while(xParent != uftq[xParent]) {
          v.push_back(xParent);
          xParent = uftq[xParent];
      }
      REP(i, v.size()) {
          uftq[v[i]] = xParent;
      }
      return xParent;
  }
  bool unite(LL x, LL y) {
      LL xRoot = find(x), yRoot = find(y);
      if(xRoot == yRoot) return false;
      if(rank[xRoot] > rank[yRoot])
          std::swap(xRoot, yRoot);
      if(rank[xRoot] == rank[yRoot])
          rank[yRoot] += 1 + rank[yRoot] - rank[xRoot];
      s[yRoot] = s[xRoot] + s[yRoot];
      s[xRoot] = 0;
      uftq[xRoot] = yRoot;
      cnt--;
      return true;
  }
  LL size(LL idx) { return s[find(idx)]; }
  LL count() { return cnt; }
};

LL N;
int xt[100001];
int yt[100001];
set<int> xs[100001], ys[100001];
map<int,int> xm, ym;
UnionFindTree<1000000> uft;

int main(){
    INIT;
    cin >> N; 
    REP(i,N) {
        cin >> xt[i] >> yt[i];
        if(xm.count(xt[i])) 
            uft.unite((LL)i,(LL)xm[xt[i]]);
        xm[xt[i]] = i;
        if(ym.count(yt[i])) 
            uft.unite((LL)i,(LL)ym[yt[i]]);
        ym[yt[i]] = i;
    }
    REP(i,N) {
        xs[uft.find((LL)i)].insert(xt[i]); 
        ys[uft.find((LL)i)].insert(yt[i]);
    }
    LL ans = 0;
    REP(i,N) ans += (LL)xs[i].size()*ys[i].size();
    cout << ans-N;
}

Measured memory_bytes: 43264
import re

N = int(input())
S = input()

res = 0
fmt = "[0-9]*{}[0-9]*{}[0-9]*{}[0-9]*"
for i in range(10):
  idx_1 = S.find(str(i))
  if (idx_1 == -1) or (idx_1 > N-3):
    continue
  for j in range(10):
    idx_2 = S[idx_1+1:].find(str(j))
    if (idx_2 == -1) or (idx_2 > N-2):
      continue
    for k in range(10):
      idx_3 = S[idx_1+1+idx_2+1:].find(str(k))
      if idx_3 != -1:
        res += 1

print(res)


Measured memory_bytes: 3316
class UnionFind:
    def __init__(self, elems):
        self.parent = dict()
        self.children = dict()
        for e in elems:
            self.parent[e] = e
            self.children[e] = 1

    def root(self, e):
        if self.parent[e] == e:
            return e

        return self.root(self.parent[e])

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

    def unite(self, x, y):
        if self.same(x, y):
            return

        rx, ry = self.root(x), self.root(y)
        # ry <- rx
        if self.members(ry) < self.members(rx):
            rx, ry = ry, rx

        self.children[ry] += self.children[rx]
        self.parent[rx] = ry

    def members(self, x):
        return self.children[self.root(x)]


n, m = map(int, input().split())
bs = []
for _ in range(m):
    bs.append(tuple(map(int, input().split())))

bs.reverse()

uf = UnionFind(list(range(1, n+1)))

inconv = n * (n - 1) // 2
inconvs = [inconv]
for b in bs[:-1]:
    i1, i2 = b
    if not uf.same(i1, i2):
        inconv -= uf.members(i1) * uf.members(i2)

    inconvs.append(inconv)
    uf.unite(i1, i2)

for inc in reversed(inconvs):
    print(inc)

Measured memory_bytes: 37880
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r; //現在のレーティング
  int p; //パフォーマンス
  int g; //レーティング
  
  cin >> r >> g ;
  p =  ( 2 * g ) - r;
  cout << p << endl;
}

Measured memory_bytes: 3620
import java.util.*;

class Main{
    public static void main(String argv[]){
        Scanner sc = new Scanner(System.in);
        while(true) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if(n == 0 && m == 0)break;
            int len[][] = new int[m][m];
            int cost[][] = new int[m][m];

            for(int i = 0; i < m; i++){
                for(int j = 0; j < m; j++){
                    len[i][j]=1<<28;
                    cost[i][j]=1<<28;
                }
                len[i][i] = 0;
                cost[i][i] = 0;
            }
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;
                int c = sc.nextInt();
                int t = sc.nextInt();
                len[a][b] = len[b][a] = Math.min(len[a][b], t);
                cost[a][b] = cost[b][a] = Math.min(cost[a][b], c);
            }
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < m; j++) {
                    for (int k = 0; k < m; k++) {
                        len[j][k] = Math.min(len[j][k], len[j][i] + len[i][k]);
                        len[k][j] = len[j][k];
                        cost[j][k] = Math.min(cost[j][k], cost[j][i] + cost[i][k]);
                        cost[k][j] = cost[j][k];
                    }
                }
            }
            int l = sc.nextInt();
            for (int i = 0; i < l; i++) {
                int p = sc.nextInt() - 1;
                int q = sc.nextInt() - 1;
                int r = sc.nextInt();
                if (r == 0) {
                    System.out.println(cost[p][q]);
                } else {
                    System.out.println(len[p][q]);
                }
            }
        }
    }
}

Measured memory_bytes: 79956
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  a, v = I()
  b, w = I()
  t = int(input())
  if v <= w:
    print('NO')
  else:
    if abs(a-b) / (v-w) <= t:
      print('YES')
    else:
      print('NO')

if __name__ == '__main__':
  main()

Measured memory_bytes: 9192
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		String ab = "";
		String ba = "";

		for (int i = 0; i < b; i++) {
			ab += a;
		}
		for (int i = 0; i < a; i++) {
			ba += b;
		}

		if (a <= b) {
			System.out.println(ab);
		} else if (b < a) {
			System.out.println(ba);
		}

		sc.close();
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
#include <ctype.h>
#include <string>
typedef long long ll;
using namespace std;

int main(){
  string n,a;
  cin>>n>>a;
  int b=n.size();
  rep(i,b){
    
  if(n[i]!=a[i]){
    cout<<"No";
    break;
  }
  if(i==b-1)  cout<<"Yes";
  }
  
}

Measured memory_bytes: 3596
n = gets.to_i
h = Hash.new(0)
n.times do
  s = gets
  h[s[0]] += 1
end
ans = 0
ans += h['M'] * h['A'] * h['R']
ans += h['M'] * h['A'] * h['C']
ans += h['M'] * h['A'] * h['H']
ans += h['M'] * h['R'] * h['C']
ans += h['M'] * h['R'] * h['H']
ans += h['M'] * h['C'] * h['H']
ans += h['A'] * h['R'] * h['C']
ans += h['A'] * h['R'] * h['H']
ans += h['A'] * h['C'] * h['H']
ans += h['R'] * h['C'] * h['H']
puts ans

Measured memory_bytes: 3836
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Array.Sort(P);
		Array.Sort(Q);
		Array.Sort(R);
		Array.Reverse(R);
		
		var p = new SkewHeap<long>();
		var q = new SkewHeap<long>();
		long tot = 0;
		for(int i=0;i<X;i++){
			tot += P[P.Length - 1 - i];
			p.Push(P[P.Length - 1 - i]);
		}
		for(int i=0;i<Y;i++){
			tot += Q[Q.Length - 1 - i];
			q.Push(Q[Q.Length - 1 - i]);
		}
		
		for(int i=0;i<C;i++){
			if(p.Count == 0 && q.Count == 0) break;
			
			long gain = -1;
			int idx = -1;
			if(p.Count > 0){
				if(R[i] > p.Top){
					if(gain < R[i] - p.Top){
						gain = R[i] - p.Top;
						idx = 0;
					}
				}
			}
			if(q.Count > 0){
				if(R[i] > q.Top){
					if(gain < R[i] - q.Top){
						gain = R[i] - q.Top;
						idx = 1;
					}
				}
			}
			
			if(idx == 0){
				tot -= p.Top;
				p.Pop();
				tot += R[i];
			}
			if(idx == 1){
				tot -= q.Top;
				q.Pop();
				tot += R[i];
			}
		}
		
		Console.WriteLine(tot);
		
	}
	int X,Y,A,B,C;
	long[] P,Q,R;
	public Sol(){
		var d = ria();
		X = d[0]; Y = d[1]; A = d[2]; B = d[3]; C = d[4];
		P = rla();
		Q = rla();
		R = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}



class SkewHeap<T> where T:IComparable<T>{
	public int Count{
		get{return cnt;}
		private set{cnt=value;}
	}
	
	public SkewHeap(){
		root=null;
		this.Count=0;
	}
	
	public void Push(T v){
		NodeSH<T> p=new NodeSH<T>(v);
		root=NodeSH<T>.Meld(root,p);
		this.Count++;
	}
	
	public void Pop(){
		if(root==null)return;
		root=NodeSH<T>.Meld(root.L,root.R);
		this.Count--;
	}
	
	public T Top{
		get{return root.Val;}
	}
	
	int cnt;
	NodeSH<T> root;
	
	class NodeSH<S> where S : IComparable<S> {
		public NodeSH<S> L, R;
		public S Val;

		public NodeSH(S v){
			Val = v;
			L = null; R = null;
		}
		public static NodeSH<S> Meld(NodeSH<S> a, NodeSH<S> b){
			if(a == null)return b;
			if (b == null) return a;
			if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b);
			a.R = Meld(a.R, b);
			swap(ref a.L, ref a.R);
			return a;
		}

		static void swap<U>(ref U x, ref U y) {
			U t = x; x = y; y = t;
		}
	}
}



Measured memory_bytes: 42260
#include<stdio.h>

int mtod(int y,int m){
  if(y%3==0){
    return 20;
  }
  else if(m%2==1){
    return 20;
  }
  else{
    return 19;
  }
}

int ytod(int y){
  if(y%3==0){
    return 200;
  }
  else{
    return 195;
  }
}

int dtod(int y,int m,int d){
  int md=mtod(y,m);
  int yd=ytod(y);
  int i;
  int cnt=0;
  for(i=1;i<y;i++){
    cnt+=ytod(i);
  }
  for(i=1;i<m;i++){
    cnt+=mtod(y,i);
  }
  return cnt+d-1;
}

void doit(){
  int y,m,d;
  int ans;
  scanf("%d %d %d",&y,&m,&d);
  ans=dtod(1000,1,1)-dtod(y,m,d);
  printf("%d\n",ans);
}

int main(){
  int n;
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    doit();
  }
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int main(void){
	int W, a, b, tmp,d;

	scanf("%d %d %d", &W, &a, &b);

	if(b<a){
		tmp = b;
		b = a;
		a = tmp;
	}

	d = b - (a + W);

	if(d <= 0 && d >= -W)
		d = 0;

	printf("%d\n", d);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define MAX (int)1e5

int C(const void* a,const void* b){
  return *(int*)b-*(int*)a;
}

int main(){
  int n,m,a[MAX],b[MAX],i;
  scanf("%d%d",&n,&m);
  if(n>=m){
    printf("0");
    return 0;
  }
  for(i=0;i<m;i++){
    scanf("%d",a+i);
  }
  qsort(a,m,sizeof(int),C);
  for(i=0;i<m-1;i++){
    b[i]=a[i]-a[i+1];
  }
  qsort(b,m-1,sizeof(int),C);
  int ans=a[0]-a[m-1];
  for(i=0;i<n-1;i++){
    ans-=b[i];
  }
  printf("%d",ans);

}


Measured memory_bytes: 1268
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var jobs = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).OrderBy(x => x[1]).ToArray();
        long curTime = 0;
        foreach (var job in jobs)
        {
            curTime += job[0];
            if (job[1] < curTime)
            {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}



Measured memory_bytes: 37060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
  int n, k, x;
  int num = 0;
  scanf("%d %d", &n, &k);
  REP(i, n){
    scanf("%d", &x);
    if (x >= k) num++;
  }
  printf("%d\n", num);
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;

long long int N;
int main (){
    cin >> N;
    long long int ans = 0;
    for(long long int i=1; i*i+i<N; i++) {
        if( (N - i) % i == 0 ) {
            ans += (N - i) / i;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int popcount(int x){
	return __builtin_popcount(x);
}

int f(int x){
	int nop = 0;
	while (x > 0){
		x %= popcount(x);
		nop++;
	}
	return nop;
}

int main(void){
	int N;
	string X;
	cin >> N >> X;
	int a[N];
	rep(i,N) a[i] = X[i] - '0';

	int pop0 = 0;
	rep(i,N) pop0 += a[i];

	int ans[N];
	rep(i,N) ans[i] = 0;

	rep(i,2) {
		int pop;
		if (i == 1) pop = pop0 - 1;
		else pop = pop0 + 1;

		if (pop <= 0) continue;

		int mod0 = 0;

		rep(j,N){
			mod0 = (mod0*2)%pop;
			mod0 += a[j];
		}		

		int k = 1;
		for (int j = N-1; j >=0; j--) {
			if (a[j] == i){
				int x = mod0;
				if (a[j] == 1) x = (x-k+pop)%pop;
				else x = (x+k)%pop;
				ans[j] = f(x) + 1;
			}
			k = (2*k)%pop;
		}
	}

	rep(i,N) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 5324
#include<stdio.h>

int main(void){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);

  if(A==5 && B==5 && C==7 || A==5 && B==7 && C==5 || A==7 && B==5 && C==5){
    puts("YES");
  }else{
    puts("NO");
  }
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<vector>
#include<queue>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#define INF 1000000000
#define MAXN 100005
#define sf(n) scanf("%d",&n)
#define sff(m,n) scanf("%d%d",&m,&n)
#define gl(x) getline(cin,x)
#define gc() getchar()
using namespace std;
int a[15][10005];
int main()
{
    while(1){
    int n,m;sff(n,m);
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            sf(a[i][j]);
    int mmax=0;
    for(int i=0;i<pow(2,n);i++)
    {
        int b[10];int r=i;
        for(int j=0;j<n;j++)
        {
            b[j]=r%2;r/=2;
        }
        int sum=0;
        for(int j=0;j<m;j++)
        {
            int k=0;
            for(int u=0;u<n;u++){
                //cout<<a[u][j]<<"  "<<b[u]<<endl;
                if((a[u][j]&&!b[u])||((!a[u][j])&&b[u]))k++;
            }
            //cout<<k<<"??"<<endl;
            sum+=max(k,n-k);
        }
        //cout<<i<<"  "<<sum<<endl;
        mmax=max(mmax,sum);
    }
    printf("%d\n",mmax);
    }
}



Measured memory_bytes: 3724
#include<stdio.h>
#include<map>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>

using namespace std;

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

const int MX = 205;
const int MM = 998244353;

int N;
pii D[MX];

pii operator-(const pii &l, const pii &r){
	return pii(l.first - r.first, l.second - r.second);
}

ll operator /(const pii &l, const pii &r){
	return (ll)l.first * r.second - (ll)l.second * r.first;
}

ll pw2[MX];

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d%d", &D[i].first, &D[i].second);
	}
	ll ans = 1;
	pw2[0] = 1;
	for(int i = 1; i <= N; i++) pw2[i] = pw2[i-1]*2 % MM;
	ans = pw2[N];
	ans = (ans - N*(N-1)/2 - N - 1) % MM;
	ans = (ans + MM) % MM;

	int vst[MX][MX] = {};
	for(int i = 1; i <= N; i++){
		for(int j = i+1; j <= N; j++){
			if( vst[i][j] ) continue;
			vector<int> P;
			for(int k = 1; k <= N; k++){
				if( (D[i] - D[j]) / (D[i] - D[k]) == 0 ) P.push_back(k);
			}
			int sz = P.size();
			if( sz >= 3 ) ans = ((ans - pw2[sz] + sz*(sz-1)/2 + sz + 1) % MM + MM) % MM;
			for(int c : P){
				for(int d : P) vst[c][d] = 1;
			}
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 384
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N, K = map(int, readline().split())

answer = N % K
while True:
    new = abs(answer - K)
    if new > answer:
        break
    answer = new
print(answer)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std; 
typedef unsigned int uint; typedef long long ll;
typedef unsigned long long ull; typedef pair<int, int> pii;
typedef pair<ll,ll> pll; typedef long double ld;
void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0);}
template<typename T> T __lcm(T a, T b){return (a*b)/__gcd(a,b);}
template<typename T> T fpow(T a, T b, T p) {
	a %= p; T res = 1; while (b > 0) { 
	if (b & 1) res = res * a % p;
	a = a * a % p; b >>= 1;} return res;}
template<typename T> T binpow(T a, T b) {
		T res = 1; while (b > 0) {if (b & 1) res = res * a;
		a = a * a; b >>= 1;} return res;}
const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1e5;

int n, k;
int a[maxn], dp[maxn];
int main() {
	rii(n, k);
	forn(i, n) ri(a[i]);
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	forr(i, 2, n){
		dp[i] = dp[i-1]+ abs(a[i]-a[i-1]);
		for(int j = i-1; j>=max(0,i-k); j--)
			dp[i] = min(dp[i], dp[j] + abs(a[i]-a[j]));
	}
	printf("%d\n", dp[n-1]);
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <bitset>
#include <queue>
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define pb push_back
#define mo 974711
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define MAXN 200005
#define eps 1e-12
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 - '0' + c;
	c = getchar();
    }
    res = res * f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N,M,I,P,Q;
struct node {
    int next,to;
}E[MAXN * 2];
int head[MAXN],sumE,col[MAXN];
bool vis[MAXN];
void dfs(int u) {
    vis[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(!vis[v]) {
	    dfs(v);
	}
    }
}
bool paint(int u) {
    if(!col[u]) col[u] = 2;
    for(int i = head[u] ; i; i = E[i].next) {
	int v = E[i].to;
	if(!col[v]) {col[v] = col[u] ^ 1;if(!paint(v)) return false;}
	else if(col[v] == col[u]) return false;
    }
    return true;
}
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void Solve() {
    read(N);read(M);
    int u,v;
    for(int i = 1 ; i <= M ; ++i) {
	read(u);read(v);
	add(u,v);add(v,u);
    }
    for(int i = 1 ; i <= N ; ++i) {
	if(!head[i]) ++I;
	else if(!vis[i]){
	    dfs(i);
	    if(paint(i)) ++Q;
	    else ++P;
	}
    }
    int64 ans = 1LL * I * I + 2LL * I * (N - I);
    ans += 1LL * P * P + 2LL * P * Q + 2LL * Q * Q;
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 5248
a=input()
if a=="SUN":
  print("7")
if a=="MON":
  print("6")
if a=="TUE":
  print("5")
if a=="WED":
  print("4")
if a=="THU":
  print("3")
if a=="FRI":
  print("2")
if a=="SAT":
  print("1")
  

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

const int MAX = 2100;
bool G[MAX][MAX];
int N, M;

bool isbipartite = true; // false になったら二部グラフでない
int dir[MAX]; // 各ノードをとりあえず左右どちらにしているか (左: 0、右: 1)
int tmpnums[2];

void dfs(int v, int tdir) {
    dir[v] = tdir;
    tmpnums[tdir]++;
    for (int e = 0; e < N; ++e) {
        if (e == v || !G[v][e]) continue;
        if (dir[e] == -1) dfs(e, 1 - tdir);
        else if (dir[e] != 1 - tdir) isbipartite = false;
    }
}

int main() {
    cin >> N >> M;
	for (int i = 0; i < MAX; ++i) for (int j = 0; j < MAX; ++j) G[i][j] = 1;
	for (int i = 0; i < M; ++i) {
	  int a, b;
	  cin >> a >> b; --a, --b;
	  G[a][b] = G[b][a] = 0;
	}
	
    // 二部グラフの構成
	vector<pair<int,int> > nums;
	for (int i = 0; i < MAX; ++i) dir[i] = -1;
	for (int v = 0; v < N; ++v) {
        if (dir[v] != -1) continue;
        tmpnums[0] = tmpnums[1] = 0;
        dfs(v, 0);
        nums.push_back(make_pair(tmpnums[0], tmpnums[1]));
	}

    // そもそも二部グラフじゃなかったらダメ
    if (!isbipartite) {
        cout << -1 << endl;
        return 0;
    }

    // ナップサック DP
    bool dp[MAX] = {0};
    dp[0] = 1;
    for (int i = 0; i < (int)nums.size(); ++i) {
        for (int j = N; j >= 0; --j) {
            if (!dp[j]) continue;
            dp[j] = 0;
            dp[j + nums[i].first] = 1;
            dp[j + nums[i].second] = 1;
        }
    }

    long long a = -1;
    long long mindif = N;
    for (int i = 0; i <= N; ++i) {
        if (!dp[i]) continue;
        if (mindif > abs(i - N/2)) mindif = abs(i - N/2), a = i;
    }
    long long b = N-a;
    cout << a*(a-1)/2 + b*(b-1)/2 << endl;
}

Measured memory_bytes: 4608
import java.util.Scanner;

public class Main{
static int n;
static int[] check;//checked ->1,yet-> 0checking->2
static int[][] m;
final static int MAX=100; 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
     int i,j,k,u,v;
     Scanner sca=new Scanner(System.in);
     m=new int[MAX][MAX];
     n=sca.nextInt();
     for(i=0;i<n;i++){
    	 for(j=0;j<n;j++){
    		 m[i][j]=-1;
    	 }
     }
     for(i=0;i<n;i++){
    	 u=sca.nextInt();
    	 k=sca.nextInt();
    	 for(j=0;j<k;j++){
    		 v=sca.nextInt();
    		 m[u][v]=sca.nextInt();
    	 }
     }
     dijkstra();
	}
	public static void dijkstra(){
		int i,u,min;
		int d[]= new int[MAX];
		check=new int[MAX];
		for(i=0;i<n;i++){
			d[i]=Integer.MAX_VALUE;
		}
		d[0]=0;
		check[0]=2;
		while(true){
			min=Integer.MAX_VALUE;
			u=-1;
			for(i=0;i<n;i++){
				if(min>d[i]&&check[i]!=1){
					u=i;
					min=d[i];
				}
			}
			if(u==-1)break;//finished
			check[u]=1;
			for(i=0;i<n;i++){
				if(check[i]!=1&&m[u][i]!=-1){
					if(d[i]>m[u][i]+d[u]){
						d[i]=m[u][i]+d[u];
						check[i]=2;
					}
				}
			}
		}
		for(i=0;i<n;i++){
			if(d[i]==Integer.MAX_VALUE)d[i]=-1;
			System.out.println(i+" "+d[i]);
		}
	}
}



Measured memory_bytes: 40648
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    string s;
    cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3620
h, w, k = map(int, input().split())
s = [list(input()) for i in range(h)]
sikaku = [[0 for _ in range(w)] for _ in range(h)]
tmp = 0
key = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if tmp == 0:
                tmp = key
            tmp += 1

        elif j == 0:
            if tmp != 0:
                key = tmp
            tmp = 0

        sikaku[i][j] = tmp

for i in range(h - 1, -1, -1):
    for j in range(w - 2, -1, -1):
        if sikaku[i][j] == 0:
            sikaku[i][j] = sikaku[i][j + 1]

for i in range(1, h):
    if sikaku[i][-1] == 0:
        for j in range(w):
            sikaku[i][j] = sikaku[i - 1][j]

for i in range(h - 2, -1, -1):
    if sikaku[i][-1] == 0:
        for j in range(w):
            sikaku[i][j] = sikaku[i + 1][j]

for i in range(h):
    for j in range(w):
        print(sikaku[i][j], end = " ")
    print()

Measured memory_bytes: 54616
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int x;
    cin >> x;
    int ans = 0;
    ans += x / 500 * 1000;
    x -= ans / 1000 * 500;
    ans += (x - x % 5);
    cout << ans << endl;
}


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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,a,b;
	cin >> n;
	if (n == 2) {
		cin >> a >> b;
	}
	if (n == 1) cout << "Hello World" << endl;
	else cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main p = new Main();
		int n;
		Team t;
		ArrayList<Team> at;


		while(true){
			n = sc.nextInt();
			at = new ArrayList<Main.Team>();

			if(n == 0){
				break;
			}

			for(int i=0;i<n;i++){
				t = p.new Team();
				t.id = sc.nextInt();
				t.school = sc.nextInt();
				t.solve = sc.nextInt();
				t.wa = sc.nextInt();
				at.add(t);
			}

			Collections.sort(at, new Comparator<Main.Team>() {
				public int compare(Team t1, Team t2){
					String t1str = String.format("$1%2s$2%6s$3%4s", t1.solve,100000-t1.wa,1000-t1.id);
					String t2str = String.format("$1%2s$2%6s$3%4s", t2.solve,100000-t2.wa,1000-t2.id);
					return t2str.compareTo(t1str);
				}
			});

			HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
			int count=0;
			while(!at.isEmpty()){
				if(hm.get(at.get(0).school) == null){
					hm.put(at.get(0).school,1);
					System.out.println(at.get(0).id);
					at.remove(0);
					count++;
				}else{
					switch(hm.get(at.get(0).school)){
					case 1:
						if(count < 20){
							hm.put(at.get(0).school,2);
							System.out.println(at.get(0).id);
							at.remove(0);
							count++;
						}else{
							at.remove(0);
						}
						break;
					case 2:
						if(count < 10){
							hm.put(at.get(0).school,3);
							System.out.println(at.get(0).id);
							at.remove(0);
							count++;
						}else{
							at.remove(0);
						}
						break;
					case 3:
						at.remove(0);
					}
				}
				if(count == 26){
					break;
				}
			}
		}
	}


	public class Team{
		public int id;
		public int school;
		public int solve;
		public int wa;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	while (cin >> n && n) {
		long t, f, a;
		t = f = 0;
		for (int i = 1; i <= n; i++) {
			a = i;
			while ( a % 2 == 0 || a % 5 == 0 ) {
				if (a % 2 == 0) {
					t++;
					a /= 2;
				}
				if (a % 5 == 0) {
					f++;
					a /= 5;
				}
			}
		}
		cout << min(t, f) << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
(n, m, q) = map(int, input().split(" "))

ns = [[0 for _ in range(n + 1)]for _ in range(n + 1)]

for i in range(m):
    (l, r) = map(int, input().split(" "))
    ns[l][r] += 1

for i in range(1, n + 1):
    for j in range(i, n + 1):
        ns[i][j] += ns[i][j - 1]
for j in range(1, n + 1):
    for i in range(1, j + 1):
        ns[i][j] += ns[i - 1][j]

for i in range(q):
    count = 0
    (l, r) = map(int, input().split(" "))
    print(ns[r][r] - ns[l - 1][r])

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
string s;
vector<int> v;
int ans = 0;

int d[500005], e[500005], f[500005];

void solve() {
//    for (int x : v) cerr << x << ' ';
//    cerr << endl;
    int n = (int)v.size();
    forn(i, n + 1) d[i] = 0, e[i] = -12341234, f[i] = -12341234;
    forn(i, n) {
        d[i + 1] = max({d[i + 1], d[i], e[i], f[i]});
        if (i < n - 1) {
            e[i + 1] = max(e[i + 1], max(d[i], e[i] - 1) + v[i]);
            e[i + 1] = max(e[i + 1], f[i] + 1);
            d[i + 2] = max(d[i + 2], max(d[i], f[i]) + v[i + 1]);
            if (v[i] > 1) {
                d[i + 2] = max(d[i + 2], e[i] + v[i + 1]);
            }
            f[i + 1] = d[i + 2] - 1;
        }
    }
    ans += d[n];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> s;
    int space = 0;
    int cur = 0;
    forn(i, n) {
        if (s[i] == '1') {
            space = 0;
            ++cur;
        } else {
            if (++space == 2) {
                if (!v.empty()) {
                    solve();
                    v.clear();
                }
            } else if (space == 1 && cur > 0) {
                v.pb(cur);
                cur = 0;
            }
        }
    }
    if (cur > 0) {
        v.pb(cur);
    }
    if (!v.empty()) {
        solve();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2972