akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 1e5 + 10;
vector<int> e[N];
int d[N], p[N];


int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n + m - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        e[x].push_back(y);
        d[y]++;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) if (d[i] == 0) {
        q.push(i);
        break;
    }
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto u : e[v]) {
            d[u]--;
            if (d[u] == 0) {
                p[u] = v;
                q.push(u);
            }
        }
    }
    for (int i = 1; i <= n; i++) printf("%d\n", p[i]);
    return 0;
}


Measured memory_bytes: 7040
n,a,b=map(int,input().split())
if (a+b)%2==0:print((b-a)//2);exit()
aa,bb=1,b-(a-1)
x=0--(bb-aa)//2+a-1
aa,bb=aa+(n-bb),n
y=0--(bb-aa)//2+n-b
print(min(x,y))

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

// 5min
int main(void){
    int a1 = 0, a2 = 0, a3 = 0; 
    int b1 = 0, b2 = 0, b3 = 0;
    int ans = 0;

    scanf("%d%d%d", &a1, &a2, &a3);

    b1 = abs(a1 - a2);
    b2 = abs(a2 - a3);
    b3 = abs(a3 - a1);

    if(b1 >= b2 && b1 >= b3){
        ans = b2 + b3;
    }else if(b2 >= b1 && b2 >= b3){
        ans = b1 + b3;
    }else if(b3 >= b2 && b3 >= b1){
        ans = b2 + b1;
    }

    printf("%d\n", ans);

    return 0;

} 


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ct = 0
while(1) :
  count = 0
  for i in range(n):
    if a[i]%2 != 0:
      count+=1
  if count != 0:
    break
  else:
    a1 = [j/2 for j in a]
    a = a1
    ct += 1
  
print(ct)

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	string s,t;
	cin>>s>>t;
	map<ll,ll> in,out;
	ll n=s.size();
	bool flag=true;
	REP(i,n){
		ll a=s[i]-'a';
		ll b=t[i]-'a';
		if(in.find(b)==in.end()) in[b]=a;
		else if(in[b]!=a) flag=false;
		if(out.find(a)==out.end()) out[a]=b;
		else if(out[a]!=b) flag=false;
	}
	cout<<(flag?"Yes":"No")<<en;
}

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

    solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 916
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    tt = ta = 0
    for i in range(n):
        t, a = list(map(int, input().rstrip('\n').split()))
        if i == 0:
            tt = t
            ta = a
        else:
            r = max((tt + t - 1) // t, (ta + a - 1) // a)
            tt = t * r
            ta = a * r
    print(tt + ta)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38768
n,i=2;main(r){
for(scanf("%d",&n),r=n;i*i<=n;i++)if(n%i==0)for(r=1LL*r*(i-1)/i;n%i==0;n/=i);
if(--n)r=1LL*r*n/++n;
n=!printf("%d\n",r);
}

Measured memory_bytes: 592
#include <stdio.h>
#include <string.h>
int main(void){
    char s[4096],p[4096],s2[4096];
    char *a;
    scanf("%s",s);
    scanf("%s",p);
    sprintf(s2,"%s%s",s,s);
    a=strstr(s2,p);
    if(a){
    puts("Yes");
    }
    else{
    puts("No");
}
    return 0;
}



Measured memory_bytes: 2144
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number  items in a set that are strictly smaller than our item aka index in set
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    //(a*b)%m=((a%m)*(b%m))%m
    int x=0;
    for(int i=0;i<n;i++){
        x+=a[i];
        x%=mod;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        x-=a[i];
        if(x<0)x+=mod;
        ans+=(a[i]*x);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}

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

int main(){
  int N, tmp = 0, max = 0;
  cin >> N;
  vector<int> H(N);

  
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
  }
  
 for(int i = N - 1; i > 0; i--){
    if(H.at(i) <= H.at(i - 1)){
      tmp++;
    }
    else{
      if(max < tmp)
        max = tmp;
      tmp = 0;
    }
  }
  
  if(tmp != 0 && max == 0)
    max = tmp;

  cout << max << endl;

}

Measured memory_bytes: 640
n, m, c = map(int, input().split())
Bs = list(map(int, input().split()))
count = 0
for i in range(n):
    As = list(map(int, input().split()))
    if sum(map(lambda a, b: (a*b), Bs, As)) > -c:
        count += 1

print(count)

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

int main() {
  ll n;
  cin >> n;
  ll count=0;
  for(ll i=1;i<=n;i++) {
    for(ll j=i+1;j<=n;j++) {
      if(n%2) {
        if(i+j!=n) {
          count++;
        }
      }
      else {
        if(i+j!=n+1) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  for(ll i=1;i<=n;i++) {
    for(ll j=i+1;j<=n;j++) {
      if(n%2) {
        if(i+j!=n) {
          cout << i << " " << j << endl;
        }
      }
      else {
        if(i+j!=n+1) {
          cout << i << " " << j << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 256
x, y = gets.split.map(&:to_i)
ans = 0
if x > y
  if x > 0 && y > 0
    ans += 2 + x - y
  elsif x.zero? || y.zero?
    ans += 1 + x.abs + y.abs
  elsif x > 0 && y < 0
    if y.abs > x
      ans += 1 + (y.abs - x)
    else
      ans += 1 + (x.abs - y.abs)
    end
  else
    ans += 2 + (y.abs - x.abs)
  end
else
  if (x > 0 && y > 0) || (x < 0 && y < 0)
    ans += (x - y).abs
  elsif x.zero? || y.zero?
    ans += x.abs + y.abs
  elsif x < 0 && y > 0
    if x.abs > y
      ans += 1 + x.abs - y
    else
      ans += 1 + (y - x.abs)
    end
  end
end
puts ans


Measured memory_bytes: 1788
n, m = map(int, input().split())
GRAPH = [[0]*n for _ in range(n)]
EDGES = []

for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    GRAPH[a][b] = GRAPH[b][a] = 1
    EDGES.append((a, b))


def make_dfs():
    visited = [0]*n

    def inner(v):
        visited[v] = 1
        for v2 in range(n):
            if not GRAPH[v][v2]:
                continue
            if visited[v2]:
                continue
            inner(v2)
        return visited
    return inner


ans = 0
for a, b in EDGES:
    GRAPH[a][b] = GRAPH[b][a] = 0
    dfs = make_dfs()
    if sum(dfs(0)) != n:
        ans += 1
    GRAPH[a][b] = GRAPH[b][a] = 1

print(ans)

Measured memory_bytes: 3064
N,M = map(int,input().split(" "))
L_list = []
R_list = []
for i in range(M):
    L,R = map(int,input().split(" "))
    L_list.append(L)
    R_list.append(R)
if min(R_list) - max(L_list) >= 0:
    print(min(R_list) - max(L_list) +1)
else:
    print(0)

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n;
string pre, cur;

int main()
{
	IOS;
	cin >> n >> pre;
	set <string> s;
	s.insert(pre);
	int fl = 0;
	while (--n) {
		cin >> cur;
		if (pre.back() != cur.front() || s.count(cur)) {
			fl = 1;
		}
		pre = cur;
		s.insert(cur);
	}
	(fl)?cout << "No\n":cout << "Yes\n";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 110;

int n;
char str[MAXN];

int main(){
	scanf("%s", str + 1);
	int n = strlen(str + 1);
	int ans = 0;
	for(int i = 1; i <= (n >> 1); i++)
		if(str[i] != str[n - i + 1]) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
class RMQ{
public:
  RMQ(){}
  RMQ(int n_){
    init(n_);
  }
  void init(int n_){
    n = 1;
    while(n < n_) n *= 2;
    dat.resize(2*n - 1);
    for(int i = 0; i < 2*n - 1; i++) dat[i] = INT_MAX;
  }
  void update(int k,int a){
    k += n - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1)/2;
      dat[k] = min(dat[k*2 + 1], dat[k*2 + 2]);
    }
  }
  void print(){
    for (int i = n - 1; i < 2*n - 1; i++) {
      std::cout << dat[i] << " ";
    }
    std::cout << std::endl;
  }
  lli query(int a,int b,int k = 0,int l = 0,int r = 0){
    if(r <= l) r = n;
    if(r <= a || b <= l) return 1e11;
    if(r <= b && a <= l) return dat[k];
    lli vl = query(a, b, k*2 + 1, l, (r + l)/2);
    lli vr = query(a, b, k*2 + 2, (r + l)/2, r);
    return min(vl,vr);
  }
private:
  int n;
  vector<int>dat;
};

vector<RMQ> makeSegTree(bool f, int mini,
                        vector<vector<int > >& grid){
  vector<RMQ> res(mini);
  int maxi = max(grid.size(), grid[0].size());
  for (int i = 0; i < mini; i++) {
    res[i].init(maxi);
  }
  for (int i = 0; i < mini; i++) {
    for (int j = 0; j < maxi; j++) {
      if(f) res[i].update(j, grid[j][i]);
      else res[i].update(j, grid[i][j]);
    }
  }
  return res;
}
void printGrid(vector<vector<int> >& grid){
  for (int i = 0; i < grid.size(); i++) {
    for (int j = 0; j < grid[0].size(); j++) {
      std::cout << grid[i][j] << " ";
    }
    std::cout << std::endl;
  }
}
int main(){
  int r, c, q;
  while(std::cin >> r >> c >> q){
    if(r == 0 && c == 0)break;
    int mini = min(r, c);
    vector<vector<int> > grid(r, vector<int>(c));
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        std::cin >> grid[i][j];
      }
    }
    vector<RMQ> t = makeSegTree(r > c, mini, grid);
    //for (int i = 0; i < t.size(); i++) {
      //t[i].print();
    //}
    int row, col, rowrow, colcol;
    for (int i = 0; i < q; i++) {
      lli ans = 1e11;
      std::cin >> row >> col >> rowrow >> colcol;
      if(r <= c)swap(col, row),swap(colcol, rowrow);
      //std::cout << col << " " << row << " " << colcol << " " << yy << std::endl;
      for (int j = col; j <= colcol; j++) {
        ans = min(ans, t[j].query(row, rowrow + 1));
      }
      std::cout << ans << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 64008
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int h, w, n; cin >> h >> w >> n;
  if(h > w) swap(h, w);
  cout << ((n + w - 1) / w) << "\n";
}


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

using namespace std;

#define INF 210000000
#define int long long

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
		for(int i=0;i<3;i++){
				char tmp;
				cin >> tmp;
				if(tmp == '1'){
						cout << 9;
				}else if(tmp == '9'){
						cout << 1;
				}
		}
		cout << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 100005
char dr[M];
int ans[M];
int main(){
	scanf("%s",dr+1);
	int n=strlen(dr+1);
	for(int i=n,pr;i>=1;--i){
		if(dr[i]=='L')pr=i;
		else ans[pr-((pr-i)&1)]++;
	}
	for(int i=1,pr;i<=n;++i){
		if(dr[i]=='R')pr=i;
		else ans[pr+((i-pr)&1)]++;
	}
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    string out = S.substr(0, 1);
    int now_len = 1;
    reps(i, N, 1)
    {

        if (S[i] != out[now_len - 1])
        {
            out += S.substr(i, 1);
            now_len++;
        }
    }
    cout << now_len << endl;
    //system("pause");
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

void solve() {
  string s; cin >> s;
  long long ans = 0;
  for (int i = 0, count = 0; i < (int)s.size()-1; ++i) {
    if (s[i] == 'A') {
      ++count;
      continue;
    }
    if (s[i] == 'B' && s[i+1] == 'C') {
      ans += count;
      ++i;
    } else {
      count = 0;
    }
  }
  cout << ans;
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

bool isprime[N];
int main(){
  int n; scanf("%d",&n);
  ll ans =1; 
  REPP(i,2,N){
    if(isprime[i]==0){
      for(int j=i+i;j<1005;j+=i) isprime[j]=1;
      int x=0;
      int y=n;
      while(y>0){
        x+=y/i; y/=i;
      }
      ans=ans*(x+1)%mod;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 5e6 + 5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int arr[N];

void solve()
{
	int n, k;
	cin >> n >> k;
	int mx = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		mx = max(mx, arr[i]);
	}
	int s = 1;
	int e = mx;
	while(s <= e)
	{
		int mid = s + e >> 1;
		int steps = 0;
		for(int i = 0; i < n; i++)
		{
			steps += arr[i] / mid;
			if(arr[i] % mid == 0) steps--;
		}
		if(steps <= k)
		{
			e = mid - 1;
		}
		else
		{
			s = mid + 1;
		}
	}
	cout << e + 1 << endl;
}
 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 5212
n = int(input())
a = list(map(int, input().split()))
import collections
l1 = collections.Counter(a).most_common()
l1.sort()
if len(l1) > 2:
    print("No")
elif len(l1) == 1:#発言が１種類の場合
    if l1[0][0] * 2 <= n or l1[0][0] == n - 1:
        print("Yes")
    else:
        print("No")
else:
    if l1[1][0] - l1[0][0] > 1:
        print("No")
    elif l1[1][1] >= (l1[1][0] - l1[0][1]) * 2 and l1[1][0] > l1[0][1]:
        print("Yes")#多い発言の人数が残りの色数かけ２より多い、全体色数が少ない発言の人数より多い
    else:
        print("No")

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

int main(){
  string S;
  cin >> S;

  long long ans = 0;

  int first_lt_idx = 0;
  while(first_lt_idx < S.length() && S[first_lt_idx] != '<'){
    first_lt_idx++;
  }
  ans += static_cast<long long>(first_lt_idx) * (first_lt_idx + 1) / 2;
  if(first_lt_idx == S.length()){
    // S == ">>>>>"
    cout << ans << endl;
    return 0;
  }
  
  int last_gt_idx = S.length() - 1;
  while(last_gt_idx >= 0 && S[last_gt_idx] != '>'){
    last_gt_idx--;
  }
  ans += static_cast<long long>(S.length() - last_gt_idx) * (S.length() - last_gt_idx - 1) / 2;
  if(last_gt_idx == -1){
    // S == "<<<<"
    cout << ans << endl;
    return 0;
  }

  int up_cnt = 0, down_cnt = 0;
  for(int i = first_lt_idx; i <= last_gt_idx; i++){
    if(S[i] == '<'){
      if(down_cnt != 0){
        long long x = min(up_cnt, down_cnt), y = max(up_cnt, down_cnt);
        ans += y * (y + 1) / 2 + x * (x - 1) / 2;
        up_cnt = 1;
        down_cnt = 0;
      }else{
        up_cnt++;
      }
    }else{
      down_cnt++;
    }
  }
  long long x = min(up_cnt, down_cnt), y = max(up_cnt, down_cnt);
  ans += y * (y + 1) / 2 + x * (x - 1) / 2;
  cout << ans << endl;
}



Measured memory_bytes: 1148
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    string s;cin >> s;
    int A,Z;
    REP(i,s.size()){
        if(s.at(i)=='A'){
            A=i;
            break;
        }
    }
    REP(i,s.size()){
        if(s.at(i)=='Z'){
            Z=i;
        }
    }
    COUT(Z-A+1);
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int maxx;
  int l;
  int sum=0;
  for (int i=0;i<N;i++){
    cin >> l;
    sum+=l;
    maxx=max(l,maxx);
  }
  string ans=sum>maxx*2?"Yes":"No";
  cout << ans << endl;
  return 0;
}


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

int main() {
	cout << fixed << setprecision(15);
	double a, b, x;
	cin >> a >> b >> x;
	x = x / a;
	double ans;
	if (x <= a * b * 0.5) {
		double y = x * 2.0 / b;
		ans = atan(b / y);
		ans = ans * 180.0 / 3.14159265358979;
	}
	else {
		double y = (a * b - x) * 2.0 / a;
		ans = atan(y / a);
		ans = ans * 180.0 / 3.14159265358979;
	}
	cout << ans << endl;
}

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

int size = 1;
long MAX = (1l << 31) - 1;
vector<long> segtree;

void change(int k, long x){
    k += size - 1;
    segtree[k] = x;
    while(k > 0){
        k = (k - 1) / 2;
        segtree[k] = min(segtree[k * 2 + 1], segtree[k * 2 + 2]);
    }
}

long minimum(int a, int b, int l, int r, int now){
    if(r <= a || b <= l){
        return MAX;
    }else if(a <= l && r <= b){
        return segtree[now];
    }else{
        return min(minimum(a, b, l, (l + r) / 2, now * 2 + 1), minimum(a, b, (l + r) / 2, r, now * 2 + 2));
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    while(size < n){
        size *= 2;
    }
    segtree.resize(size * 2 - 1, MAX);
    for(int i = 0; i < q; i++){
        int com;
        cin >> com;
        if(com){
            int x, y;
            cin >> x >> y;
            cout << minimum(x, y + 1, 0, size, 0) << endl;
        }else{
            int x, y;
            cin >> x >> y;
            change(x, y);
        }
    }
}



Measured memory_bytes: 4960
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main(){
   int n; cin>>n;
   set<string> s;
   for(int i=0;i<n;i++){
      string a; cin>>a;
      s.insert(a);
   }
   cout<<s.size()<<endl;
   return 0;
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
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;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5;
const int sz = 'Z' - 'A' + 1;

int n;
string s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> s;
    for (auto &c: s)
    {
        c = ((c - 'A') + n) % sz + 'A';
    }
    cout << s;
    return 0;
}


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

using db = double;
const db eps = 1e-6;

struct poi {
	db x, y;
	void r() { cin >> x >> y; }
	poi operator -(poi p) {
		return {x - p.x, y - p.y};
	}
	db cross(poi p) {
		return x * p.y - y * p.x;
	}
};
db xmul(poi a, poi b, poi c) {
	return (b - a).cross(c - a);
}

int main() {
	ios :: sync_with_stdio(false);
	poi a, b, c, p;
	while(cin >> a.x >> a.y) {
		b.r(); c.r(); p.r();
		db s = abs(xmul(a, b, c));
		db t = abs(xmul(p, a, b)) + abs(xmul(p, b, c)) + abs(xmul(p, c, a));
		if(s < t + eps && t < s + eps)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 3084
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;




int main() {
	
	int n;
	cin>>n;
	long long int a,b,c;
	cin>>a>>b;c=a+b;
	for(int i=1;i<n;i++){
		long long int x,y,z;
		cin>>x>>y;
		long long int p=max((a+x-1)/x,(b+y-1)/y);
		
		a=p*x;
		b=p*y;
	
		
	}
	cout<<a+b<<endl;

    return 0;
}

	
	


	

Measured memory_bytes: 256
import java.util.Scanner;
//2-3
public class Main{
    public static void main(String [] args){
    	Scanner scan=new Scanner(System.in);
    	String s=scan.next();
    	StringBuilder sb = new StringBuilder(s);
    	int a=Integer.parseInt(sb.substring(0, 2));
    	int b=Integer.parseInt(sb.substring(2,4));

    	boolean c=false;
    	boolean d=false;
    	//System.out.println(a+" "+b);
    	if(a<=12 && a>0) {
    		c=true;
    	}
    	if(b<=12 && b>0) {
    		d=true;
    	}

    	if(c&&d) {
    		System.out.println("AMBIGUOUS");
    	}else if(c) {
    		System.out.println("MMYY");
    	}else if(d) {
    		System.out.println("YYMM");
    	}else {
    		System.out.println("NA");
    	}
    }
}

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

int main() {
  int N;
  cin >> N;
  int sum;
  for (int i = 0; true ; i++){
    int A = 1;
    
    for (int j = 0; j < i; j++){
      A *= 10;
    }
    
    if (N / A  == 0){
      break;
    }
    sum += (N % (10 * A) - N % A) / A;
  }
  
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll H, W;
    cin >> H >> W;
    if ((H == 1) || (W == 1))
    {
        cout << 1 << endl;
    }
    else if ((H % 2 == 0) || (W % 2 == 0))
    {
        cout << H * W / 2 << endl;
    }
    else
    {
        cout << H * W / 2 + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef complex<long double> base;
const double pi=acos(-1.);
const int MX=132132,md=998244353;
int n,m,it,ut,i,x,y,res,u[MX],a[3][MX],mx[3];
long long cnt[3][MX];
vector<int> g[MX];
long long pw10(long long x) {
  if (x==0) return 1LL;
  if (x&1) return (pw10(x-1)*10LL)%md;
  long long z=pw10(x/2);
  return (z*z)%md;
}
int main() {
  scanf("%d",&n);
  for (it=0; it<3; it++) {
    for (i=1; i<=n; i++) g[i].clear();
    scanf("%d",&m);
    while (m--) {
      scanf("%d%d",&x,&y);
      g[min(x,y)].push_back(max(x,y));
    }
    for (i=n; i>0; i--) {
      ++ut;
      for (x=0; x<g[i].size(); x++) u[a[it][g[i][x]]]=ut;
      for (a[it][i]=0; u[a[it][i]]==ut; a[it][i]++);
      cnt[it][a[it][i]]=(cnt[it][a[it][i]]+pw10(18*i))%md;
      mx[it]=max(mx[it],a[it][i]);
    }
  }
  for (i=0; i<=mx[0]; i++) if (cnt[0][i]) for (x=0; x<=mx[1]; x++) if (cnt[1][x] && cnt[2][i^x])
    res=(res+((cnt[0][i]*cnt[1][x])%md)*cnt[2][i^x])%md;
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
const int maxn=131172;
int h[maxn],mem;
struct
{
    int v,w,next;
}e[maxn];
long long mid;
void add(int u,int v,int w)
{
    e[mem].v=v;
    e[mem].w=w;
    e[mem].next=h[u];
    h[u]=mem++;
}
vector<pair<long long,long long> > q[maxn];
bool cmp1(pair<long long,long long> a,pair<long long,long long> b)
{
    if(a.first!=b.first) return a.first<b.first;
    return a.second<b.second;
}
bool cmp2(pair<long long,long long> a,pair<long long,long long> b)
{
    if(a.second!=b.second) return a.second<b.second;
    return a.first<b.first;
}
void Merge(int f,int l,int r)
{
    if(q[l].size()>q[r].size())
        swap(l,r);
    if(q[l].size()==0) return ;
    sort(q[l].begin(),q[l].end(),cmp2);
    sort(q[r].begin(),q[r].end(),cmp1);

    long long mi=-1;
    int s=0;
    for(int i=q[l].size()-1;i>=0;i--)
    {
        while(s<q[r].size()&&q[r][s].first+q[l][i].second<=mid){
            if(mi==-1) mi=q[r][s].second;
            else mi=min(mi,q[r][s].second);
            s++;
        }
        if(mi!=-1){
            q[f].push_back(make_pair(q[l][i].first,mi));
        }
    }

    mi=-1;
    s=0;
    sort(q[l].begin(),q[l].end(),cmp1);
    sort(q[r].begin(),q[r].end(),cmp2);

    for(int i=q[l].size()-1;i>=0;i--)
    {
        while(s<q[r].size()&&q[r][s].second+q[l][i].first<=mid){
            if(mi==-1) mi=q[r][s].first;
            else mi=min(q[r][s].first,mi);
            s++;
        }
        if(mi!=-1){
            q[f].push_back(make_pair(mi,q[l][i].second));
        }
    }
}

void dfs(int u)
{
    q[u].clear();
    if(h[u]==-1)
    {
        q[u].push_back(make_pair(0,0));
        return ;
    }
    int ls=0,rs,lw,rw;
    for(int i=h[u];i+1;i=e[i].next)
    {
        int v=e[i].v;
        dfs(v);
        if(ls==0){
            ls=v;
            lw=e[i].w;
        }
        else{
            rs=v;
            rw=e[i].w;
        }
    }
    for(int i=0;i<q[ls].size();i++)
    {
        q[ls][i].first+=lw;
        q[ls][i].second+=lw;
    }
    for(int i=0;i<q[rs].size();i++)
    {
        q[rs][i].first+=rw;
        q[rs][i].second+=rw;
    }
    Merge(u,ls,rs);
//    printf("%d-----\n",u);
//    for(int i=0;i<q[u].size();i++)
//        printf("%lld %lld\n",q[u][i].first,q[u][i].second);
}
int main()
{
    int n;
    scanf("%d",&n);
    memset(h,-1,sizeof(h));mem=0;
    for(int i=2;i<=n;i++)
    {
        int v,w;
        scanf("%d%d",&v,&w);
        add(v,i,w);
    }
    long long l=0,r=1LL*maxn*maxn;
    long long ans;
    //dfs(1);
    while(l<=r)
    {
        mid=(l+r)>>1;
        dfs(1);
        if(q[1].size()){
            r=mid-1;ans=mid;
        }
        else l=mid+1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 27380
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

// #define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int k, x; cin >> k >> x;

  for (int i = max(-1000000,x - k + 1); i < min(1000000 + 1, x + k); ++i) {
    cout << i << " ";
  }
  cout << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
     int x;

     scanf("%d",&x);

     if(x >= 400 && x < 600){
         printf("8\n");
     }else if(x < 800){
         printf("7\n");
     }else if(x < 1000){
         printf("6\n");
     }else if(x < 1200){
         printf("5\n");
     }else if(x < 1400){
         printf("4\n");
     }else if(x < 1600){
         printf("3\n");
     }else if(x < 1800){
         printf("2\n");
     }else if(x < 2000){
         printf("1\n");
     }
     return 0;



    
}

Measured memory_bytes: 1660
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

const int N = 2e3 + 5;

ll n, m, dp[N][N];

int main(){
   IOS

   cin>>n>>m;

   vi s(n), t(m);

   for(int &x : s)cin>>x;
   for(int &x: t)cin>>x;

   memset(dp, 0, sizeof dp);

   for(int i = 0; i <= m; i++){
       dp[0][i] = 1;
   }
   for(int i = 0; i <= n; i++){
       dp[i][0] = 1;
   }

   for(int i = 1; i <= n; i++){
       for(int j = 1; j <= m; j++){
           if(s[i-1] == t[j-1]){
               dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % mod;
           }else{
               dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] + mod)%mod;
           }
       }
   }

 
   cout<<dp[n][m]<<"\n";










    







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
int N, M, a[50], b[50];

bool coneCheck(int r, int s, int t){
int d=1, c[N+1]={}; c[s]=1;
while(d){ d=0;
   for(int i=0; i<M; i++){
     if((c[a[i]]^c[b[i]])&&(i!=r)){ c[a[i]]=c[b[i]]=d=1; }
   }
}
if(c[t]==1){ return true; }else{ return false; }
}

int main(){
cin >> N >> M;
for(int i=0; i<M; i++){ scanf("%d", &a[i]); scanf("%d", &b[i]); }

int c=0;
for(int i=0; i<M; i++){ if(!coneCheck(i, a[i], b[i])){c++;} }
cout << c << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;


int main() {
	int x = 0, ans = 0;
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') {
			x++;
		}
		else {
			x--;
		}
		if (ans < x) {
			ans = x;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n, mod = 1e9 + 7;
	scanf("%lld", &n);
	ll a[n], s = 0, ans = 0;
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]), s += a[i];
	}
	for (int i = 0; i < n; i++){
		s -= a[i];
		(ans += (a[i] * (s % mod) % mod)) %= mod;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 5344
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define db long double
#define ll long long
#define inf 2333333333333333.233
using namespace std;

struct L{
	db k,b;
}l[44000];
int n,id=0;
db now;
ll aim;

int c[44000];
struct Node{
	db w;
	int pos;
}nd[44000];

bool xxx(L l1,L l2){
	return l1.k>l2.k;
}
bool yyy(L l1,L l2){
	return ( (l1.k<0.0) ^ (l2.k<0.0) )?  l1.k>l2.k :l1.k<l2.k;
}

bool cmp(Node d1,Node d2){
	return d1.w<d2.w;
}

void add(int x){
	for (;x<=n;x+=x&-x) c[x]++;
}
int que(int x){
	int t=0; for (;x;x-=x&-x) t+=c[x]; return t;
}

ll doitx(){
	memset(c,0,sizeof c);
	ll res=0;
	for (int i=1;i<=n;i++){
		nd[i]=(Node){l[i].k*now+l[i].b,i};
	}
	sort(nd+1,nd+n+1,cmp);
	for (int i=1;i<=n;i++){
		add(nd[i].pos);
		res+=i-que(nd[i].pos);
	}
	return res;
}

ll doity(){
	memset(c,0,sizeof c);
	ll res=0;
	for (int i=1;i<=n;i++){
		nd[i]=(Node){(now-l[i].b)/l[i].k,i};
	}
	sort(nd+1,nd+n+1,cmp);
	for (int i=1;i<=n;i++){
		add(nd[i].pos);
		res+=i-que(nd[i].pos);
	}
	return res;
}

int main(){
	scanf("%d",&n);
	aim=((ll)n*(n-1)/2+1)/2;
	int x,y,z;
	for (int i=1;i<=n;i++){
		scanf("%d%d%d",&x,&y,&z);
		l[i].k=-(db)x/y; l[i].b=(db)z/y;
	}
	
	sort(l+1,l+n+1,xxx);
	db st=-inf,en=inf;
	for (int i=1;i<=100;i++){
		now=(st+en)/2.0;
		if (doitx()>=aim){
			en=now;
		}else{
			st=now;
		}
	}
	printf("%.20lf ",(double)(st+en)/2.0);
	
	sort(l+1,l+n+1,yyy);
	st=-inf,en=inf;
	for (int i=1;i<=100;i++){
		now=(st+en)/2.0;
		if (doity()>=aim){
			en=now;
		}else{
			st=now;
		}
	}
	printf("%.20lf",(double)(st+en)/2.0);
}

Measured memory_bytes: 3072
#include <cstdio>

#define MAX 200000

int main(){

  int n, T;
  int t[MAX];
  long long ans = 0;

  scanf("%d %d", &n, &T);
  for(int i = 0; i < n; i++)
    scanf("%d", &t[i]);

  for(int i = 0; i < n - 1; i++){
    int tmp = t[i + 1] - t[i];
    if(tmp < T)
      ans += tmp;
    else
      ans += T;
  }

  ans += T;

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> pii;
#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d",&a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
int mod = 1e9 + 7;
const int N = 1e6 + 10;
const double pi = acos(-1.0);

int a[N],n;
int V(int b) {
	ll res = 0;
	f(i, 1, n)res += (a[i] - b) * (a[i] - b);
	return res;
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	int l=-100, r=100;
	int k = 20; int res = inf;
	sf(n);
	f(i, 1, n)sf(a[i]);
	while (k--) {
		int L = l + (r - l) / 3;
		int R = r - (r - l) / 3;
		int lval = V(L), rval = V(R);
		if (lval < rval)r = R; else l = L;
		res = min(res,min(lval, rval));
	}
	cout << res;
}

Measured memory_bytes: 256
(n, m) = map(int, input().split())
stores = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
cost = 0
for store in stores:
    if store[1] < m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        break
print(cost)


Measured memory_bytes: 29788
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
const int mod=2019;
int head[maxm],nt[maxm],to[maxm],cnt;
int a[maxm],b[maxm];
int c[maxm],d[maxm];
int mark[55][2505];
int dp[55][2505];
int n,m,s;
struct Node{
    int i,j,v;
    bool operator<(const Node& a)const{
        return v>a.v;
    }
};
void add(int x,int y,int aa,int bb){
    cnt++;nt[cnt]=head[x];head[x]=cnt;to[cnt]=y;
    a[cnt]=aa;b[cnt]=bb;
}
void dj(){
    priority_queue<Node>q;
    memset(dp,0x3f,sizeof dp);
    s=min(s,2500LL);
    dp[1][s]=0;
    q.push({1,s,dp[1][s]});
//    cout<<dp[1][s]<<endl;
    while(!q.empty()){
        int ii=q.top().i,jj=q.top().j,vv=q.top().v;
        q.pop();
        if(mark[ii][jj])continue;
        mark[ii][jj]=1;//标记.
        for(int i=head[ii];i;i=nt[i]){
            int v=to[i];
            if(jj<a[i])continue;
            if(dp[v][jj-a[i]]>dp[ii][jj]+b[i]){
                dp[v][jj-a[i]]=dp[ii][jj]+b[i];
                q.push({v,jj-a[i],dp[v][jj-a[i]]});
            }
        }
        if(jj<2500){
            jj+=c[ii];
            jj=min(jj,2500LL);
            vv+=d[ii];
            if(dp[ii][jj]>vv){
                dp[ii][jj]=vv;
                q.push({ii,jj,vv});
            }
        }
    }
}
signed main(){
    ios::sync_with_stdio(0);
    cin>>n>>m>>s;
    for(int i=1;i<=m;i++){
        int u,v,a,b;cin>>u>>v>>a>>b;
        add(u,v,a,b);
        add(v,u,a,b);
    }
    for(int i=1;i<=n;i++){
        cin>>c[i]>>d[i];
    }
    dj();
    for(int i=2;i<=n;i++){
        int ans=1e18;
        for(int j=0;j<=2500;j++){
            ans=min(ans,dp[i][j]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*
令dp[i][j]表示点i处,j块钱的最小时间,
利用最短路完成转移即可.

因为a(i)最大50,n最大50,
那么走遍整个图最多50*50=2500,
(如果按a(i)*m算也只有50*100=5000)
因此第二维开2500(或者5000)就行了.
*/


Measured memory_bytes: 8436
import sys
m,d=map(int,input().split())
ct=0
if d<=10:
  print(0)
  sys.exit()
for i in range(10,d+1):
  l=list(str(i))
  if int(l[0])*int(l[1])<=m and 0<int(l[0])*int(l[1]) and int(l[0])>1 and int(l[1])>1:
    ct+=1
print(ct)

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
	string A;
	cin >> A;
	ll N = A.size();
	map<char, ll> m;
	REP(i, N) {
		m[A[i]]++;
	}
	ll ans = (N*(N-1))/2;
	for(pair<char, ll> p : m) {
		ans -= (p.second*(p.second-1))/2;
	}
	PRINT(ans+1);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <cstring>
#include <cstdio>
#include <cmath>
 
using namespace std;
 
int f(const int);
 
int main()
{
    int N;
    int num=1,old[2]={1,1};
    cin>>N;
    for(int i=1;i<N;i++){
        num=old[0]+old[1];
        old[0]=old[1];
        old[1]=num;
    }
    cout<<num<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    vector<int> V(n);
    rep(i,n) cin>>V[i];

    map<int,int> cnt[2];
    rep(i,n) cnt[i%2][V[i]]++;

    vector<pair<int,int>> v[2];
    rep(i,2){
        for(auto p : cnt[i]) v[i].push_back({p.second,p.first});
        sort(all(v[i]));
        reverse(all(v[i]));
    }

    if(v[0][0].second!=v[1][0].second){
        int ans=n-v[0][0].first-v[1][0].first;
        cout<<ans<<endl;
        return 0;
    }

    if(v[0].size()==1 && v[1].size()==1){
        int ans=n/2;
        cout<<ans<<endl;
        return 0;
    }

    int ans=INF;
    if(2<=v[0].size()) ans=min(ans,n-v[0][1].first-v[1][0].first);
    if(2<=v[1].size()) ans=min(ans,n-v[0][0].first-v[1][1].first);

    cout<<ans<<endl;
}

Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
	cin >> n;

	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

mod = 10**9+7

SA = set(A)
SB = set(B)
A.sort()
B.sort()

if len(SA) != len(A) or len(SB) != len(B):
    print(0)
    exit()

ans = 1
import bisect
for i in reversed(range(1, n*m+1)):
    if i in SA and i in SB:
        ans *= 1
    elif i in SA:
        j = bisect.bisect_left(B, i)
        ans *= m-j
    elif i in SB:
        j = bisect.bisect_left(A, i)
        ans *= n-j
    else:
        j = bisect.bisect_left(A, i)
        k = bisect.bisect_left(B, i)
        ans *= (n-j)*(m-k) - (n*m-i)
    ans %= mod
print(ans)

Measured memory_bytes: 45096
fun main(args: Array<String>) {
    abc141a()
}

fun abc141a() {
    val answer = when (readLine()!!) {
        "Sunny" -> "Cloudy"
        "Cloudy" -> "Rainy"
        "Rainy" -> "Sunny"
        else -> ""
    }

    println(answer)
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const double PI = acos(-1);
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n), b(n+1);
	rep(i, n) cin >>a[i];
	rep(i, n) b[a[i]] = i+1;
	rep2(i, 1, n+1) cout <<b[i] <<" ";
	cout <<"\n";
	return 0;
	
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp; cin >> temp; return temp;
}

template <typename VType = int>
list<VType> const LR(VType start, VType end) {
    list<VType> ret; for (VType i = start; i < end; i++) ret.push_back(i); return move(ret);
}

int main() {
    int A(in()), P(in());
    cout << (A * 3 + P) / 2 << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin >> s){
		if(s=="0")
			break;
		int ans = 0;
		for(int i=0; i<s.size(); i++){
			if(s[i]>='0' && s[i]<='9')
				ans += s[i]-'0';
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){ return (a%m + b%m+2*m)%m;}

ll mul(ll a, ll b, ll m = MOD){ return ((a%m+m)*(b%m+m))%m;}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100000+5;

int n, m;
vi G[N];
bool vis[N];
int memo[N];

int DP(int u){
	if(vis[u]) return memo[u];
	int ans = 0;
	for(int i=0; i<G[u].size(); i++){
		int v = G[u][i];
		ans = max(ans,1+DP(v));
	}
	vis[u] = true;
	return memo[u] = ans;
}

int main(){
	ri2(n,m);
	int a, b;
	for(int i=0; i<m; i++){
		ri2(a,b);
		G[a].pb(b);
	}
	int ans = 0;
	for(int i=1; i<=n; i++){
		ans = max(ans,DP(i));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8192
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        SortedMap<Integer, Long> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            long num = Long.parseLong(sc.next());
            map.merge(temp, num, (v1, v2) -> v1 + v2);
        }
        long ans = 0;
        for (int i = 0; i < m; i++) {
            int temp = map.firstKey();
            ans += temp;
            long num = map.get(temp) - 1;
            if (num == 0) {
                map.remove(temp);
            } else {
                map.put(temp, num);
            }

        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 70916