akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> Range;
typedef pair<Range, int> Info;
Info info[100000];
vector<int> G[100000];
int P[100000];
bool dfs(int v, int par) {
	int l = -1 << 30;
	int r = 1 << 30;
	int p = -1;
	for (int to : G[v]) {
		if (to == par) continue;
		if (!dfs(to, v)) return false;
		if (info[to].second != -1) {
			if (p == -1) {
				p = info[to].second ^ 1;
			}
			else if (p == info[to].second) {
				return false;
			}
			l = max(l, info[to].first.first - 1);
			r = min(r, info[to].first.second + 1);
		}
	}
	if (p == -1) {
		if (P[v] == -1) {
			info[v] = Info(Range(-1 << 30, 1 << 30), -1);
		}
		else {
			info[v] = Info(Range(P[v], P[v]), P[v] % 2);
		}
	}
	else {
		if (l > r || (l == r) && (abs(l) % 2 != p)) return false;
		if (P[v] == -1) {
			info[v] = Info(Range(l, r), p);
		}
		else if (l <= P[v] && P[v] <= r && P[v] % 2 == p) {
			info[v] = Info(Range(P[v], P[v]), P[v] % 2);
		}
		else {
			return false;
		}
	}
	return true;
}
void make(int v, int par) {
	if (par != -1) {
		if (info[v].second == -1) {
			P[v] = P[par] - 1;
		}
		else {
			int l = info[v].first.first, r = info[v].first.second, p = info[v].second;
			if (l <= (P[par] - 1) && (P[par] - 1) <= r && (P[par] - 1) % 2 == p) {
				P[v] = P[par] - 1;
			}
			else {
				P[v] = P[par] + 1;
			}
		}
	}
	for (int to : G[v]) {
		if (to == par) continue;
		make(to, v);
	}
}
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int A, B;
		cin >> A >> B; A--; B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	fill(P, P + N, -1);
	int K;
	cin >> K;
	int root = -1;
	for (int i = 0; i < K; i++) {
		int v, k;
		cin >> v >> k;
		v--;
		P[v] = k;
		root = v;
	}
	bool ok = dfs(root, -1);
	if (!ok) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	make(root, -1);
	for (int i = 0; i < N; i++) {
		cout << P[i] << endl;
	}
}


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

int main() {
  int n;
  cin >> n;
  string ans = "No";
  
  rep(i, 9) {
    rep(j, 9) {
      if((i+1) * (j+1) == n) {
        ans = "Yes";
        goto Fin;
      }
    }
  
  }
  
  Fin:
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

int main(){
  string x; cin >> x;
  int n = x.size();

  int ans = n;
  int cs = 0;
  rep(i, n){
    if(x[i] == 'S') cs++;
    if(x[i] == 'T'){
      if(cs > 0){
        cs--;
        ans -= 2;
      }
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 640
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

int64_t GreatestCommonDivisor(const int64_t a, const int64_t b) {
  // GCD. O(log(min(a, b))). 最大公約数.
  int64_t result = -1LL;
  if (a < 0) {
    std::cerr << "ERROR: GreatestCommonDivisor(): a is out of range: " << a << std::endl;
    throw 1;
  } else if (b < 0LL) {
    std::cerr << "ERROR: GreatestCommonDivisor(): b is out of range: " << b << std::endl;
    throw 1;
  } else if (a == 0LL) {
    result = b;
  } else if (b == 0LL) {
    result = a;
  } else {
    const int64_t new_a = std::min(a, b);
    const int64_t new_b = std::max(a, b) % new_a;  // Euclidean Algorithm
    result = GreatestCommonDivisor(new_a, new_b);
  }
  return result;
}

std::vector<std::pair<int64_t, int64_t>> FactorizeIntoPrimeFactors(const int64_t N) {
  std::vector<std::pair<int64_t, int64_t>> result;
  if (N <= 0LL || N == 1LL) {
    return result;
  }
  int64_t remaining = N;
  for (int64_t i = 2LL; i * i <= remaining; ++i) {
    int64_t count = 0LL;
    while (remaining % i == 0LL) {
      ++count;
      remaining /= i;
    }
    if (count > 0LL) {
      result.push_back(std::pair<int64_t, int64_t>(i, count));
    }
  }
  if (remaining > 1) {
    result.push_back(std::pair<int64_t, int64_t>(remaining, 1));
  }
  return result;
}

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

  int64_t A, B;
  cin >> A >> B;
  const int64_t gcd = GreatestCommonDivisor(A, B);
  vector<Pair> fs = FactorizeIntoPrimeFactors(gcd);
  int64_t result = 1;
  result += static_cast<int64_t>(fs.size());
  cout << result << endl;
  return 0;
}


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

public class Main {

  public static void main(String args[]) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String st = br.readLine();
    br.close();

    byte[] c = st.getBytes();
    c[0] = (byte) (c[0] + (byte) 1);

    System.out.println(new String(c));
  }
}


Measured memory_bytes: 20564
a, b, c = map(int,input().split())

if a + b + c == 17:
    if a == 5:
        if b == 5 or b == 7:
            print ("YES")
        else:
            print ("NO")
    elif a == 7:
        if b == 5:
            print ("YES")
        else:
            print ("NO")
    else:
        print ("NO")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define MAX 10000

int main(){
	int n,m,a;
	int x[MAX],index=0;
	scanf("%d%d",&n,&m);
	while(n!=0){
		a=n%m;
		n/=m;
		if(a<0){
			a=a-m;//注意负数余数转换的时候，余数-进制，被取数+1.
			n+=1;
			x[index++]=a;
		}
		else
			x[index++]=a;
	}
	cout<<index<<endl; 
	
	return 0;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<bool> used(26, false);
    REP(i, n) {
        used[s[i] - 'a'] = true;
    }

    if(s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << "-1" << endl;
        return 0;
    }

    if(n < 26) {
        REP(i, 26) {
            if(!used[i]) {
                cout << s << (char)('a' + i) << endl;
                return 0;
            }
        }
    }

    int nozoku = 0;
    bool find = false;
    REP_REV(i, n) {
        int idx = s[i] - 'a';
        REPN(j, idx+1, 26) {
            //cout << (char)('a'+j);
            if(!used[j]) {
                //cout << "aaaaaa" << endl;
                s[i] = 'a' + j;
                find = true;
                break;
            } 
        }
        if(find) break;
        //cout << endl;
        used[idx] = false;
        nozoku++;
    }

    cout << s.substr(0, n-nozoku) << endl;
    

    return 0;
}

Measured memory_bytes: 256
function main(lines) {
  let [a, b, c] = splitN(lines[0]);
  const K = +lines[1];

  for (let i = 0; i < K; i++) {
    if (a >= b) b *= 2;
    else if (b >= c) c *= 2;
  }
  
  return a < b && b < c ? 'Yes' : 'No';
}


const ans = main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );
console.log( ans );

function splitN(s) {
  return s.split(' ').map(Number);
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll r, g, b, n;
	cin >> r >> g >> b >> n;

	ll ret = 0;
	rep(i, n / r + 1) {
		ll remain = n - i * r;
		//debug(i);
		//debug(remain);

		rep(j, remain / g + 1) {
			//debug(j);
			//debug(remain - j * g);

			if( (remain - j * g) % b == 0 ) {
				//cerr << "(" << i << ", " << j << ", " << (n - (i * r) - (j * g)) / b << ")" << endl;
				++ret;
			}
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <type_traits>
#include <fstream>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// print(x, y, z);
// printVec(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << *it << " ";
    if ((it - begin) % 20 == 19 || it == end - 1) { std::cout << std::endl; }
  }
}
template<typename Iterator> void printVecPair(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << it->first << " " << it->second << " ";
    if ((it - begin) % 10 == 9 || it == end - 1) std::cout << std::endl;
  }
}

template<typename T> T bitnum(T x)
{
  T cnt = 1;
  T ret = 0;
  while (x > 0) {
    ret += (x % 2) * cnt;
    x /= 2;
    cnt *= 10;
  }
  return ret;
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll A, B, K;
  std::cin >> A >> B >> K;

  std::vector<ll> vans;
  
  ll ans = INF;
  ll cnt = 0;
  for (ll i = 1; i <= std::min(A, B); i++) {
    if (A % i == 0 && B % i == 0) vans.push_back(i);
  }

  print(vans[vans.size() - K]);
  return 0;
}


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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


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

    map<ll, int> m;
    rep(i, n) {
        ll a;
        cin >> a;
        m[a]++;
    }

    vector<ll> c;
    for (auto e : m) {
        if (e.second >= 4) c.push_back(e.first);
        if (e.second >= 2) c.push_back(e.first);
    }

    sort(c.rbegin(), c.rend());

    if (c.size() < 2) {
        cout << 0 << endl;
    } else {
        cout << c[0] * c[1] << endl;
    }


}



Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,T;
    cin >>N>>T;
    //vector<Pi> ct(N);
    ll ans = INF;
    rep(i,N){
        ll c,t;
        cin>>c>>t;
        //ct[i]=mp(c,t);
        if(t<=T){
            chmin(ans,c);
        }
    }

    
    if(ans == INF){
        cout<<"TLE"<<endl;
    }else{
        cout << ans << endl;
    }
    


    return 0;
    

}

Measured memory_bytes: 3600
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto s = readln.chomp.to!ulong;
    bool[1000000] memo;
    foreach (i; 0..1000000) {
        memo[s] = true;
        auto a = s & 1 ? (3*s+1) : (s/2);
        if (memo[a]) {
            writeln(i+2);
            return;
        }
        s = a;
    }
}



Measured memory_bytes: 1276
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n, k, s; cin >> n >> k >> s;
		if (n == 0) break;
		vector< vector<int> > dp(k + 1, vector<int>(s + 1));
		dp[0][0] = 1;
		for (int i = 1; i <= n; i++)
			for (int j = k; j >= 1; j--)
				for (int l = s; l >= i; l--)
					dp[j][l] += dp[j - 1][l - i];
		cout << dp[k][s] << endl;
	}
}

Measured memory_bytes: 1224
#include <iostream>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	int d[n]; REP(i, 0, n) cin >> d[i];
	long long ans = 0;
	REP(i, 0, n)
		REP(j, i + 1, n)
			ans += d[i] * d[j];
	cout << ans;
}

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

Hs[0] -= 1
for i in range(1, N):
    if Hs[i] > Hs[i - 1]:
        Hs[i] -= 1
    elif Hs[i] >= Hs[i - 1]:
        pass
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 63984
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 540000;

int n;
string s;
int l;
int r;
int pl, pr;
int p[N];
int rr[N];
int al[N];
int ar[N];

int get(int x) {
	int ans = 0;
	int now = 1;
	while (x) {
		int c = x % 3;
		x /= 3;
		if (c == 1) {
			ans += now * 2;
		} else if (c == 2) {
			ans += now;
		}
		now *= 3;
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n;
	cin >> s;
	r = n / 2;
	l = n - r;
	pl = 1;
	for (int i = 0; i < l; ++i) {
		pl *= 3;
	}
	pr = 1;
	for (int i = 0; i < r; ++i) {
		pr *= 3;
	}

	for (int i = 0; i < pl * pr; ++i) {
		rr[i] = get(i);
	}

	for (int i = 0; i < pr; ++i) {
		p[i] = i;
	}

	for (int i = 0; i < pl * pr; ++i) {
		ar[i] = i % pr;
		al[i] = i / pr;
	}

	int dr = 0;

	for (char c : s) {
		if (c == 'S') {
			dr ^= 1;
			for (int i = 0; i < pr; ++i) {
				p[i] = rr[p[i]];
			}
		} else if (c == 'R') {
			int z = 0;
			for (int i = 0; i < pr; ++i) {
				++p[i];
				if (p[i] == pr) {
					z = i;
					p[i] = 0;
				}
			}

			for (int i = 0; i < pl; ++i) {
				int x = i * pr + z;
				int y = al[x];
				if (dr) {
					y = rr[y];
				}
				y += 1;
				if (y == pl) {
					y = 0;
				}
				if (dr) {
					y = rr[y];
				}
				al[x] = y;
			}
		}
	}

	for (int i = 0; i < pl * pr; ++i) {
		if (dr) {
			cout << rr[al[i]] * pr + p[ar[i]] << " ";
		} else {
			cout << al[i] * pr + p[ar[i]] << " ";
		}
	}
	cout << "\n";

	return 0;
}




Measured memory_bytes: 10548
n = gets.to_i
ss = n.times
  .map { gets.chomp[0] }
  .select { |s| %w(M A R C H).any? { |c| s.start_with?(c) } }

counts = %W(M A R C H).each_with_object(Hash.new(0)) { |c, h| h[c] = 0 }
ss.each { |s| counts[s] += 1 }

ans = counts.keys.combination(3).inject(0) do |r, (a, b, c)|
  r + counts[a] * counts[b] * counts[c]
end

puts ans


Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
#define MOD 1000000007
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = 2147493647;
const double pi = acos(-1);
const double EPS = 1e-9;

int main()
{
    int n;
    cin >> n;
    vi A(n);
    rep(i,0,n) cin >> A[i];
    double sm = 0;
    rep(i,0,n) sm += (1/(double)(A[i]));
    cout << fixed << setprecision(12) << (1/sm) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<utility>
#include<queue>
using namespace std;

struct task{
  string name;
  int time;
};

int main(){
  queue<task> que;
  task t, t1;
  string name;
  int n, q, time, cnt_time;
  cnt_time = 0;
  cin>>n>>q;
  for(int i=0;i<n;i++){
    cin>>name>>time;
    t.name=name;
    t.time=time;
    que.push(t);
  }
  while(!que.empty()){
    t = que.front();
    if(t.time <= q){
      cnt_time += t.time;
      cout<<t.name<<" "<<cnt_time<<endl;
      que.pop();
    }
    else{
      cnt_time += q;
      t1.name = t.name;
      t1.time = t.time - q;
      que.pop();
      que.push(t1);
    }
  }
}



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

int main() {
	
	int n; cin >> n;
	vector<ll> x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	ll maxCnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			ll tmp_x = x[j] - x[i];
			ll tmp_y = y[j] - y[i];
			ll tmpCnt = 0;
			for (int k = 0; k < n; k++) {
				for (int h = 0; h < n; h++) {
					if (k == h) continue;
					if (x[h] - x[k] == tmp_x && y[h] - y[k] == tmp_y) {
						tmpCnt++;
					}
				}
			}
			maxCnt = max(maxCnt, tmpCnt);
		}
	}
	cout << n - maxCnt << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	long long cnt = 11;
	cout << cnt << " ";
	int tmp = 1;
	while(tmp < n)
	{
		cnt += 10;
		bool flag = true;
		for(int i = 2; i < cnt; i++)
		{
			if(cnt % i == 0)
			{
				flag = false;
			}
		}
		
		if(flag == true)
		{
			tmp++;
			cout << cnt << " ";
		}
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    string input;
    cin >> input;

    string st;
    rep(i, input.size()) {
        if (input[i] == 'A') {
            st.pb('A');
        } else if (input[i] == 'B') {
            if (i + 1 < input.size() && input[i+1] == 'C') {
                st.pb('F');
                i++;
            } else {
                st.pb('x');
            }
        } else {
            st.pb('x');
        }
    }

    //std::cout << st << std::endl;

    int ans = 0, cnt = 0;
    rep(i, st.size()) {
        if (st[i] == 'A') cnt++;
        else if (st[i] == 'F') {
            ans += cnt;
        } else {
            cnt = 0;
        }
    }

    std::cout << ans << std::endl;


    return 0;
}


Measured memory_bytes: 916
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

ll h,w;
char ch[200][200];
int rui[200][200];
int f[200][200][200],g[200][200][200];
int main(){
    cin>>h>>w;
    for(int i=0;i<200;i++)rui[i][0]=rui[0][i]=0;
    for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	    cin>>ch[i][j];  
	    rui[i+1][j+1]=rui[i+1][j]+rui[i][j+1]-rui[i][j]+(ch[i][j]=='.'); 
	}
    }
    for(int a=0;a<w;a++)for(int b=a;b<w;b++){
	for(int c=0;c<h;c++){
	    int l=c-1,r=h,d;
	    while(l<r-1){
		d=(l+r)>>1;
		int res=rui[d+1][b+1]-rui[d+1][a]-rui[c][b+1]+rui[c][a];
		if(res==0||res==(b-a+1)*(d-c+1))l=d;
		else r=d;
	    }
	    f[a][b][c]=l;
	}
    }
    for(int s=0;;s++){
	if(f[0][w-1][0]>=h-1){
	    cout<<s<<endl;
	    break;   
	}
	for(int a=0;a<w;a++)for(int b=a;b<w;b++)for(int c=0;c<h;c++){
	    int d=f[a][b][c];
	    d++;
	    if(d<h)g[a][b][c]=f[a][b][d];
	    else g[a][b][c]=h-1;
	    if(a<b){
		int l=a,r=b-1,k;
		while(l<r-1){
		    k=(l+r)>>1;
		    if(f[a][k][c]>f[k+1][b][c])l=k;
		    else r=k;
		}
		chmax(g[a][b][c],min(f[a][l][c],f[l+1][b][c]));
		chmax(g[a][b][c],min(f[a][r][c],f[r+1][b][c]));
	    }
	}
	for(int a=0;a<w;a++)for(int b=a;b<w;b++)for(int c=0;c<h;c++){
	    f[a][b][c]=g[a][b][c];
	}
    }
}



Measured memory_bytes: 61696
#include<stdio.h>
#include<stdlib.h>
int main()
{
    char str[10];
    int z, x, y;

    scanf("%[^\n]", str);
    z = strcmp(str, "Sunny");
    x = strcmp(str, "Cloudy");
    y = strcmp(str, "Rainy");


    if(z == 0)
    {
        printf("Cloudy");
    }

    else if(x == 0)
    {
        printf("Rainy");
    }

    else if(y == 0)
    {
        printf("Sunny");
    }

    return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main(void) {
  int i, j, k, d, e;
  while( 1 ) {
    double ans = 10e9;
    scanf("%d%d", &d, &e);
    if(!d && !e) break;
    for(i = 0; i <= d / 2; ++i) {
      double t = sqrt(i * i + (d - i) * (d - i)) - (double)e;
      if((t >= 0 ? t : -t) < ans) ans = t >= 0 ? t : -t;
    }
    printf("%lf\n", ans);
  }
  return 0;
}


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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (int i = 0; i <  (int)(n); i++)
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)

namespace graph {
  static const int V_MAX = 1010;
  static const long long INF = (1LL<<60);
  struct edge {
    int from, to, dist;
  };

  int V_SIZE = 0;
  std::vector<edge> G[V_MAX];

  long long wf_dp[V_MAX][V_MAX];
  bool wf_initialized = false;
  void wf_init() {
    if(wf_initialized) return;
    assert(V_SIZE > 0);
    for(int i = 0; i < V_SIZE; i++)
    for(int j = 0; j < V_SIZE; j++) {
      if(i == j) wf_dp[i][j] = 0LL;
      else {
        auto itr = find_if(G[i].begin(), G[i].end(), [j](edge e) { return e.to == j; });
        if(itr != G[i].end()) wf_dp[i][j] = (long long)itr->dist;
        else wf_dp[i][j] = INF;
      }
    }
    for(int k = 0; k < V_SIZE; k++)
    for(int i = 0; i < V_SIZE; i++)
    for(int j = 0; j < V_SIZE; j++)
    if(wf_dp[i][k] < INF && wf_dp[k][j] < INF) {
      wf_dp[i][j] = std::min(wf_dp[i][j], wf_dp[i][k] + wf_dp[k][j]);
    }
    wf_initialized = true;
  }
}

namespace solver {
  using namespace std;
  using namespace graph;
  typedef long long ll;

  static const ll MAX = 330LL;
  int A[MAX][MAX];

  void init() {
    scanf("%lld", &V_SIZE);
    rep(i, V_SIZE) rep(j, V_SIZE) {
      scanf("%lld", &A[i][j]);
      G[i].push_back({i, j, A[i][j]});
    }
  }

  void solve() {
    graph::wf_init();
    bool B[V_SIZE][V_SIZE];
    rep(i, V_SIZE-1) REP(j, i+1, V_SIZE) B[i][j] = true;
    rep(i, V_SIZE-1) REP(j, i+1, V_SIZE) if(wf_dp[i][j] < A[i][j]) {
      std::cout << "-1" << endl;
      return;
    }
    rep(i, V_SIZE-1) REP(j, i+1, V_SIZE) rep(k, V_SIZE) if(i!=k && j!=k) {
      if(wf_dp[i][j] == wf_dp[i][k] + wf_dp[k][j]) B[i][j] = false;
    }
    ll ans = 0;
    rep(i, V_SIZE-1) REP(j, i+1, V_SIZE) if(B[i][j]) ans += A[i][j];
    std::cout << ans << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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

#define int ll
#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define pb push_back
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
constexpr int inf = 1ll<<61;

class dijkstra{
public:
  ll ans;

  dijkstra(ll s,ll t,vector<vector<pii>> &g,vector<vector<pii>> &f){ // sからtへの最短経路
    vector<vector<vector<pii>>> G(2);
    G[0] = move(g);
    G[1] = move(f);
    vvi dist(2,vi(G[0].size(),inf));
    vector<vector<bool>> visit(2,vector<bool>(G[0].size(),false));
  
    vector<priority_queue<pii,vector<pii>,greater<pii>>> que(2);
    que[0].emplace(dist[0][s]=0,s);
    que[1].emplace(dist[1][t]=0,t);
    ll mu = inf;

    while(!que[0].empty() and !que[1].empty()){
      if(que[0].top().first + que[1].top().first >= mu) break;
      ll k = (que[0].top().first > que[1].top().first)?0:1;
      ll d,v; tie(d,v) = que[k].top();
      que[k].pop();

      if(visit[k^1][v]) goto L;
      visit[k][v] = true;

      rep(i, G[k][v].size()){
	auto n = G[k][v][i];
	ll tmp = d + n.second;
	if(dist[k][n.first] > tmp){
	  mu = min(mu, dist[k][v] + n.second + dist[k^1][n.first]);
	  dist[k][n.first] = tmp;
	  que[k].emplace(tmp,n.first);
	}
      }
    }
  L:
    g = move(G[0]);
    f = move(G[1]);

    ans = inf;
    rep(i,g.size()) ans = min(ans, dist[0][i]+dist[1][i]);
  }
};

main(){
  int k; cin >> k;
  vector<vector<pii>> g(k,vector<pii>(2)),f(k);
  rep(i,k){
    g[i][0] = pii((i+1)%k,1);
    g[i][1] = pii((i*10)%k,0);
    
    f[(i+1)%k].pb(pii(i,1));
    f[(i*10)%k].pb(pii(i,0));
  }
  dijkstra d(1,0,g,f);
  cout << d.ans+1 << endl;
}

Measured memory_bytes: 18672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	int ct = 0;
	REP(i,n){
cin >> a[i];
 if(a[i] & 1)ct++;
	}
	if(!(ct &1))cout << "YES" << endl;
	else cout << "NO" << endl;
	
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B ; cin >> A >> B;
    int d,e,f;
        d = A + B;
        e = A - B;
        f = A * B;
    vector<int> aaa(3);
    aaa.at(0) = d;
    aaa.at(1) = e;
    aaa.at(2) = f;
    sort(aaa.begin(),aaa.end());
    cout << aaa.at(2) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#include<stdlib.h>


int bubblesort (int * ,int);
int main(){
  int i, n,*a,q,f=0;
  scanf(" %d",&n);

  a=(int *)malloc(n *sizeof(int));
  for(i=0;i<n;i++){

    scanf(" %d",&a[i]);
   
  }
 f= bubblesort(a,n);
 //printf("%d",a[0]);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");;
    printf("%d",a[i]);
  }
 printf("\n%d\n",f);

 return 0;
}

int bubblesort(int *A,int N){
  int i,j,k,l,m=0;
  for(i=0;i<N-1;i++){
    for (j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1])
	{
	  k=A[j];
	  l=A[j-1];
	  A[j]=l;
	  A[j-1]=k;
	  m++;
	}
    }
  }
  
  return m;
}



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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int a[n], p[n], q[n];
	for (int i = 0; i < n; i++){
		a[i] = i + 1;
	}
	for (int i = 0; i < n; i++){
		cin >> p[i];
	}
	ll ans = 0;
	bool f = false;
	while(f == false){
		ans ++;
		f = true;
		for (int i = 0; i < n; i++){
			if (a[i] != p[i]){
				f = false;
				break;
			}
		}
		next_permutation(a, a + n);
	}
	for (int i = 0; i < n; i++){
		cin >> q[i];
		a[i] = i + 1;
	}
	f = false;
	while(f == false){
		ans --;
		f = true;
		for (int i = 0; i < n; i++){
			if (a[i] != q[i]){
				f = false;
				break;
			}
		}
		next_permutation(a, a + n);
	}
	cout << abs(ans);
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
  let k: i64 = read();
  let n: usize = read();
  let a: Vec<i64> = read_n(n);

  let mut ans = 0;
  let mut lg = 0;
  let mut prev = a[0];
  for i in 1..a.len() {
    let ai = a[i];
    ans += ai - prev;
    lg = max(lg, ai - prev);
    prev = ai;
  }

  lg = max(lg, k + a[0] - prev);
  ans += k + a[0] -  prev;
  println!("{}", ans - lg);

}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 105;
int n, m;
string s[N];
string ans;

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


Measured memory_bytes: 3676
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int A, B;
	cin >> A >> B;
	cout << max(A + B, max(A - B, A*B)) << endl;	
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

int n;
string s;

void init() {
  cin >> n >> s;
}
void solve() {
  int ans = 0;
  for(int i = 0 ; i < 10 ; ++i) {
    for(int j = 0 ; j < 10 ; ++j) {
      for(int k = 0 ; k < 10 ; ++k) {
        string p; p.push_back('0' + i); p.push_back('0' + j); p.push_back('0' + k);
        int ii = 0;
        for(int l = 0 ; l < n ; ++l) {
          if(s[l] == p[ii]) {
            ii++;
            if(ii > 2) break;
          }
        }
        if(ii > 2) ans++;
      }
    }
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  init();
  solve();
}


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

int P[10000+10];
int n,q,p,num1,num2;

int root(int a){
	if (P[a] == a) return a;
	return (P[a] = root(P[a]));
}

bool same(int a, int b){
	return root(a)==root(b);
}
	
void unite(int a, int b){
	P[root(a)] = root(b);
}	
			
int main() {
	cin >> n >> q;
	for (int i=1; i<=n; i++){
		P[i] = i;
	}
	
	for (int x=1; x<=q; x++){
		cin >> p >> num1 >> num2;
		if (p==0){			
			unite(num1, num2);
		}else{
			cout << same(num1, num2) << endl;
		}
	}
}

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

using namespace std;

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


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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
    fastio;

    string s;
    cin >> s;
    bool characters[26];
    FOR(i, 0, 26) {
        characters[i] = false;
    }
    FOR(i, 0, s.size()) {
        int x = s[i] - 96;
        characters[x-1] = true;
    }
    bool possible = false;
    FOR(i, 0, 26) {
        if (!characters[i]) {
            possible = true;
            char c = i + 1 + 96;
            cout << c << "\n";
            break;
        }
    }
    if (!possible) {cout << "None\n";}
    return 0;
}


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

int main()
{
  ll n,t;
  cin >> n >> t;
  vector<pair<ll,ll> > v;
  rep(n)
  {
    ll a,b;
    cin >> a >> b;
    v.emplace_back(a,b);
  }
  sort(v.begin(),v.end());
  
  rep(n)
  {
    if(v[i].second <= t)
    {
      cout << v[i].first << endl;
      return 0;
    }
  }

  cout << "TLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
vector<int > baseK(int N, int k) {
    vector<int> ans;
    if(N == 0) {
        ans.push_back(0);
        return ans;
    }
    const int absK = abs(k);
    while (N != 0) {
        int current = (N % k + absK) % absK;
        ans.push_back(current);
        N -= current;
        N /= k;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
//-------
void func() {
    int N;
    cin >> N ;
    vector<int > ans = baseK(N,-2);
    string rel = "";
    for (auto num: ans) {
        rel += to_string(num);
    }
    cout << rel << endl;
}

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


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N, 0);
    rep(i, 0, K) {
        int d;
        cin >> d;
        rep(j, 0, d) {
            int t;
            cin >> t;
            t--;
            a[t]++;
        }
    }
    int res = 0;
    rep(i, 0, N) {
        if(a[i] == 0) {
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (n); ++i)
#define pb push_back
#define ALL(c) (c).begin(), (c).end()

const int INF = 100100100;

struct Edge
{
    int to, cost, com;
    bool operator>(const Edge &rhs) const { return cost > rhs.cost; }
};

int cost[102][22];
int dis[102][102][22];
vector<int> q[22], r[22];
vector<Edge> G[102];

int calcost(int dis, int com)
{
    int t = lower_bound(ALL(q[com]), dis) - q[com].begin();
    if(t == 0) return dis * r[com][0];
    int ret = r[com][0] * q[com][0];
    rep2(i, 1, t) ret += r[com][i] * (q[com][i] - q[com][i-1]);
    ret += r[com][t] * (dis - q[com][t-1]);
    return ret;
}

int main()
{
    int n, m, c, s, g, x, y, d, cc, p[22];

    while(cin >> n >> m >> c >> s >> g && n)
    {
        // initialize
        --s, --g;
        rep(i, 22) q[i].clear(), r[i].clear();
        rep(i, 102) G[i].clear();
        fill_n(**dis, 102*102*22, INF);
        rep(i, 102) rep(j, 22) dis[i][i][j] = 0;
        fill_n(*cost, 102*22, INF);
        fill_n(cost[s], 22, 0);

        // input
        rep(i, m) {
            cin >> x >> y >> d >> cc;
            --x, --y, --cc;
            dis[x][y][cc] = min(dis[x][y][cc], d);
            dis[y][x][cc] = min(dis[y][x][cc], d);
        }
        rep(i, c) cin >> x, p[i] = x;
        rep(i, c) {
            rep(j, p[i]-1) cin >> x, q[i].pb(x);
            rep(j, p[i]) cin >> x, r[i].pb(x);
        }

        // Warshall-Floyd
        rep(k, n) rep(i, n) rep(j, n) rep(l, c) {
            dis[i][j][l] = min(dis[i][j][l], dis[i][k][l] + dis[k][j][l]);
        }

        // make graph
        rep(i, n) rep2(j, i+1, n) rep(k, c) {
            if(dis[i][j][k] < INF) {
                int co = calcost(dis[i][j][k], k);
                G[i].pb((Edge){ j, co, k });
                G[j].pb((Edge){ i, co, k });
            }
        }

        // Dijkstra
        priority_queue< Edge, vector<Edge>, greater<Edge> > que;
        que.push((Edge){ s, 0, 20 });
        while(!que.empty())
        {
            Edge cur = que.top(); que.pop();
            int v = cur.to;
            if(cost[v][cur.com] < cur.cost) continue;
            rep(i, G[v].size())
            {
                Edge &e = G[v][i];
                if(e.com == cur.com) continue;
                if(cost[e.to][e.com] > cur.cost + e.cost) {
                    cost[e.to][e.com] = cur.cost + e.cost;
                    que.push((Edge){ e.to, cost[e.to][e.com], e.com });
                }
            }
        }

        // output
        int mincost = INF;
        rep(i, c) mincost = min(mincost, cost[g][i]);
        if(mincost == INF) mincost = -1;
        cout << mincost << endl;
    }
}

Measured memory_bytes: 5636
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    for i in range(N):
        if A[i] % 2 == 0:
            if A[i] % 3 != 0 and A[i] % 5 != 0:
                print('DENIED')
                exit()
    print('APPROVED')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	LL A,B,C,D;
	string S;
	cin>>N>>A>>B>>C>>D;
	A--;B--;C--;D--;
	cin>>S;
	bool check=false;
	for(int i=B-1;i<D;i++){
		if(i+2>=N)continue;
		if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.')check=true;
	}
	bool a=true;
	bool b=true;
	int now=A;
	REP(i,N){
		if(now>=C)break;
		if(S[now+1]=='.'){
			now=now+1;
		}
		if(S[now+2]=='.'){
			now=now+2;
		}
	}
	if(now<C){
		a=false;
	}
	now=B;
	REP(i,N){
		if(now>=D)break;
		if(S[now+1]=='.'){
			now=now+1;
		}
		if(S[now+2]=='.'){
			now=now+2;
		}
	}
	if(now<D){
		b=false;
	}
	if(a==false||b==false){
		cout<<"No"<<endl;
		return 0;
	}
	if(C>D&&check==false){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
	
}

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

int main() {
  string S;
  cin >> S;
  int N;
  N = S.size();
  int x = 200000;
  int y = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A') {
      x = min (x, i);
    }
    else if (S[i] == 'Z') {
      y = max (y, i);
    }
  }
  cout << y - x + 1;
  return 0;
}
  

Measured memory_bytes: 640
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], ts[MAX_N];

/* subroutines */

ll invnum(int as[], int li, int ri) {
  if (li + 1 >= ri) return 0;

  ll cnt = 0;
  int mid = (li + ri) / 2;

  cnt += invnum(as, li, mid);
  cnt += invnum(as, mid, ri);

  int i = li, j = mid, k = li;
  while (i < mid && j < ri) {
    if (as[i] <= as[j]) ts[k++] = as[i++];
    else {
      cnt += mid - i;
      ts[k++] = as[j++];
    }
  }
  while (i < mid) ts[k++] = as[i++];
  while (j < ri) ts[k++] = as[j++];

  for (int i = li; i < ri; i++) as[i] = ts[i];

  return cnt;
}

/* main */

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

  ll cnt = invnum(as, 0, n);
  printf("%lld\n", cnt);
  return 0;
}

Measured memory_bytes: 2708
def maxHeapiify(A, i, n):
    l = 2*i+1
    r = 2*i+2
    if l < n and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r < n and A[r] > A[largest]:
        largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapiify(A, largest, n)


def buildMaxHeap(A, n):
    for i in range(n//2, -1, -1):
        maxHeapiify(A, i, n)


def main():
    N = int(input())
    H = list(map(int, input().split()))
    buildMaxHeap(H, N)
    print(" ", end="")
    print(*H)


if __name__ == '__main__':
    main()



Measured memory_bytes: 63704
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		int m = S % 3600 / 60;
		int s = (S % 3600) % 60;
		System.out.println(h + ":" + m + ":" + s);

	}
}


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

const	int 	INF = (2<<28);

int	main() {
	int N;
	cin >>N;
	int LN=N-1;
	//vector<vector<vector<int>>> node(N+1, vector<vector<int>> ());
	vector<vector<vector<long>>> node(N+1);
	for (int i=1; i<=N-1; i++) {
		int f;
		int t;
		long d;
		cin >>f >>t >>d;
		node.at(f).push_back({t, d});
		node.at(t).push_back({f, d});
	}
	int Q, K;
	cin >>Q >>K;
	vector<int> x(Q, 0);
	vector<int> y(Q, 0);
	for (int i=0; i<Q; i++)
		cin >>x.at(i) >>y.at(i);
	// Preparation
	// Tree: Nodes are from 1 to N
	// N-1 Links
	// No loop
	// to Store the distance
	vector<long> d(N+1, INF);
	// to check if done or not
	vector<bool> fixed(N+1, false);
	// queue to put node in processing order
	vector<int> q;
	int ixq;
	// Start Node
	d.at(K)=0;
	// Put into queue
	q.push_back(K);
	ixq=0;
	// Till all nodes done
	while(N!=ixq) {
		int f=q.at(ixq);
		fixed.at(f)=true;
		for (int i=0; i<node.at(f).size(); i++) {
			int t=node.at(f).at(i).at(0);
			long dd=node.at(f).at(i).at(1);
			if (!fixed.at(t)) {
				d.at(t)=d.at(f)+dd;
				q.push_back(t);
			}
		}
		ixq++;
	}
//	// Output
//	for (int i=1; i<=N; i++)
//		cout <<i <<": " << d.at(i) <<endl;
	for (int i=0; i<Q; i++)
		cout <<d.at(x.at(i))+d.at(y.at(i)) <<endl;
	return 0;
}



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

using namespace std;

using ll = long long;

#define clr(a) (a.clear())
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a))
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define pb push_back
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);

#define X first
#define Y second

using pii = pair <int, int>;
using pll = pair <ll, ll>;

const ll inf = 1;
const ll mod = 1E9;


#define SZ 100010



int main() {
#if defined JESI
//        freopen("1.txt", "r", stdin);
//        freopen("2.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector <int> a(n);
    for (auto &x: a) cin >> x;

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

    cout << a[n - 1] - a[0] << endl;

    return 0;
}






Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
		static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[][] dp=new int[s[0]+1][];
		dp[0]=new int[s[1]+1];
		int ans=0;
		for(int i = 1;i<=s[0];i++) {
			int[] q=sc.Ia2;
			dp[i]=new int[s[1]+1];
			for(int j = 1;j<=s[1];j++) {
				if(q[j]==1){continue;}
				dp[i][j]=1+Math.Min(Math.Min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]);
				ans=Math.Max(ans,dp[i][j]);
			}
		}
		Console.WriteLine("{0}",ans*ans);
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}


Measured memory_bytes: 45048