akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string S;
int a[550000];
signed main() {
    cin >> S;
    S = '>' + S + '<';
    fill(a, a + 550000, -1);
    reps(i, S.length() - 1) {
        if (S[i - 1] == '>' && S[i] == '<') { a[i] = 0; }
    }
    for (int i = 1; i <= S.length() - 2; i++) {
        if (S[i] == '<') { chmax(a[i + 1], a[i] + 1); }
    }
    for (int i = S.length() - 1; i >= 1; i--) {
        if (S[i] == '>') { chmax(a[i], a[i + 1] + 1); }
    }

    int ans = 0;
    for (int i = 1; i <= S.length()-1; i++) { ans += a[i]; }
    cout << ans << endl;

}


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) {
    int atmp;
    cin >> atmp;
    a.at(i) = atmp - 1;
  }
  int pos = 0;
  vector<int> flag(n, -1);
  int x = 0, y = 0;
  rep(i,min(k, n+1)) {
    if (flag.at(pos) != -1) {
      x = i - flag.at(pos);
      y = (k - i) % x;
      break;
    }
    flag.at(pos) = i;
    pos = a.at(pos);
  }
  rep(i,y) {
    pos = a.at(pos);
  }
  cout << pos + 1 << endl;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = res * a % mod;
			a = a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = i * ninv % mod;
		}
	}
};

char inputbuf[4096];
char *ptr = inputbuf;

int main() {
	fread_unlocked(inputbuf, 1, sizeof(inputbuf), stdin);
	int n = 0;
	while (*ptr >= '0' && *ptr <= '9') n = n * 10 + *ptr++ - '0';
	while (*ptr != 'R' && *ptr != 'G' && *ptr != 'B') ptr++;
	
	int back[3] = { 0 };
	int forward[3] = { 0 };
	int a[n];
	for (int i = 0; i < n; i++) {
		a[i] = ptr[i] == 'R' ? 0 : ptr[i] == 'G' ? 1 : 2;
		back[a[i]]++;
	}
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		back[a[j]]--;
		res += forward[(a[j] + 1) % 3] * back[(a[j] + 2) % 3];
		res += forward[(a[j] + 2) % 3] * back[(a[j] + 1) % 3];
		forward[a[j]]++;
	}
	// j - i == k - jで相異なるものを引く
	int n2 = 1;
	for (; n2 < n + n - 1; n2 <<= 1);
	NTT<40961, 3> ntt;
	std::vector<int> count[3];
	for (auto &i : count) i.resize(n2);
	for (int i = 0; i < n; i++) count[a[i]][i]++;
	for (auto &i : count) ntt.ntt(i, false);
	
	std::vector<int> conved[3]; // conved count[i], count[(i + 1) % 3]
	for (int i = 0; i < 3; i++) {
		auto &cur = conved[i];
		cur.resize(n2);
		for (int j = 0; j < n2; j++) cur[j] = count[i][j] * count[(i + 1) % 3][j] % 40961;
		ntt.ntt(cur, true);
	}
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}


Measured memory_bytes: 3840
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
int a, b, n = 100, m = 100;
char buf[110][110];
int main() {
    memset(buf, '\0', sizeof(buf));
    scanf("%d%d", &a, &b);
    a--, b--;
    for (int i = 1; i <= n; i++) {
        buf[i][1] = '#';
        for (int j = 2; j < m; j++) {
            buf[i][j] = i & 1 ? '.' : '#';
        }
        buf[i][m] = '.';
    }
    for (int i = 1; i <= n; i += 2) {
        for (int j = 3; j < m; j += 2) {
            if (a) buf[i][j] = '#', a--;
        }
    }
    for (int i = n; i >= 1; i -= 2) {
        for (int j = m - 2; j > 1; j -= 2) {
            if (b) buf[i][j] = '.', b--;
        }
    }
    printf("%d %d\n", n, m);
    for (int i = 1; i <= n; i++) puts(buf[i] + 1);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  int cnt=0;
  cin >> a >> b >> c;
  for(int i=a; i<=b; i++){
    if(i%c==0){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<climits>
using namespace std;
 
int main()
{
  int n,k;
  cin>>n>>k;
  int * arr= new int [n];
  int *dp = new int[n];
 
 
  for(int i=0;i<n;i++)
  cin>>arr[i];
  for(int i=0;i<n;i++)
  dp[i]=INT_MAX;
  
  dp[0]=0;
  
   for(int i=0;i<n;i++)
   {
     for(int j=1;j<=k;j++)
     {   
       if(i+j>=n)
         break;
       dp[i+j]=min(dp[i]+abs(arr[i]-arr[i+j]),dp[i+j]);
      }
     
   }
   cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define maxn 110000
using namespace std;
typedef long long LL;
inline LL read()
{
    char ch=getchar();
    LL f=1,x=0;
    while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

struct LCA{
    LL eg;
    LL deep[maxn], head[maxn], fa[maxn][20], vis[maxn], dis[maxn];
    struct A{LL u, v, w, next;}star[maxn*2];
    void init(){
        memset(vis, 0, sizeof vis);
        memset(head, -1, sizeof head);
        memset(dis, 0, sizeof dis);
        eg = 0;
    }
    void ins(LL u,LL v,LL w){
        ++eg, star[eg] = (A){u, v, w, head[u]}, head[u] = eg;
    }
    void insert(LL u,LL v,LL w){
        ins(u,v,w);ins(v,u,w);
    }
    void dfs(LL u){
        vis[u]=1;
        for(LL i=1; i<=18; i++){
            if(deep[u] < (1<<i))break;
            fa[u][i] = fa[fa[u][i-1]][i-1];
        }
        for(LL i=head[u]; ~i; i=star[i].next){
            LL v = star[i].v;
            if(vis[v]) continue;
            deep[v] = deep[u]+1;
            fa[v][0] = u;
            dis[v] = dis[u] + star[i].w;
            dfs(v);
        }
    }
    LL lca(LL u, LL v){
        if(deep[u] < deep[v]) swap(u, v);
        LL d=deep[u]-deep[v];
        for(LL i=0;i<=18;i++)
            if((1<<i)&d) u = fa[u][i];
        for(LL i=18;i>=0;i--)
            if(fa[u][i]!=fa[v][i]){
                u=fa[u][i];v=fa[v][i];
            }
        if(u == v)return u;
        return fa[u][0];
    }
    void solve(LL n){
        init();
        for(LL i=1; i<n; i++){
            LL u, v, w;
            scanf("%lld%lld%lld", &u, &v, &w);
            insert(u, v, w);
        }
        LL m, k;
        scanf("%lld%lld", &m, &k);
        dfs(1);
        for(LL i=1; i<=m; i++){
            LL u, v, w;
            scanf("%lld%lld", &u, &v);
            printf("%lld\n", dis[u] + dis[k] - 2*dis[lca(u, k)] + dis[v] + dis[k] - 2*dis[lca(v, k)]);
        }
    }
}solver;


int main(){
    LL n;
    while(~scanf("%lld", &n)){
        solver.solve(n);
    }
    return 0;
}


Measured memory_bytes: 31360
// inputに入力データ全体が入る
function Main(input) {
  
  var inp = input.split('\n');

  var W = [];
  for (var i = 1; i <= parseInt(inp[0]); i++){
    W.push(inp[i]);
  }

  var preString = '';
  var nowString = '';
  for(var i = 0; i < W.length; i++){
    nowString = W[i];
    if(i >= 1){
      // 最後尾の文字のチェック
      if(preString.charAt(preString.length - 1) !== nowString.charAt(0)){
        console.log('%s', 'No');
        return;
      }
      // 同じ単語のチェック
      for (var j = 0; j < i; j++){
        if(nowString === W[j]){
          console.log('%s', 'No');
          // console.log(nowString);
          return;
        }
      }
    }
    preString = nowString;
  }

  console.log('%s', 'Yes')

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

    int cnt[100001] = {};
    int a[n], check = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] <= k && cnt[a[i]] == 0)  check++;
        cnt[a[i]]++;
    }

    if(check != k){
        cout << 0 << endl;
        return 0;
    }

    memset(cnt, 0, sizeof(cnt));
    int l = 0, r = 0, ans = n;
    check = 0;

    while(l < n){
        while(r < n && check < k){
            if(cnt[a[r]] == 0 && a[r] <= k) check++;
            cnt[a[r]]++;
            r++;
        }
        if(check < k)   break;
        ans = min(ans, r-l);
        if(cnt[a[l]] == 1 && a[l] <= k) check--;
        cnt[a[l]]--;
        l++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;

int main(){
    int a,b; cin >> a >> b;
    if(a<10 && b<10) cout << a*b << endl;
    else cout << -1 << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int par1[200001];
int par2[200001];
int len1[200001];
int len2[200001];
void init1(int n){
  for(int i=1;i<=n;i++){
    par1[i]=i;
    len1[i]=1;
  }
  return;
}
void init2(int n){
  for(int i=1;i<=n;i++){
    par2[i]=i;
    len2[i]=1;
  }
  return;
}
int root1(int n){
  if(par1[n]==n)return n;
  return root1(par1[n]);
}
int root2(int n){
  if(par2[n]==n)return n;
  return root2(par2[n]);
}
void unit1(int x,int y){
  x=root1(x);y=root1(y);
  if(x==y)return;
  if(len1[x]>len1[y]){
    par1[y]=x;
    len1[x]++;
  }
  else{
    par1[x]=y;
    len1[y]++;
  }
  return;
}
void unit2(int x,int y){
  x=root2(x);y=root2(y);
  if(x==y)return;
  if(len2[x]>len2[y]){
    par2[y]=x;
    len2[x]++;
  }
  else{
    par2[x]=y;
    len2[y]++;
  }
  return;
}
int main(){
  int n,k,l;cin>>n>>k>>l;
  int p[k],q[k],r[l],s[l];
  for(int i=0;i<k;i++)cin>>p[i]>>q[i];
  for(int i=0;i<l;i++)cin>>r[i]>>s[i];
  init1(n);init2(n);
  for(int i=0;i<k;i++){
    unit1(p[i],q[i]);
  }
  for(int i=0;i<l;i++){
    unit2(r[i],s[i]);
  }
  
  int ans[n+1];
  for(int i=1;i<=n;i++)ans[i]=0;
  vector<pair<pair<int,int>,int > >v={};
  for(int i=1;i<=n;i++){
    pair<int,int>p=make_pair(root1(i),root2(i));
    pair<pair<int,int>,int >pp=make_pair(p,i);
    v.push_back(pp);
  }
  sort(v.begin(),v.end()); 
  vector<int>w={};
  int cnt=0;
  for(int i=0;i<v.size()-1;i++){
    cnt++;
    if(v[i].first!=v[i+1].first){
      w.push_back(cnt);
      cnt=0;
    }
  }
  w.push_back(cnt+1);
  int cn=0;
  for(int i=0;i<v.size()-1;i++){
    ans[v[i].second]=w[cn];
    if(v[i].first!=v[i+1].first){
      cn++;
    }
  }
  ans[v[n-1].second]=w[w.size()-1];
  
  
  for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
}


Measured memory_bytes: 10480
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int W,a,b;
    while(scanf("%d%d%d",&W,&a,&b)!=EOF)
    {
        if (a<b)
        {
            if (a+W>b)
                printf("0\n");
            else
            {
                printf("%d\n",b-(a+W));
            }
        }
        else if(a==b)
            printf("0\n");
        else
        {
            if (b+W>a)
                printf("0\n");
            else
                printf("%d\n",a-(b+W));
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, H;
  cin >> N >> H;
  long max_a = 0;
  vector<long> bs(N);
  rep (i, N) {
    long a, b;
    cin >> a >> b;
    max_a = max(max_a, a);
    bs[i] = b;
  }
  sort(bs.rbegin(), bs.rend());
  long ans = 0;
  long rest = H;
  for (auto it: bs) {
    if (it <= max_a) break;
    if (rest <= 0) break;
    rest -= it;
    ans++;
  }
  if (rest > 0) {
    ans += rest / max_a;
    rest %= max_a;
    if (rest > 0) ans++;
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
 
int main()
{
  int A,B,C,seven=0,five=0;
  
  scanf("%d%d%d",&A,&B,&C);
  
  if(A==5){
    five++;
  }else if(A==7){
    seven++;
  }
  
  if(B==5){
    five++;
  }else if(B==7){
    seven++;
  }
  
  if(C==5){
    five++;
  }else if(C==7){
    seven++;
  }
  
  if(seven==1&&five==2){
    printf("YES");
  }else{
    printf("NO");
  }
  
  return 0;
}

Measured memory_bytes: 128
N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for _ in range(W+1)] for i in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])


Measured memory_bytes: 217176
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    int ab[2010] = {0};
    int ac[4010] = {0};
    int ad[4010] = {0};

    for(int a = 0;a <= 1000;a++){
        for(int b = 0;b <= 1000;b++){
            ab[a+b]++;
        }
    }
    for(int a = 0;a <= 2*1000;a++){
        for(int b = 0;b <= 1000;b++){
            ac[a+b]+=ab[a];
        }
    }
    for(int a = 0;a <= 3*1000;a++){
        for(int b = 0;b <= 1000;b++){
            ad[a+b]+=ac[a];
        }
    }
     while(cin>>n){
        cout<<ad[n]<<endl;
     }
    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define pie 3.141592653589793
#define si(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define pi(a) printf("%d",a)
#define pl(a) printf("%lld",a)
#define ps(a) printf("%s",a)
#define ll long long
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  int c;
  cin >> c;
  if(a==b)
    cout << c << endl;
  else if(c==b)
    cout << a << endl;
  else
    cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=300005;

int n,A[MAXN],type[MAXN];
bool Check()
{
	int last=2;
	for(int i=2;i<=n+2;i+=2)
		if(A[i]!=i||A[i+1]==i+1)
		{
			int L=last-1,R=min(i-1,n);
			//printf("(%d,%d)\n",L,R);
			int mx=0,mn=n+1;
			for(int j=L;j<=R;j++)
				mx=max(mx,A[j]),mn=min(mn,A[j]);
			if(mx!=R||mn!=L)
				return false;
			int t=0;
			for(int j=L;j<=R;j++)
				if(A[j]>j)
				{
					if(A[j]<A[t])
						return false;
					t=j;
				}
			t=0;
			for(int j=L;j<=R;j++)
				if(A[j]<j)
				{
					if(A[j]<A[t])
						return false;
					t=j;
				}
			i--;
			last=i+2;
			if(last>n)
				break;
		}
	return true;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&A[i]);
	if(Check())
		puts("Yes");
	else
		puts("No");
	
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#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 INF                 (ll)1e15
#define MOD                 (1000 * 1000 * 1000 + 7)
#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 IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
// 枝定義
struct Edge
{
	ll to;
	ll silver;
	ll cost;
	Edge(){}
	Edge(ll to, ll silver, ll cost) : to(to), silver(silver), cost(cost){}
};

struct queParam
{
	ll v;
	ll silver;
	ll cost;
	
	queParam(ll v, ll s, ll t) : v(v), silver(s), cost(t){}
	bool operator<(const queParam &a) const {
		return cost > a.cost;
	}
};

// グラフ定義(二次元配列)
template <class E>
using Graph = vector<vector<E>>;

// ダイクストラ
class Dijkstra
{
private:
	const ll maxSilver = 3000;

public:
	// res[i] = sからiまでの最短距離
	vector<vector<ll>> res;

public:
	Dijkstra(const Graph<Edge> &G, const vector<ll> &C, const vector<ll> &D, ll s)
	{
		int V = (int)G.size();
		res = vector<vector<ll>>(V, vector<ll>(maxSilver + 1, INF));

		priority_queue<queParam> que;
		s = min(s, maxSilver);
		que.emplace(0, s, 0);
		res[0][s] = 0;

		while (!que.empty()) {
			queParam qOne = que.top(); que.pop();

			// 違う最短距離がキューにあるのでスキップ
			if (res[qOne.v][qOne.silver] < qOne.cost) {
				continue;
			}
			if (qOne.silver < 0) {
				continue;
			}

			ll nokoriSilver = min(maxSilver, qOne.silver + C[qOne.v]);
			ll koukanCost = qOne.cost + D[qOne.v];
			if (res[qOne.v][nokoriSilver] > koukanCost) {
				res[qOne.v][nokoriSilver] = koukanCost;
				que.emplace(qOne.v, nokoriSilver, koukanCost);
			}

			// 最短距離を更新
			for (Edge e : G[qOne.v]) {
				nokoriSilver = qOne.silver - e.silver;
				if (0 <= nokoriSilver) {
					ll &nowCost = res[e.to][nokoriSilver];
					ll newCost = res[qOne.v][qOne.silver] + e.cost;
					if (nowCost > newCost) {
						nowCost = newCost;
						que.emplace(e.to, nokoriSilver, newCost);
					}
				}
			}
		}
	}
};

int main()
{
	int N, M, S;
	cin >> N >> M >> S;
	Graph<Edge>	G(N);
	REP(i, M) {
		ll u, v, a, b;
		cin >> u >> v >> a >> b;
		u--, v--;
		G[u].emplace_back(Edge(v, a, b));
		G[v].emplace_back(Edge(u, a, b));
	}

	vector<ll> C(N), D(N);
	REP(i, N) {
		cin >> C[i] >> D[i];
	}

	Dijkstra dijk(G, C, D, S);

	REPN(i, 1, N) {
		ll ans = INF;
		for (auto one : dijk.res[i]) {
			ans = min(ans, one);
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 7632
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String nn = String.valueOf(n);
		int[] nnn = new int[3];
		for (int i = 0; i <= 2; i++) {
			if (nn.charAt(i) == '1') {
				nnn[i] = 9;
			} else {
				nnn[i] = 1;
			}
		}
		for (int i = 0; i <= 2; i++) {
			System.out.print(nnn[i]);
		}
	}
}


Measured memory_bytes: 23636
import bisect

n, q = map(int, input().split())
s = input().strip()
lrs = [list(map(int, input().split())) for _ in range(q)]

indices = []
for i, (c0, c1) in enumerate(zip(s, s[1:])):
    if c0 == 'A' and c1 == 'C':
        indices.append(i)

indices_c = [i + 1 for i in indices]
for (l, r) in lrs:
    li = bisect.bisect_left(indices, l - 1)
    ri = bisect.bisect_left(indices_c, r)
    print(ri - li)

Measured memory_bytes: 32292
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		String S = sc.nextLine();

		String dream = "dream";
		String erase = "erase";

		int count = 0;
		while (count != -1) {
			if (S.startsWith(dream, count)) {
				count += 5;
				if (S.startsWith("er", count)) {
					if(S.startsWith(erase, count)) {
						count += 5;
						if(S.startsWith("r", count)) {
							count++;
						}
					} else {
						count += 2;
					}
				}
			} else if (S.startsWith(erase, count)) {
				count += 5;
				if (S.startsWith("r", count)) {
					count++;
				}
			} else {
				count = -1;
			}

			if (count == S.length()) {
				break;
			}
		}


		if (count != -1 ) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}


	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }

	}


}


Measured memory_bytes: 22868
#include<iostream>
#include<vector>
#include<algorithm>
using Int = long long;

int main() {

	Int A, B, C, D, E, F;

	std::cin >> A >> B >> C >> D >> E >> F;

	long double max_density = (long double)(E * 100) / (100 + E);
	long double ans_density = 0;
	Int ans_sum = 0;
	Int ans_sugar = 0;
	Int number_a = F / 100 / A;
	Int number_b = F / 100 / B;
	Int number_c = F / C;
	Int number_d = F / D;

	for (Int a = 0; a <= number_a; a++) {
		for(Int b=0;b<=number_b;b++){
			Int sum = 100 * A * a + 100 * B * b;
			if (sum > F)break;

			if (100 * A * a + 100 * B * b > 0) {
				for (Int c = 0; c <= number_c; c++) {
					Int sum = 100 * A * a + 100 * B * b + C * c;
					if (sum > F)break;

					for (Int d = 0; d <= number_d; d++) {
						Int sum = 100 * A * a + 100 * B * b + C * c + D * d;
						if (sum > F)break;

						Int sugar = C * c + D * d;
						long double density = (long double)sugar*100/ sum;//この行をsugar/sum*100にするとWA
						if (density >= ans_density && density <= max_density) {
								ans_density = density;
								ans_sum = sum;
								ans_sugar = sugar;
						}
					}
					
				}
				
			}
		}
	}

	std::cout << ans_sum <<" "<< ans_sugar << std::endl;

}

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

class Node{
    private:
        int data;
        Node* next;
        Node* prev;
    public:
        Node(){next = NULL; prev = NULL;}
        void setData(int data){this->data = data;}
        void setNext(Node* next){this->next = next;}
        void setPrev(Node* prev){this->prev = prev;}

        int getData(){return data;}
        Node* getNext(){return next;}
        Node* getPrev(){return prev;}
};

class List{
    private:
        Node* head;
        Node* tail;
    public:
        List(){
            head = new Node;
            tail = new Node;
            head->setPrev(tail);    //headの後ろがtail
            tail->setNext(head);
        }
        void insert(int x){
            Node* newNode;
            newNode = new Node;
            newNode->setData(x);
            newNode->setNext(head);
            newNode->setPrev(head->getPrev());
            head->getPrev()->setNext(newNode);
            head->setPrev(newNode);
        }
        void deleteNode(int x){
            tail->setData(x);
            Node* i = head->getPrev();
            while(i->getData()!=x)
                i = i->getPrev();
            if(i!=tail){
                i->getNext()->setPrev(i->getPrev());
                i->getPrev()->setNext(i->getNext());
                delete i;
            }
        }
        void deleteFirst(){
            Node* tmp = head->getPrev();
            tmp->getPrev()->setNext(head);
            head->setPrev(tmp->getPrev());
            delete tmp;
        }
        void deleteLast(){
            Node* tmp = tail->getNext();
            tmp->getNext()->setPrev(tail);
            tail->setNext(tmp->getNext());
            delete tmp;
        }
        void showList(){
            Node* i = head->getPrev()->getPrev();
            cout << head->getPrev()->getData();
            while(i!=tail){
                cout << " " << i->getData();
                i = i->getPrev();
            }
            cout << endl;
        }
        ~List(){
            Node* tmp = head->getPrev();
            while(tmp!=tail){
                delete tmp->getNext();
                tmp = tmp->getPrev();
            }
            delete tmp;
        }
};

int main(){
    List list;
    unsigned n;
    char command[12]; //コマンド
    int x;  //値
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> command;
        if(command[6]=='F'){
            list.deleteFirst();
        }else if(command[6]=='L'){
            list.deleteLast();
        }else if(command[0]=='i'){
            cin >> x;
            list.insert(x);
        }else if(command[0]=='d'){
            cin >> x;
            list.deleteNode(x);
        }else{
            cout << "Unknown command" << endl;
        }
    }
    
    
    list.showList();

    return 0;
}


Measured memory_bytes: 34320
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define db long double
   
int n;
ll c;
ll a[200007];
ll b[200007];
ll pref[200007];
ll pref2[200007];

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output2.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> c;
    ll ans = 0;
    for (int i = 1; i <= n; i++){
    	cin >> a[i] >> b[i];
    }

    ll sum = 0;
    for (int i = 1; i <= n; i++){
    	sum += b[i];
    	pref[i] = max(pref[i - 1], sum - a[i]);
    	ans = max(ans, pref[i]);
    }

    sum = 0;
    for (int i = n; i >= 1; i--){
    	sum += b[i];
    	pref2[i] = max(pref2[i + 1], sum - (c - a[i]));
    	ans = max(ans, pref2[i]);
    }

    sum = 0;
    for (int i = 1; i < n; i++){
    	sum += b[i];
    	ll now = sum - 2 * a[i] + pref2[i + 1];
    	ans = max(ans, now);
    }

    sum = 0;
    for (int i = n; i > 1; i--){
    	sum += b[i];
    	ll now = sum - 2 * (c - a[i]) + pref[i - 1];
    	ans = max(ans, now);
    }


    cout << ans;	
}

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

using namespace std;

bool same_all(string s)
{
	bool all = true;
	for (int i = 1; i < s.size(); i++)
	{
		if (s[0] != s[i])
		{
			all = false;
			break;
		}
	}

	return all;
}


int main()
{
	string s;
	int ans = 1000;

	cin >> s;
	int N = s.size();

	for (int i = 0; i < N; i++)
	{
		string t = s;
		int count = 0;
		while (!same_all(t))
		{
			for (int j = 0; j < t.size() - 1; j++)
			{
				if (t[j] == s[i])
				{
					if (j > 0)
						t[j - 1] = s[i];
				}
			}
			t.erase(t.begin() + t.size() - 1);

			count++;
		}

		if (ans > count)
			ans = count;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N=2e5+5;
int n,k,x[N];
double sum=0,ans;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>x[i];
	for(int i=0;i<k;i++)
	{
		sum+=(double)(x[i]+1)/2;
	}
	ans=sum;
	for(int i=k;i<n;i++)
	{
		sum-=(double)(x[i-k]+1)/2;
		sum+=(double)(x[i]+1)/2;
//		cout<<sum<<endl;
		ans=max(ans,sum);
	}
	printf("%.1f\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	cin>>n>>m;
	vector<string> w(n);
	for(int i=0; i<n; i++)
		cin>>w[i];

	int vert[] = {1,0,-1,0};
	int hort[] = {0,1, 0,-1};
	int max = 0;
	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			if(w[i][j] == '.') {
				vector<int> r(m, 0);
				vector< vector<int> > arr(n, r);
				vector< vector<int> > visited(n,r);
				queue< pair<int,int> > q;
				pair<int,int> sp = make_pair(i,j);
				q.push(sp);
				visited[i][j] = 1;
				while(!q.empty()) {
					pair<int,int> temp = q.front();
					q.pop();
					int r = temp.first;
					int c = temp.second;
					for(int k=0; k<4; k++) {
						if(r+vert[k] >= 0 && r+ vert[k] < n && c+hort[k] >=0 &&  c+hort[k] < m && w[r+vert[k]][c+hort[k]] != '#' && visited[r+vert[k]][c+hort[k]] == 0) {
							q.push(make_pair(r+vert[k], c+hort[k]));
							arr[r+vert[k]][c+hort[k]] = arr[r][c]+1;
							visited[r+vert[k]][c+hort[k]] = 1;
						}
					}
				}
				for(int x=0; x<n; x++) {
					for(int y=0; y<m; y++) {
						if(arr[x][y] > max)
							max = arr[x][y];
					}
					
				}
			}

		}
	}
	cout<<max;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   ll n;
   cin>>n;
   ll ar[n][2];
   for(ll i=0;i<n;i++)
   {
       cin>>ar[i][0];
       cin>>ar[i][1];
   }
   ll f=0;
   for(ll i=0;i<n-2;i++)
   {
       if(ar[i][0]==ar[i][1] && ar[i+1][0]==ar[i+1][1] && ar[i+2][0]==ar[i+2][1])
       {cout<<"Yes";
       f=1;
       break;
       }
   }
   if(f==0)
   cout<<"No";
    return 0;
}

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

int main(){
	int N,K;
  	cin >> N >> K;
  	char T[N];
	
  	for(int i = 0;i<N;i++){
    	cin >> T[i];
      	if(i+1 == K){
        	if(T[i] == 'A'){
            	T[i] = 'a';
            }
          	if(T[i] == 'B'){
            	T[i] = 'b';
            }
        	if(T[i] == 'C'){
            	T[i] = 'c';
                
            }
        }
      
      cout << T[i];
    }
}

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

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

        int AB = Integer.parseInt(sc.next());
        int BC = Integer.parseInt(sc.next());
        int CA = Integer.parseInt(sc.next());
        sc.close();

        out.printf("%d\n", AB * BC / 2);
        out.flush();
    }
}


Measured memory_bytes: 21844
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            var s = cin.Read;
            if(a < 3200)
            {
                WriteLine("red");
            }
            else
            {
                WriteLine(s);
            }
        }

        public long C(int X, int Y)
        {

            if (Y == 0 || Y == X)
            {
                return 1;
            }
            if (X < Y)
            {
                return 0;
            }
            var Pascal = new long[X + 1, X + 1];
            for (int i = 0; i <= X; i++)
            {
                Pascal[i, 0] = 1L;
                Pascal[i, i] = 1L;
            }
            for (int i = 2; i <= X; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[X, Y];
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
#define int long long
using namespace std;

int INF = 1e+15;
int n;
int a[300000];
int zen[300001];
int kou[300001];
priority_queue<int, vector<int>, greater<int> > que1;
priority_queue<int> que2;

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < 3 * n; i++) cin >> a[i];
	
	//前半
	int ssum = 0;
	for (i = 0; i < n; i++) { ssum += a[i]; que1.push(a[i]); }
	zen[n] = ssum;
	for (i = n; i < 3 * n; i++) {
		que1.push(a[i]); ssum += a[i];
		ssum -= que1.top(); que1.pop();
		zen[i + 1] = ssum;
	}
	
	//ひっくり返して
	int l = 0, r = 3 * n - 1;
	while (l < r) { swap(a[l], a[r]); l++; r--; }

	//後半
	ssum = 0;
	for (i = 0; i < n; i++) { ssum += a[i]; que2.push(a[i]); }
	kou[n] = ssum;
	for (i = n; i < 3 * n; i++) {
		que2.push(a[i]); ssum += a[i];
		ssum -= que2.top(); que2.pop();
		kou[i + 1] = ssum;
	}
	
	//デバッグ
	//for (i = 0; i <= 3 * n; i++) { cout << zen[i] << " " << kou[i] << endl; }
	
	int ans = -INF;
	for (i = n; i <= 2 * n; i++) {
		ans = max(ans, zen[i] - kou[3 * n - i]);
	}
	cout << ans << endl;
	return 0;
}

//前半|後半, の仕切りの場所を考えます(*)。(前半i個)|(後半3N-i個), としきりを入れたとき、前半では上位N個, 後半では下位N個を取りたいです。
//(前半i個)のうち上位N個をiを動かしながら持つには、「値の挿入・最小値の削除」を高速にできると嬉しいので、priority_queueが適しています。
//後半についても同様にできます。O(NlogN)で解けました。
//*「要素を選ぶ→仕切りをつける：最大値は？」を「仕切りをつける→要素を選ぶ：最大値は？」に置き換えても良い。

Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec_prob(N);
  for(int i=0; i<N; i++){
    cin >> vec_prob.at(i);
  }
  int M;
  cin >> M;
  vector<int> vec_ans(M);
  for(int j=0; j<M; j++){
    cin >> vec_ans.at(j);
  }
  sort(vec_prob.begin(), vec_prob.end());
  sort(vec_ans.begin(), vec_ans.end());
  
  int count = 0;
  int l=0;
  int k=0;
  while(k<M){
    if (vec_ans.at(k) == vec_prob.at(l)){
      count++;
      k++;
      l++;
    }
    else{
      l++;
    }
    if(l >= N){
      break;
    }
  }
  
  if(count == M){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

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

int gcd3(int a ,int b,int c){
  int x = gcd2(a,b);
  return gcd2(x,c);
}

int main(){
  int k;cin>> k;
  int64_t ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        ans+=gcd3(i,j,l);
      }
    }
  }

  cout << ans << endl;

}

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

using namespace std;
const int _max = 200;
typedef long long ll;
int dir[4][2] = {{1,  0},{-1, 0},{0,  1},{0,  -1}};
struct Node {
    int x;
    int y;
};
int a[_max];

int main() {
    int x,n;
    cin>>x>>n;
    for(int i=0;i<n;i++){
        int shu;
        cin>>shu;
        a[shu+100]=1;
    }
    if(a[x+100]==0){
        cout<<x<<endl;
        return 0;
    }
    for(int i=1;i<100;i++){
        if(a[x-i+100]==0){
            cout<<x-i<<endl;
            return 0;
        }
        if(a[x+i+100]==0){
            cout<<x+i<<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int x=0;
    while(a>=b){
        b*=2;
        x++;
    }
    while(b>=c){
        c*=2;
        x++;
    }
    if(x<=k)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m;
	cin >> n >> m;
	vector<ll> a(m);
	for(int i = 0; i < m; i++){
		cin >> a[i];
	}
	if(m<=n){
		cout << 0 << endl;
		return 0;
	}
	sort(all(a));

	vector<ll> l(m-1);
	for(int i = 0; i < m-1; i++){
		l[i] = a[i+1] - a[i];
	}
	sort(all(l));
	reverse(all(l));
	ll res = 0;
	for(int i = 0; i < n-1; i++){
		res += l[i];
	}
	cout << a[m-1] - a[0] - res << endl;

	return 0;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort()
blist = []

if n >= m :
  print(0)
elif n == 1:
  print(alist[m-1] - alist[0])
else:
  for i in range(0,m-1):
    blist.append(alist[i+1] - alist[i])
  blist.sort()
  d = -1 * (n-1)
  c = sum(blist[d:])
  b1 = alist[m-1] - alist[0]
  print(b1 - c)

Measured memory_bytes: 13968
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt();
    cout<<max(0,a-2*b)<<endl;
    
    return 0;   
}


 
 


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

int main(){
  int n; cin >> n;
  string str_t, str_h;
  int T = 0, H = 0;
  for(int i=0; i< n; i++){
    cin >> str_t >> str_h;
    if(str_t > str_h) T += 3;
    else if (str_t < str_h) H += 3;
    else {T++; H++;}
  }
  cout << T << ' ' << H << endl;
}



Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main() {
  int q;
  int c, a, n;
  
  cin >> q;
  while(q--) {
	int ans = 0;
	cin >> c >> a >> n;
	
	for(;c > 0;) {
	  if(n > 0) {
		if(a > 0) {
		  ans ++;
		  n--, a--, c--;
		} else n = 0;
	  } else if(a > 0 && c > 1) {
		ans ++;
		a--, c-=2;
	  } else {
		if(c > 2) c-=3, ans++;
		else c = 0;
	  }
	}
	cout << ans << endl;
  }
  
  return 0;
}

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

int main(void)
{
	int n;

	while(cin >> n, n){
		int ice[10] = {};
		int no;

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

		for(int i = 0; i < 10; i++){
			if(ice[i])
				for(int j = 0; j < ice[i]; j++)
					cout << "*";
			else
				cout << "-";
			cout << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>> a(n),b(m);
  for(auto& x:a)cin>>x.first>>x.second;
  for(auto& x:b)cin>>x.first>>x.second;
  
  for(auto x:a){
    int idx=0;
    int dist=(1<<28);
    for(int i=0;i<m;++i){
      int t=abs(x.first-b[i].first)+abs(x.second-b[i].second);
      if(t<dist){
        dist = t;
        idx = i+1;
      }
    }
    cout<<idx<<endl;
  }
}

Measured memory_bytes: 256
# AOJ ITP2_1_A: Vector
# Python3 2018.6.24 bal4u

from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	if a[0] == '2': Q.pop()      # popBack
	else:
		id, v = map(int, a.split())
		if id == 0: Q.append(v)  # pushBack
		else: print(Q[v])        # randomAccess


Measured memory_bytes: 13808
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  bool flag=0;
  for(size_t i=0;i<=S.length()-1;i++){
  
    flag=1;
    for(size_t j=i;j<=i+S.length()-1;j++){
      
        if(S[j%S.length()]!=T[j-i]){
          
          flag=0;
          break;
        }
    }
    if(flag==1){
      
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,a[340000],bits[63]={},two[63]={1},mycount,res=0;
string str;
int main() {
	cout << fixed << setprecision(18);
    for(long long int i=1;i<62;i++){
        two[i]=2*two[i-1];
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        mycount=0;
        while(a[i]!=0){
            bits[mycount]+=a[i]%2;
            a[i]/=2;
            mycount++;
        }
    }
    for(int i=0;i<=60;i++){
        long long int memo=bits[i]*(n-bits[i]);
        memo%=mod;
        memo*=(two[i]%mod);
        memo%=mod;
        res+=memo;
        //cout<<bits[i]<<endl;
    }
    cout<<res%mod;
} 


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    string s;
    cin >> s;

    s.push_back('T');
    int n = s.size();

    int x, y;
    cin >> x >> y;

    vector<int> a[2];
    int c = 0, d = 0, f = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'F') {
            c++;
        } else {
            if (f == 0) {
                x -= c;
                f = 1;
            } else {
                a[d].push_back(c);
            }
            c = 0;
            d ^= 1;
        }
    }

    int b = 0;
    for (int d = 0; d < 2; d++) {
        vector<int> dp(20000), h(20000);
        dp[10000] = 1;

        int m = a[d].size();
        for (int i = 0; i < m; i++) {
            int a1 = a[d][i];
            for (int j = 0; j < 20000; j++) {
                h[j] = 0;
            }
            for (int j = 0; j < 20000; j++) {
                if (dp[j]) {
                    h[j - a1] = 1;
                    h[j + a1] = 1;
                }
            }
            for (int j = 0; j < 20000; j++) {
                dp[j] = h[j];
            }
        }

        int z = d == 0 ? x : y;
        if (dp[z + 10000]) b++;
    }

    cout << (b == 2 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 512
/*  ex5_3
    hangan2020 */

#include <stdio.h>
#define IS 101

int main(void){
    int H, W;
    int i, j;
    char row[IS][IS];


    scanf("%d %d", &H, &W);
    //Input by loop
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            scanf(" %c", &row[i][j]);
        }
    }

    // Scanning for '.' only rows
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            if(row[i][j] != '.'){
                break;
            }
            else if((j == W -1)&&(row[i][j] == '.')){
                row[i][W] = 'n';// print none(n)
            }
        }
    }
    // Scanning for '.' only columns
    for (j = 0; j < W ; j++){
        for(i = 0; i < H ; i++){
            if(row[i][j] != '.'){
                break;
            }
            else if((i == H-1)&&(row[i][j] == '.')){
                row[H][j] = 'n';// print none(n)
            }
        }
    }

    /*for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            printf("%c", row[i][j]);
        }
        printf("\n");
    }*/

    //Printing out by loop ( except for rows or columns that starts with 'n')
    for (i = 0; i < H ; i++){
        if(row[i][W] != 'n'){
            for(j = 0; j < W ; j++){
                if(row[H][j] != 'n'){
                    printf("%c", row[i][j]);
                }
            }
        printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
a,b,c,d = gets.chomp.split(" ").map(&:to_i)
 
l = c.lcm(d)
 
puts (b - (a-1)) - ( ((b/c) - ((a-1)/c))  + ((b/d) - ((a-1)/d))  ) + ( (b/l) - ((a-1)/l) )

Measured memory_bytes: 1788