akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

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

	vector<int> gcd_1;
	for (int i = 1; i <= K; ++i) {
		for (int j = 1; j <= K; ++j) {
			gcd_1.push_back(gcd(i,j));
		}
	}

	long long sum = 0;
	for (int i = 1; i <= K; ++i) {
		for (auto t : gcd_1) {
			sum += gcd(i, t);
		}
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3320
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

bool out(int a, int b, int c) {
	return a < 0 || a >= N || b < 0 || b >= N || c < 0 || c >= N;
}

bool win(vector<vector<vector<int>>>&field, int a, int b, int c, int turn) {
	int ret = 1;
	vector<vector<int>>dir = { {0,0,1},{0,1,0},{1,0,0},{0,1,1},{1,0,1},{1,1,0},{0,1,-1},{1,0,-1},{1,-1,0},{1,1,1},{1,1,-1},{1,-1,1},{1,-1,-1} };
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (field[i][j][k] != turn)continue;
				for (auto d : dir) {
					if (out(i + d[0] * M, j + d[1] * M, k + d[2] * M))continue;
					int ok = true;
					for (int l = 1; l <= M; l++) {
						ok &= field[i + d[0] * l][j + d[1] * l][k + d[2] * l] == turn;
						if (!ok)break;
					}
					if (ok)return true;
				}
			}
		}
	}
	return false;
}

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

	while (cin >> N >> M >> K, N) {
		M--;
		vector<vector<vector<int>>>field(N, vector<vector<int>>(N, vector<int>(N, -1)));
		vector<vector<int>>nx(N, vector<int>(N, 0));
		for (int turn = 1; turn <= K; turn++) {
			int a, b;
			cin >> a >> b;
			a--, b--;
			field[a][b][nx[a][b]] = turn & 1;
			if (win(field, a, b, nx[a][b], turn & 1)) {
				if (turn & 1) {
					cout << "Black " << turn << endl;
				}
				else {
					cout << "White " << turn << endl;
				}
				turn++;
				while (turn <= K) {
					cin >> L >> R;
					turn++;
				}
				break;
			}
			nx[a][b]++;
			if (turn == K)cout << "Draw" << endl;
		}
	}
}


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

int main(){
  vector<int> candy(3);
  for(int i = 0; i < 3; i++){
    cin >> candy.at(i);
  }
  sort(candy.begin(), candy.end());
  if(candy.at(0) + candy.at(1) == candy.at(2)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  i64 n, m, c;
  cin >> n >> m >> c;

  vector<i64> b(m+1);
  rep(i, m) cin >> b[i];

  int ans = 0;
  i64 a[100][100];
  rep(i, n) {
    i64 res = 0;
    rep(j, m) {
      cin >> a[i][j];
      res += a[i][j] * b[j];
    }
    if (res + c > 0) ++ans;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, q, v[15], a[51], b[51], c[51], d[51], sol;

void backtr(int k, int pos) {
    if (k == n) {
        int suma = 0;
        for (int i = 1; i <= q; i++)
            if (v[b[i]] - v[a[i]] == c[i])
                suma += d[i];
        sol = max(sol, suma);
        return;
    }
    for (int i = pos; i <= m; i++) {
        v[k + 1] = i;
        backtr(k + 1, i);
    }
}

int main() {
    cin.tie(0);ios::sync_with_stdio(0);
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    backtr(0, 1);
    cout << sol;
    return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	int n, k;
	char s[50];
	scanf("%d%d%s", &n, &k, s);
	s[k - 1] = s[k - 1] - 'A' + 'a';
	printf("%s\n", s);	
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
vector<int> edge[100001];
bool used[100001];
int chi[100001];
int par[100001];

int dfs(int x){
  used[x] = true;
  chi[x] = 1;
  for(int c: edge[x]){
    if(used[c])continue;
    par[c] = x;
    int tmp = dfs(c);
    chi[x] += tmp;
  }
  return chi[x];
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  for(int i = 0; i < n - 1; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  fill(used, used + n, false);
  par[0] = 0;
  dfs(0);
  vector<int> vec;
  vec.pb(n - 1);
  for(int i = par[n - 1]; i != 0; i = par[i]){
    vec.pb(i);
  }
  vec.pb(0);
  if(vec.size() == 2){
    if(chi[0] - chi[n - 1] > chi[n - 1])cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
  }
  reverse(vec.begin(), vec.end());
  int at = (vec.size() + 1) / 2 - 1;
  fill(used, used + n, false);
  used[vec[at + 1]] = true;
  int tmp = dfs(vec[at]);
  if(tmp - 1 > n - tmp - 1)cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
	return 0;
}


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

const int MOD = 1000000007;

// 繰り返し二乗法 n^k % mod
ll modpow(int n, int k, int mod) {
    ll ret = 1;
    ll multi = n;
    for (int i = 0; i < 31; i++) {
        if (k >> i & 1) ret = ret * multi % mod;
        multi = multi * multi % mod;    
    }
    return ret;
}

// nCmのmの最大
const int mmax = 2010;
vector<int64_t> com1(mmax);
vector<int64_t> com2(mmax);

void combination(int n, int mod, vector<int64_t> &com) {
    com[0] = 1;
    for (int i = 1; i < mmax; i++) {
        int64_t c = (n-i+1) * modpow(i, mod-2, mod) % mod * com[i-1] % mod;
        if (c < 0) c += mod;
        com[i] = c;
    }
}

int main() {
    int n, k;
    cin >> n >> k;
    combination(k-1, MOD, com1);
    combination(n-k+1, MOD, com2);
    rep(i,k+1) {
        if (i > 0) {
            int64_t ans = (com1[i-1] * com2[i]) % MOD;
            // if (ans < 0) ans += MOD;
            // cout << com1[i-1] << " " << com2[i] << " " << ans << endl;
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int n, m, c; cin >> n >> m >> c;
	VI b(m); rep(i, m)cin >> b[i];
	VVI a(n, VI(m));
	rep(i, n)rep(j, m)cin >> a[i][j];

	int ans = 0;
	rep(i, n) {
		int sum = c;
		rep(j, m)sum += a[i][j] * b[j];
		if (sum > 0)ans++;
	}
	cout << ans << endl;
}

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

using P = pair<int, int>;
int n;
vector<P> v;

ModInt<> solve();

int main() {
  cin >> n;
  for (int t = 0; t < 2; ++t)
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      v.emplace_back(x, t);
    }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res = 1;
  int cnt[2] = {};
  for (auto p : v) {
    if (!cnt[!p.second])
      ++cnt[p.second];
    else
      res *= cnt[!p.second]--;
  }
  return res;
}

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

int main()
{
  int nap[3][3];

  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> nap[i][j];
    }
  }

  if(nap[0][0] + nap[1][1] == nap[0][1] + nap[1][0]
      && nap[0][1] + nap[1][2] == nap[0][2] + nap[1][1]
          && nap[1][0] + nap[2][1] == nap[1][1] + nap[2][0]
              && nap[1][1] + nap[2][2] == nap[1][2] + nap[2][1])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

using namespace std;

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

	vector<int> a(n + 1, 0);
	vector<int> b(n + 1, 0);
	vector<pair<int,int>> p(n);

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

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

	//for (int i = 0; i < n-1; i++) {
	//	for(int j=i+1;j<n;j++){
	//		if (b[i] > b[j]) {
	//			swap(a[i], a[j]);
	//			swap(b[i], b[j]);
	//		}
	//		else if (b[i] == b[j]&& a[i]>a[j]) {
	//			swap(a[i], a[j]);
	//			swap(b[i], b[j]);
	//		}
	//	}
	//}

	int limitt = 0;
	for (int i = 0; i < n; i++) {
		limitt = limitt +p[i].second;
		if (limitt > p[i].first) {
			cout << "No" << endl;
			return 0;
		}
		//else {
		//	limitt = limitt + b[i];
		//}

	}
	cout << "Yes" << endl;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll maxn=1000001,mod=1e9+7;

int par[maxn],sz[maxn];

void init(int n){
    for(int i=0;i<=n;i++){
        par[i]=i;
        sz[i]=1;
    }
}
int root(int a){
    while(a!=par[a]){
        par[a]=par[par[a]];
        a=par[a];
    }
    return a;
}
void uni(int a,int b){
    a=root(a);
    b=root(b);
    if(sz[b]>sz[a]) swap(a,b);
    par[b]=a;
    sz[a]+=sz[b];
}


int main(){
sync

    int n,m;
    cin>>n>>m;
    int ans[n+1];
    multiset<pii> ms;
    vvi g(maxn);
    int cnt[n+1];
    memset(cnt,0,sizeof(cnt));
    memset(ans,0,sizeof(ans));
    init(n);
    forn(i,n+m-1){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        cnt[b]++;
    }
    fore(i,1,n){
        ms.insert(mp(cnt[i],i));
    }
    while(!ms.empty()){
        pii p = *ms.begin();
        ms.erase(ms.begin());
        for(auto it:g[p.se]){
            
                ans[it]=p.se;
            
            auto iit = ms.find(mp(cnt[it],it));
            if(iit!=ms.end()){
                pii temp=*iit;
                ms.erase(iit);
                temp.fi-=1;
                cnt[it]-=1;
                ms.insert(temp);
            }
        }
    }
    fore(i,1,n){
        cout<<ans[i]<<endl;
    }
return 0;
}

Measured memory_bytes: 38912
#include <stdio.h>
#include <string.h>
int main () {
    int i=0,count=0;
    char w[15], n[1005];
    scanf("%s",w);
    while (1) {
        scanf("%s",n);
        if(strcmp(n,"END_OF_TEXT")==0) break;
        for(int j=0;j<strlen(n);j++) if(n[j]>='A'&&n[j]<='Z') n[j]+=32;
        if (strcmp(n,w)==0) count++;
    }
    printf("%d\n",count);
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a; cin >> a;
    double b; cin >> b;
    b += 0.001;
    b *=100;
    ll b100 = (ll)b / 100;
    ll b10 = ((ll)b%100)/10;
    ll b1 = (ll)b % 10;
    cout << b1 * a / 100 + b10 * a/ 10 + b100 * a  + ((b1*a)%100 + (b10*a)%10*10)/100<< endl;  
}


Measured memory_bytes: 3732
s = list(map(int, list(input())))
minnum = 9999

for i in range(len(s) - 2):
    if minnum > abs(753 - (s[i] * 100 + s[i+1]*10 + s[i+2])):
        minnum = abs(753 - (s[i] * 100 + s[i+1]*10 + s[i+2]))

print(minnum)


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

using namespace std;
const string YES = "YES";
const string NO = "NO";

void solve(int A, int B, int C) {
  rep(i, B)
    if (i * A % B == C) {
      cout << YES << endl;
      return;
    }
  cout << NO << endl;
}

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

  int A, B, C;
  cin >> A >> B >> C;

  solve(A, B, C);

  return 0;
}


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

constexpr int N = 1e5;

int n;
int a[N + 1], b[N + 1], c[N + 1], d[N + 1];

int f[N + 1];
int find(int x) {
    while (x != f[x])
        x = f[x] = f[f[x]];
    return x;
}
bool merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
        return 0;
    f[x] = y;
    return 1;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
        a[n] ^= a[i];
    }
    for (int i = 0; i < n; ++i) {
        std::cin >> b[i];
        b[n] ^= b[i];
    }
    
    std::copy(a, a + n + 1, c);
    std::copy(b, b + n + 1, d);
    std::sort(c, c + n + 1);
    std::sort(d, d + n + 1);
    if (!std::equal(c, c + n + 1, d)) {
        std::cout << -1 << "\n";
        return 0;
    }
    
    for (int i = 0; i <= n; ++i)
        f[i] = i;
    int ans = 0, cnt = 0;
    std::map<int, int> id;
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i])
            continue;
        ++ans;
        if (!id.count(a[i]))
            id[a[i]] = cnt++;
        if (!id.count(b[i]))
            id[b[i]] = cnt++;
        if (merge(id[a[i]], id[b[i]]))
            --ans;
    }
    
    ans += cnt;
    ans -= id.count(a[n]);
    
    std::cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 10228
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N,X = (int(x) for x in input().split())
x = list(map(int, input().split()))
a = [abs(X-y) for y in x]
if N == 1:
    print(a[0])
else:
    gcd = xgcd(a[0],a[1])
    for i in range(2,N):
        gcd = xgcd(gcd,a[i])
    print(gcd)

Measured memory_bytes: 63640
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  vector<int> d(n);
  for (int i=0; i<n; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());

  cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int cnt = 0;
    int a, b, c;
    cin >> c >> a >> b ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    for(int i = a ; i <= b; i++){
        if(i % c == 0){
            cnt++;
        }
    }
    
    //*
    if( cnt != 0 ){
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    //*/
    
    //cout << ((floor(a / 2) + fmod(a, 2)) / a) << endl;
    
    return 0; 
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int D[100010];
typedef pair<int, int> P; 
typedef pair<P, int> PP;
PP A[100010];
int L[100010];


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, 100010) L[i] = INF2;
    L[0] = 0;
    rep(i, M) {
        int l, r, c;
        cin >> l >> r >> c;
        l--; r--;
        A[i] = {{r, l}, c};
    }
    sort(A , A + M);
    //rep(i, M) cout <<A[i].first.second << " " << A[i].first.first << endl;
    rep(i, M) {
        int s = A[i].first.second;
        int t = A[i].first.first;
        int c = A[i].second;
        L[t] = min(L[t], L[s] + c);
        while(t - 1 >= 0 && L[t - 1] > L[t]) {
            L[t - 1] = L[t];
            t--;
        }
        //rep(i, N) cout << L[i] << " ";
        //cout << endl;
    }
    if (L[N - 1] >= INF2) {
        cout << -1 << endl;
        return 0;
    }
    //rep(i, N) cout << L[i] << " ";
    //cout << endl;
    cout << L[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;

    bool can = false;

    if (N % 2 == 0 && S.substr(0, N/2) == S.substr(N/2, N/2)) {
        can = true;
    }


    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 256
class Dice:
    def __init__(self, data):
        self.data = data

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
             self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]
        elif direction == 'LEFT':
            self.data[2],self.data[4],self.data[3],self.data[1] = \
                    self.data[1], self.data[2],self.data[4],self.data[3]


    def getTop(self):
        return self.data[0]

    def getRight(self):
        return self.data[2]

    def moveTopTo(self, target):
        for i in range(4):
            if self.data[0] == target:
                break
            self.move('W')

            if self.data[1] == target:
                self.move('S')
            elif self.data[4] == target:
                self.move('N')

    def moveFrontTo(self, target):
        for i in range(4):
            if self.data[1] == target:
                break
            self.move('LEFT')

dice = Dice(input().split())
count = int(input())
result = []

for i in range(count):
    (top, front) = [i for i in input().split()]
    dice.moveTopTo(top)
    dice.moveFrontTo(front)
    result.append(dice.getRight())

[print(i) for i in result]

Measured memory_bytes: 6808
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }
};

//--global--//



//----------//

bool calc(ll n, ll m, ll v, ll p, ll *s, int index) { //条件判定
	ll i = upper_bound(s, s+n, s[index]) - s - 1;
	ll a = s[i] + m, now = 0;
	ll k = upper_bound(s, s+n, a) - s - 1;
	if (k < n - p) return false;
	if (i >= n - p) return true;
	rep(j, n) {
		if (j >= n - p + 1) now += m;
		else now += min(a - s[j], m);
	}
	//cout << i << " " << now << endl;
	if (now >= m * v)return true;
	return false;
}

bool calc(ll n, ll m, ll v, ll p, ll *a, ll mid, ll nextMax){
    ll fm = a[mid] + m;
    ll allselect = m * (v-p+1LL);
    // cout << allselect << ", " << mid << endl;
    // cout << fm << endl;
    //if(fm < nextMax)return false;

	ll i = upper_bound(a, a+n, a[mid]) - a - 1;
	ll k = upper_bound(a, a+n, fm) - a - 1;

	if (k < n - p) return false;
	if (i >= n - p) return true;
    rep(i, n-(p-1LL)){
        //if(fm-a[i] <= 0LL)continue;
        allselect -= (min(fm-a[i], m));
    }

    if(allselect <= 0LL)return true;
    return false;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    ll *a;
    a = new ll[MAX];
    ll nextMax = -1;
    ll Ma = -1;
    rep(i, n){
        cin >> a[i];
        if(Ma == -1){
            Ma = a[i];
            nextMax = Ma;
        }
        if(Ma < a[i]){
            nextMax = Ma;
            Ma = a[i];
        }
    }
    //cout << nextMax << endl;

    sort(a, a+n);

    ll ansNum = LLINF;
    ll l = -1LL;
    ll r = n;
    while(r - l > 1LL){
        ll mid = (l + r) / 2LL;
        // cout << mid << ", " << a[mid] << endl;
        if(calc(n, m, v, p, a, mid, 1LL)){
            // できていたら
            r = mid;
            ansNum = min(ansNum, mid);
        }
        else{
            l = mid;
        }
    }

    //cout << ansNum << endl;

    cout << n - ansNum << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  int x[N];
  for(int i=0;i<N;++i) cin>>x[i];
  int ans = 0;
  for(int i=0;i<N;++i){
    ans += min(x[i], abs(K-x[i]))*2;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3476
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    dq = [LI() for _ in range(N)]
    p = [0] * N
    cnt = 0
    c = [0] * N
    while cnt < N*(N-1)//2:
        ud = False
        for i in range(N):

            while p[i] < N-1:
                j = dq[i][p[i]]-1
                if dq[j][p[j]]-1 == i:
                    c[i] = c[j] = max(c[i],c[j]) + 1
                    p[i] += 1; p[j] += 1
                    cnt += 1
                    ud = True
                else:
                    break
        if ud:
            continue
        else:
            print(-1)
            return
    print(max(c))

if __name__ == '__main__':
    main()

Measured memory_bytes: 54232
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if(i*m + n*j - 2*i*j == k) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
def main():
    import math
    import itertools
    N, K = map(int, input().split())

    # A = [i for i in range(N+1)]

    B = [0]*(N+2-K)
    # import numpy as np
    # for n in range(K, N+2):
    #     # print('n:', n)
    #     num = math.factorial(N+1) // (math.factorial(n)
    #                                   * math.factorial(N+1-n))
    #     try:
    #         C = [0]*num
    #     except:
    #         print(n)
    #     for i, v in enumerate(itertools.combinations(A, n)):
    #         # print('v:', v)
    #         C[i] = sum(v)
    #     # print('C:', C)
    #     B[n-K] = len(set(C))
    #     # print('B:', B[n-K])

    full = (((N+1)*(N)) // 2)
    for n in range(K, N+2):
        mi = (n*(n-1)) // 2
        # print(mi)
        ma = full - ((N-n)*(N-n+1)//2)
        # print(ma, '\n')
        B[n-K] = ma-mi+1
        # print(B[n-K])
    print(sum(B) % (10**9 + 7))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65968
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
using namespace std;
int main(){
string a,b,c;
cin>>a>>b>>c;
if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>


void do_command(int *dice, char command) {
  int targets[4] = {0, -1, 5, -1};
  int temp;

  switch (command) {
    case 'E':
      targets[1] = 3;
      targets[3] = 2;
      break;
    case 'W':
      targets[1] = 2;
      targets[3] = 3;
      break;
    case 'S':
      targets[1] = 4;
      targets[3] = 1;
      break;
    case 'N':
      targets[1] = 1;
      targets[3] = 4;
      break;
  }

  temp = dice[targets[0]];
  for (int i = 1; i < 4; i ++) 
    dice[targets[i - 1]] = dice[targets[i]];
  dice[targets[3]] = temp;
}
 
int main() {
  int dices[100][6];
  int q, l;
  char commands[25] = "NNNNWNNNWNNNENNNENNNWNNN";
  bool flag;
 
  std::cin >> q;
  for (int i = 0; i < q; i ++)
    for (int j = 0; j < 6; j ++) 
      std::cin >> dices[i][j];

  for (int i = 0; i < q; i ++) {
    flag = false;
    for (int j = i + 1; j < q; j ++) {
      for (int k = 0; k < 24; k ++) {
        for (l = 0; l < 6; l ++) {
          if (dices[i][l] != dices[j][l]) break;
          if (l == 5) {
            std::cout << "No" << std::endl;
            return 0;
          }
        }
        do_command(dices[i], commands[k]);

      }
    }
  }

    std::cout << "Yes" << std::endl;
  return 0;
}



Measured memory_bytes: 3100
from numpy import*
n,m,*a=int_(open(0).read().split())
a=int_(fft.irfft(fft.rfft(bincount(a,[1]*n,2**18))**2)+.5)
c=0
for i in where(a>0)[0][::-1]:t=min(m,a[i]);c+=i*t;m-=t
print(c)

Measured memory_bytes: 32936
#  --*-coding:utf-8-*--



def main():
    N = int(input())
    A = list(map(int, input().split()))

    M = int(10**9)
    bitOfM = M.bit_length()

    X = {}
    Y = [set() for _ in range(bitOfM+1)]

    for a in A:
        if not a in X:
            X[a] = 1
            Y[a.bit_length()].add(a)
        else:
            X[a] += 1

    c = 0

    for i in range(bitOfM, 0, -1):
        P = 1<<(i-1)
        
        if P in X:
            c += X[P]//2

        for a in Y[i]:
            if a == P:
                continue

            a2 = 2*P - a
            if a2 in X:
                c2 = min(X[a], X[a2])
                c += c2
                X[a2] -= c2


    print(c)



if __name__ == '__main__':
    main()


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, s.size() - 1) if (s[i] != s[i + 1]) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int g = 0;
    if(n==1){
      System.out.println(m);
      return;
    }
    for(int i=1;i<=m/n;i++)if(m%i==0)g=i;
    System.out.println(g);
  }
}


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

using namespace std;

int main(void) {
	int x, y;
	scanf("%d%d", &x, &y);
	int cal = 4*x - y;
	int b = cal /= 2;
	int a = x-b;
//	printf("a:%d\nb:%d\n", a, b);
	if(y%2 == 1) {
		printf("No\n");
	}
	/*else if(cal < 2) {
		printf("No\n");
	} */else {
		if(a < 0 || b<0) {
			printf("No\n");
		} else {
			printf("Yes\n");
		}
	}

	return 0;
}

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

using namespace std;

int main()
{
    long int n,p;
    scanf("%d",&n);
    if(n%2==0&&n%n==0){
        cout << n << endl;

    }
    else{
        p=n*2;
        cout << p << endl;
    }


    //cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
string s1,s2;
int main()
{
	cin>>n;
	cin>>s1>>s2;
	for(int i=1;i<=n;i++)
	cout<<s1[i-1]<<s2[i-1];
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
int dp[1010][1010];
char s[1010][1010];

signed main(){
	cin>>N>>M;
	REP(i,N){
		cin>>s[i];
	}
	REP(i,N){
		if(s[i][0]=='#'){
			break;
		}
		dp[i][0]=1;
	}
	REP(i,M){
		if(s[0][i]=='#'){
			break;
		}
		dp[0][i]=1;
	}
	REP(i,N){
		REP(j,M){
			if(s[i+1][j+1]!='#'){
				dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j];
				dp[i+1][j+1]%=MOD;
			}
		}
	}
	cout<<dp[N-1][M-1]<<endl;
	return 0;
}


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

int main() {
    float n, d;
    cin >> n >> d;

    int ans = ceil(n / (d*2+1));

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int c[3][3], i, j, k;
	bool valid = true;
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) cin >> c[i][j];
	}
	for (i = 0; i < 3; i++) {
		if (c[i][0] - c[i][1] != c[0][0] - c[0][1]) valid = false;
		if (c[i][2] - c[i][1] != c[0][2] - c[0][1]) valid = false;
		if (c[0][i] - c[1][i] != c[0][0] - c[1][0]) valid = false;
		if (c[2][i] - c[1][i] != c[2][0] - c[1][0]) valid = false;
	}

	if (valid) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}



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

if A+B<=2*C:
    ans=A*X+B*Y

elif X<=Y:
    ans=2*X*C
    Y-=X
    ans+=min(2*Y*C,Y*B)

elif X>Y:
    ans=2*Y*C
    X-=Y
    ans+=min(2*X*C,X*A)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, k; cin >> n >> k;
  vector<int> ai(n);
  for(int i = 0; i < n; i++) {
    cin >> ai.at(i);
  }
  for(int i = 0; i < n -k; i++) {
    if(ai.at(i) < ai.at(i +k)) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4048
n = int(input())
lst = list(map(int, input().split()))
res = 0
if n <= 2:
  print(0)
  exit()
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      if lst[i] != lst[j] and lst[j] != lst[k] and lst[k] != lst[i] and lst[i] + lst[j] > lst[k] and lst[j] + lst[k] > lst[i] and lst[k] + lst[i] > lst[j]:
        res += 1
print(res)

Measured memory_bytes: 9204
n = int(input())
a = list(map(int, input().split()))
 
sum = 0
sum1 = 0
mod = 1000000000+7
for i in range(n):
    if a[i] >= mod:
        a[i] = a[i] % mod
    sum1 += a[i]
    sum1 %= mod
    
for i in range(n-1):
    #for j in range(i+1, n):
    sum1 -= a[i]
    #sum += a[i] * a[j]
    if sum1 < 0:
        sum1 += mod
    sum += a[i] * sum1
    sum %= mod
            
print(sum)

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL x, y;
  cin >> x >> y;
  cout << ((x - y) * 100 + y * 1900) * (1ll<<y) << endl;

  return 0;
}


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

lac = [0]*(N+1)
lpcnt = [0]*(N+1)

for i in range(M):
  s = input().split()
  n = int(s[0])
  if s[1] == "AC":
    lac[n] =1
    continue
  if s[1] == "WA" and lac[n] == 0:
    lpcnt[n] += 1

cnt = 0
for i in range(N+1):
  if lac[i] == 1:
    cnt += lpcnt[i]
  
print(sum(lac), end=" ")
print(cnt)

Measured memory_bytes: 4596
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int gcd(int a,int b)
{
  int r;
  if(a<b){
    r=b;
    b=a;
    a=r;
  }
  
  while(a%b!=0){
    r=a%b;
    a=b;
    b=r;
  }
  return b;
}

void main(void)
{
  int K,sum=0;
  scanf("%d",&K);
  
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int l=1;l<=K;l++){
        sum+=gcd(gcd(i,j),l);
      }
    }
  }
  printf("%d",sum);
  
        
  
}

Measured memory_bytes: 1728
#include <cstdio>
#include <queue>
#include <algorithm>
#include <climits>

#define MAX_N (100000)

using namespace std;

typedef long long lint;

int size;
struct Node {
	int val, lazy;
} seg[1 << 18];

struct Spring {
	int pos, val;
	Spring(int pos, int val) : pos(pos), val(val) {}
	Spring() {}
};

bool operator < (const Spring &a, const Spring &b)
{
	if (a.val != b.val) return (a.val < b.val);
	return (a.pos > b.pos);
}

void init(int n)
{
	size = 1;
	while (size < n) size *= 2;	
}

inline void evaluate(int k)
{
	seg[k].val += seg[k].lazy;
	
	if (k < size - 1){
		seg[k * 2 + 1].lazy += seg[k].lazy;
		seg[k * 2 + 2].lazy += seg[k].lazy;
	}
	
	seg[k].lazy = 0;
}

inline void update(int k)
{
	seg[k].val = max(seg[k * 2 + 1].val, seg[k * 2 + 2].val);
}

void add(int a, int b, int x, int k = 0, int l = 0, int r = size)
{
	evaluate(k);
	
	if (b <= l || r <= a) return;
	
	if (a <= l && r <= b){
		seg[k].lazy += x;
		evaluate(k);
		return;
	}
	
	add(a, b, x, k * 2 + 1, l, (l + r) / 2);
	add(a, b, x, k * 2 + 2, (l + r) / 2, r);
	update(k);
}

int getMax(int a, int b, int k = 0, int l = 0, int r = size)
{
	evaluate(k);
	
	if (b <= l || r <= a) return (INT_MIN);
	
	if (a <= l && r <= b){
		return (seg[k].val);
	}
	
	int lmax = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
	int rmax = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
	update(k);
	
	return (max(lmax, rmax));
}

int main()
{
	int N, H;
	int dmg[MAX_N], heal[MAX_N];
	
	scanf("%d %d", &N, &H);
	
	for (int i = 0; i < N - 1; i++){
		scanf("%d %d", dmg + i, heal + i);
	}
	
	init(N);
	
	lint ans = 0;
	
	int nowLife = H;
	priority_queue<Spring> pq;
	for (int i = 0; i < N - 1; i++){
		add(i, i + 1, nowLife);
		pq.push(Spring(i, heal[i]));
		nowLife -= dmg[i];
		
		while (nowLife <= 0){
			Spring x = pq.top();
			int mVal = getMax(x.pos, i + 1);
			
			if (mVal + x.val > H){
				x.val = H - mVal;
				pq.pop();
				pq.push(x);
				continue;
			}
			
			int plus = min((-nowLife) / x.val + 1, (H - mVal) / x.val);
			ans += plus;
			add(x.pos, i + 1, plus * x.val);
			nowLife += plus * x.val;
		}
	}
	
	printf("%lld\n", ans);
	
	return (0);
}

Measured memory_bytes: 4264
package main

import (
	"fmt"
)

func main() {
	a, b := 0, 0
	fmt.Scanf("%d %d", &a, &b)

	i := b * 10
	found := false
	for ; i < ((a/2)+1)*25; i++ {
		if isValid(float64(i), a, b) {
			fmt.Println(i)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}
func isValid(x float64, a, b int) bool {
	if (int(float64(x)*.08) == int(a)) && (int(int(float64(x)*float64(.1))) == int(b)) {
		return true
	}
	return false
}

func abs(a, b int) int {
	if a-b < 0 {
		return b - a
	}
	return a - b
}
func mn(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int S = scan.nextInt();
		int W = scan.nextInt();

		if (W >= S) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 35592
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
const int maxn = 1e6 + 10;
int N,K,Q,a[maxn],ans = INT_MAX;
void cal(int x){
    int l,r;
    l = r = 1;
    vector<int> choice;
    while(l <= N){
        vector<int> tmp;
        while(a[l] < x && l <= N) l++;
        r = l;
        while(a[r] >= x && r <= N) r++;
        for(int i = l; i < r; i++) tmp.push_back(a[i]);
        l = r;
        if(tmp.size() < K) continue;
        sort(tmp.begin(),tmp.end());
        for(int i = 0; i < tmp.size() - K + 1; i++) choice.push_back(tmp[i]);
    }
    if(choice.size() < Q) return;
    sort(choice.begin(),choice.end());
    ans = min(ans, choice[Q - 1] - x);
}

int main(){
    FAST_IO
    cin>>N>>K>>Q;
    for(int i = 1; i <= N; i++) cin>>a[i];
    for(int i = 1; i <= N; i++) cal(a[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
#define iinf 0x3f3f3f3f3f3f3f3fll
using namespace std;
int n;
class node
{
	public:
		int x,id;
		inline bool operator<(const node &b)const
		{
			return x<b.x;
		}
}x[10000050];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(reg int i=1;i<=n;i++)
	{
		cin>>x[i].x;
		x[i].id=i;
	}
	sort(x+1,x+n+1);
	for(reg int i=1;i<=n;i++)cout<<x[i].id<<" "; 
}//第i个学生进入教室时已经有i个学生了 

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;


void oneCase() {
    ll n;
    cin >> n;
    int d = 0;
    for (auto l : to_string(n)) {
        d += int(l) - 48;
    }
    cout << (n % d ? "No\n" : "Yes\n");
    
}

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

    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
//cout<<fixed<<setprecision(15);

signed main(){
    int n; cin >> n;
    vp a(n);
    rep(i,n){cin >> a[i].second >> a[i].first;}
    sort(all(a));
    int t=0;
    rep(i,n){
        t+=a[i].second;
        if(t>a[i].first){
            coutn;
            return 0;
        }
    }
    couty;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputIntArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			List<long> intList = new List<long>();
			intList.Add(inputIntArray[0] * inputIntArray[2]);
			intList.Add(inputIntArray[0] * inputIntArray[3]);
			intList.Add(inputIntArray[1] * inputIntArray[2]);
			intList.Add(inputIntArray[1] * inputIntArray[3]);
			long result = intList.Max();
			Console.WriteLine(result);
		}
	}
}

Measured memory_bytes: 28324