akhauriyash/Code-Regression huggingface dataset:
#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 all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
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;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

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));
}

class UnionFind {
 vector<int> data;
 int num;
public:
 UnionFind(int size) : data(size, -1), num(size) { }
 bool unionSet(int x, int y) {
  x = root(x); y = root(y);
  if (x != y) {
   if (data[y] < data[x]) swap(x, y);
   data[x] += data[y]; data[y] = x;
   num--;
  }
  return x != y;
 }
 bool findSet(int x, int y) {
  return root(x) == root(y);
 }
 int root(int x) {
  return data[x] < 0 ? x : data[x] = root(data[x]);
 }
 int size(int x) {
  return -data[root(x)];
 }
 int numSet() {
  return num;
 }
};

void solve(){
    ll n;
    cin>>n;
    ll m=101010;
    UnionFind uni(2*m);
    Graph g(2*m);
    REP(i,n){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        add_edge(g,x,y+m,1,true,1);
        uni.unionSet(x,y+m);
    }

    Matrix con(2*m,Array(2,0));
    Matrix con2(2*m,Array(2,0));
    REP(i,m){
        con2[uni.root(i)][0]++;
        con[uni.root(i)][0]+=g[i].size();
        con2[uni.root(i+m)][1]++;
        con[uni.root(i+m)][1]+=g[i+m].size();
    }
    
    ll ans=0;
    Array used(2*m,false);
    REP(i,2*m){
        ll r = uni.root(i);
        if(used[r]) continue;
        used[r]=true;
        ans += con2[r][0]*con2[r][1]-(con[r][0]+con[r][1])/2;
    }
    cout<<ans<<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: 35968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000009
using namespace std;
using ll = long long;
int main()
{
    vector<int> v = {1,
                     1,
                     1,
                     2,
                     1,
                     2,
                     1,
                     5,
                     2,
                     2,
                     1,
                     5,
                     1,
                     2,
                     1,
                     14,
                     1,
                     5,
                     1,
                     5,
                     2,
                     2,
                     1,
                     15,
                     2,
                     2,
                     5,
                     4,
                     1,
                     4,
                     1,
                     51};
    int k;
    cin >> k;
    cout << v[k - 1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(void){
  int n;
  cin >> n;
  int a[n];
  rep(i, n)
    cin >> a[i];
  //ここまで入力

  //trueのときは先頭から見て，falseのときは末尾から見る
  bool front = true;
  
  list<int> b;
  rep(i, n){
    //先頭から見る
    if(front == true){
      b.push_back(a[i]);
      //次は末尾から見る
      front = false;
    }
    //末尾から見る
    else if(front == false){
      b.push_front(a[i]);
      //次は先頭から見る
      front = true;
    }
  }

  //末尾フラッグが立っていれば反転させる
  if(front == false)
    b.reverse();
  
  //解答用出力
  for(auto x : b)
    cout << x << " ";
  cout << endl;
  
  return 0;
}


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

using namespace std;

int check(int pos, vector< pair<char, char> > spell, string squares, int length){

    char square = squares[pos];
    //cout << endl << square;

    for (auto it : spell) {

        if (pos == length) {
            return 1;
        } else if (pos == 0) {
            return -1;
        }
        
        if (square == it.first) {
            if (it.second == 'L') {
                pos--;
                square = squares[pos];
            } else if (it.second == 'R') {
                pos++;
                square = squares[pos];
            }
        }

    }

    if (pos == length) {
        return 1;
    } else if (pos == 0) {
        return -1;
    }
    return 0;
}

int bs1(int left, int right, vector< pair<char, char> > spell, string squares, int length) {

    int ans = 0;
    while (left <= right) {

        int mid = (left + right) / 2;
        if (check(mid, spell, squares, length) == -1) {
            ans = mid;
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }

    return ans;
}

int bs2(int left, int right, vector < pair<char, char> > spell, string squares, int length){

    int ans =  length;
    while (left <= right) {
        int mid = (right + left) / 2;
        if (check(mid, spell, squares, length) == 1) {
            ans = mid;
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }

    return ans;
}

int main()
{
    int n, q;
    vector < pair<char, char> > spell;
    string squares;
    cin >> n >> q;
    cin >> squares;
    squares = "0" + squares + "0";
    //cout << squares;
    
    for (int i = 0; i < q; i++) {
        char t, d;
        cin >> t >> d;
        //cout << t << " " << d << endl;

        spell.push_back(make_pair(t, d));
    }

    int res1 = bs1(1, n, spell, squares, n + 1);
    int res2 = bs2(1, n, spell, squares, n + 1);
    int res = n - (res1 + n + 1 - res2);

    cout << res << endl;
    return  0;
}

Measured memory_bytes: 1884
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n, m, l = getList()

INF = 10 ** 10
vers = [[INF for j in range(n)] for i in range(n)]

for i in range(n):
    vers[i][i] = 0

for _ in range(m):
    a, b, c = getList()
    if c <= l:
        vers[a-1][b-1] = c
        vers[b - 1][a - 1] = c

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

d2 = warshall_floyd(vers)

new_vers = [[INF for j in range(n)] for i in range(n)]
for i in range(n):
    new_vers[i][i] = 0

for i in range(n):
    for j in range(n):
        if i != j and d2[i][j] <= l:
            new_vers[i][j] = 1

d3 = warshall_floyd(new_vers)

# print(d3)
Q = getN()

for _ in range(Q):
    a, b = getList()
    if d3[a-1][b-1] == INF:
        print(-1)
    else:
        print(d3[a - 1][b - 1] - 1)


Measured memory_bytes: 57820
N = int(input())
S = input()
min = S[1:N].count("E")
now = S[1:N].count("E")

for i in range (1,N):
    if S[i-1] == "E" and S[i] == "E":
        now -= 1
    if S[i-1] == "W" and S[i] == "W":
        now += 1
    if now < min:
        min = now
print(min)


Measured memory_bytes: 3700
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int tc;cin>>tc;while(tc--)
#define N 100003
#define M 103
#define inf LLONG_MAX
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//int mod=1e9+7;
//int mod=998244353;

signed main()
{
    SPEED

    int n,m;
    cin>>n>>m;
    int a[n+1],i,j,b[m+1],c[m+1];
    pii p[m+1];
    for(i=1;i<=n;++i)
        cin>>a[i];
    for(i=1;i<=m;++i)
        cin>>b[i]>>c[i],p[i]={c[i],b[i]};
    sort(a+1,a+n+1);
    sort(p+1,p+m+1,greater<pii>());
    
    i=1;
    j=1;
    int t1=p[i].first,t2=p[i].second;
    while(j<=n and i<=m)
    {
        while(j<=n and t2 and a[j]<t1)
            a[j++]=t1,--t2;
        if(j>n or a[j]>=t1)
            break;
        ++i;
        t1=p[i].first,t2=p[i].second;
    }
    
    int ans=0;
    for(i=1;i<=n;++i)
        ans+=a[i];
    
    cout<<ans;
    
    
    
    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

const int mxq = 60;
int n, m, q;
int mx = 0, cnt = 0;
vector<int> A;
struct quad{
    int a, b, c, d;
};
quad arr[mxq];
void solve(int cur = 1, int sz = 0){
    if(sz == n){
        int sum = 0;
        for(int i = 1; i <= q; ++i){
            cnt++;
            if(A[arr[i].b-1] - A[arr[i].a-1] == arr[i].c) sum += arr[i].d;
        }
        mx = max(sum, mx);
        return;
    }
    for(int i = cur; i <= m; ++i){
        A.push_back(i);
        solve(i, sz+1);
        A.pop_back();
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i = 1; i <= q; ++i) arr[i] = {input(), input(), input(), input()};
    solve();
    cout << mx;
    return 0;
}


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

int main(void) {
    string S;cin>>S;
    if (S == "abc" || S == "acb" || S == "bac" || S == "bca" || S == "cab" || S == "cba") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int mod;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int a,int b){
    int ret=1;
    while(b){
        if(b&1)ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}

int C[333][333];

int N,K;

vint A;

signed main(){
    
    cin>>N>>K>>mod;
    rep(i,333){
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    }


    vint dp(N+1);
    for(int i=K-1;i>=0;i--){
        vint dp2(N+1);
        dp2[1]=1;
        for(int j=2;j<=N;j++){
            for(int k=1;k<j;k++){
                add(dp2[j],dp2[j-k]*dp[k]%mod*C[j-2][k-1]%mod);
            }
        }
        rep(j,N+1)add(dp[j],dp2[j]);
    
    }

    vint ans(N+1);
    ans[0]=1;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=i;j++)add(ans[i],ans[i-j]*dp[j]%mod*C[i-1][j-1]%mod);
    }
    cout<<ans[N]<<endl;
    return 0;
}


Measured memory_bytes: 1152
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

int main(){
  // Failed to predict input format
  ll r,x,d;
  cin >> r >> d >> x ;
  ll temp = x;
  rep(i,10){
    temp = r*temp-d;
    cout << temp << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
ls = [[_ for _ in input()] for _ in range(n)]

lssorted = [''] * n

for i in range(n):
	ls[i].sort()
	lssorted[i] = ''.join(ls[i])

lssorted.sort()


cnt = 1
ans = 0

for j in range(1, n):
	if lssorted[j] == lssorted[j - 1]:
		cnt += 1
		if j == n - 1:
			ans += cnt * (cnt - 1) / 2
	else:
		ans += cnt * (cnt - 1) / 2
		cnt = 1

print(int(ans))

Measured memory_bytes: 31820
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
int digit(int a){
    int count = 0;
    for (int i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }     
    }
    return count;
}
//pow(x,n) == x^n

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

int n,sum = 0;
cin >> n;
int x = n;
while(1){
    if (x != 0)
    {
        sum += x%10;
        x /= 10;
    }else
    {
        break;
    }
}
if (n % sum == 0)
{
    cout << "Yes" << endl;
}else
{
    cout << "No" << endl;
}





//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n), h(n);
  vector<pair<int, int>> edges;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    g[a].emplace_back(b);
    h[b].emplace_back(a);
    edges.emplace_back(a, b);
  }

  const int inf = 1e9;
  for (auto e : edges) {
    int src, tgt;
    tie(src, tgt) = e;
    swap(src, tgt);
    vector<int> d(n, inf);
    d[src] = 0;
    queue<int> q;
    q.emplace(src);
    while (q.size() > 0) {
      auto cur = q.front();
      q.pop();
      for (auto nxt : g[cur]) {
        if (d[cur] + 1 < d[nxt]) {
          d[nxt] = d[cur] + 1;
          q.emplace(nxt);
        }
      }
    }
    if (d[tgt] == inf) continue;
    set<int> vs = {tgt};
    while (tgt != src) {
      for (auto v : h[tgt]) {
        if (d[v] + 1 == d[tgt]) {
          vs.insert(v);
          tgt = v;
          break;
        }
      }
    }
    vector<int> indeg(n), outdeg(n);
    for (auto ee : edges) {
      if (vs.count(ee.first) and vs.count(ee.second)) {
        indeg[ee.second] += 1;
        outdeg[ee.first] += 1;
      }
    }
    bool ok = true;
    rep(i, n) {
      if (indeg[i] != outdeg[i]) ok = false;
      if (indeg[i] >= 2) ok = false;
    }
    if (ok) {
      cout << vs.size() << endl;
      for (auto v : vs) {
        cout << v + 1 << endl;
      }
      return 0;
    }
  }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<double,double> Pdouble;

const int INF = 2000000000;
const int MOD = 1000000007;

const int MAX_N = 110;
const int MAX_M = 110;

char maze[MAX_N][MAX_M + 1];

int main() {
  ll k,n;
  cin >> k >> n;
  vector<ll> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  vector<ll> b(n);
  for(int i=0; i<n-1; i++){
    b.at(i) = a.at(i+1)-a.at(i);
  }
  b.at(n-1)=k-a.at(n-1)+a.at(0);

  ll answer =k - *max_element(b.begin(),b.end());

  cout << answer << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define reps(i, j, n) for(int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int animal[110000];
  //初めの2匹を仮定, 0がwolf, 1がsheep
  bool flag = false;
  rep(i, 2){
    rep(j, 2){
      animal[0] = i; animal[1] = j;
      reps(k, 2, n+1){
        if((animal[k-1] && s[k-1] == 'o')||(!animal[k-1] && s[k-1] == 'x')) animal[k] = animal[k-2];
        else if((animal[k-1] && s[k-1] == 'x')||(!animal[k-1] && s[k-1] == 'o')) animal[k] = (animal[k-2]+1)%2;
      }
      if((animal[n] == animal[0]) && ((animal[0] && (s[0] == 'o' ? animal[1] == animal[n-1] : animal[1] != animal[n-1]))||(!animal[0] && (s[0] == 'o' ? animal[1] !=animal[n-1] : animal[1] == animal[n-1])))){
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  if(!flag){
    cout << -1 <<endl;
    return 0;
  }
  rep(i, n){
    printf("%c", animal[i] ? 'S' : 'W');
  }
  cout <<endl;
}

Measured memory_bytes: 4088
from math import log,floor
a,b,c = map(int,input().split())
K = int(input())
count = 0

while a>=b:
    b*=2
    count+=1

while b>=c:
    c*=2
    count+=1
#print(a,b,c)
if count > K:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 9168
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}

int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int check = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (s[i] == 'L') {
				check++;
			}
		}
		else {
			if (s[i] == 'R') {
				check++;
			}
		}
	}
	if (check == 0) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int m[301][301];
bool aru[301];
vector<int> dat[301];
int ans[301][301];

int main(){
  int H,W,K; cin>>H>>W>>K;
  vector<int> V;
  V.push_back(-1);

  for(int i=0;i<H;i++){
    string S; cin>>S;
    int X=V.size();
    for(int j=0;j<W;j++){
      if(S.at(j)=='#') {m[i][j]=1; aru[i]=true; dat[X].push_back(j);}
    }
    if(aru[i]) V.push_back(i);
  }
  

  int count=1;
  int VS=V.size();
  for(int i=1;i<VS;i++){
    int A=V.at(i-1)+1, B=V.at(i);
    if(i==VS-1) B=H-1;
    int memory=count;
    for(int k=A;k<=B;k++){
      count=memory;
      for(int p=0;p<dat[i].size();p++){
        if(p==0) for(int t=0;t<=dat[i].at(0);t++) {ans[k][t]=count;} 
        else for(int t=dat[i].at(p-1)+1;t<=dat[i].at(p);t++) ans[k][t]=count;
        if(p==dat[i].size()-1) for(int t=dat[i].at(p);t<W;t++) ans[k][t]=count;
        count++;
      }
      
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cout<<ans[i][j]<<' ';
    cout<<endl;
  }

}


Measured memory_bytes: 2048
#include<stdio.h>

int main() {
  int N,A,B,taxi,train;

  scanf("%d",&N);
  scanf("%d",&A);
  scanf("%d",&B);

  train = A * N;
  taxi = B;

  if (train >= taxi) printf("%d",taxi);
  else printf("%d",train);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define x first
#define y second
#define oo 1000000000
#define PII pair <int, int>
 
using namespace std;

int n, a, b, c, d;
 
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> a >> b >> c >> d;
    int mx = max(a, c);
    int mn = min(b, d);
    if (mn < mx) cout << "0";
    else cout << mn - mx;
    return 0;
}


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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)


int main(){
    int mod=1000000007;
    int n,a,ans=0;
    sc1(n);
    int w[15][14][2];
    rep(i,15) rep(j,14) rep(k,2) w[i][j][k]=0;
    rep(i,n) {
        sc1(a);
        rep(j,a) sc2(w[i][j][0],w[i][j][1]);
    }
    rep(i,pow(2,n)) {
        if (i==0) continue;
        int x=i;
        int l[15]={0};
        rep(j,n) {
            if (x&1) l[j]=1;
            x=x>>1;
        }
        int f=1;
        rep(j,n) {
            if (l[j]) {
                rep(k,14) if (w[j][k][0]>0 && l[w[j][k][0]-1]!=w[j][k][1]) f=0;
            }
        }
        int cnt=0;
        if (f) {
            rep(j,n) cnt+=l[j];
            ans=max(ans,cnt);
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
typedef pair<int, int> P;

int dp[100001] = {}, h[100001] = {};

int main(){
    int n, i;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> h[i];
        if(i==0) dp[i] = 0;
        else if(i==1) dp[i] = abs(h[i-1]-h[i]);
        else dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i-2]-h[i]));
    }
    cout << dp[n-1] << "\n";
    return 0;
}

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

using namespace std;

const int N = 110, K = 1e5+100, mod = 1e9+7;
int n, k, a[N], dp[N][K], sum[K];


int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	scanf("%d %d", &n, &k);

	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}

	dp[0][0] = 1; // i , k qtd de doces

	for (int i = 1; i <= n; i++){
		memset(sum, 0, sizeof sum);
		sum[0] = dp[i - 1][0];

		for (int j = 1; j <= k; j++){
			sum[j] = (sum[j - 1] + dp[i - 1][j])%mod;
		}

		for (int j = 0; j <= k; j++){
			int sumj = sum[j], 
				rmv = j - a[i] - 1; // [a[i], j]
			if (rmv >= 0){
				//cout << rmv << endl;
			 	sumj = (sumj - sum[rmv] + mod)%mod;
			 }
			dp[i][j] = sumj;
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}

	printf("%d\n", dp[n][k]);

	return 0; 
}

Measured memory_bytes: 43176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int maxn = 100000 + 5;

ll a, b, c;

int main() {
    cin >> a >> b >> c;
    if (a + b < c) c = a + b + 1;
    cout << b + c << endl;
    return 0;
}

Measured memory_bytes: 256
def rotateDice(direction: str, dice: dict) -> dict:
    if direction == 'S':
        dice['S'], dice['F'], dice['N'], dice['B'] = dice['F'], dice['N'], dice['B'], dice['S']
    elif direction == 'E':
        dice['E'], dice['F'], dice['W'], dice['B'] = dice['F'], dice['W'], dice['B'], dice['E']
    elif direction == 'W':
        dice['W'], dice['F'], dice['E'], dice['B'] = dice['F'], dice['E'], dice['B'], dice['W']
    elif direction == 'N':
        dice['N'], dice['F'], dice['S'], dice['B'] = dice['F'], dice['S'], dice['B'], dice['N']
    return dice
 
 
dice_list = list(map(int, input().split()))
dice = {'FSEWNB'[i]: dice_list[i] for i in range(6)}
for c in input():
    dice = rotateDice(c, dice)
print(dice['F'])


Measured memory_bytes: 5612
N,M,X,Y = list(map(int,input().split()))
x = list(map(int,input().split()))
y = list(map(int,input().split()))
hantei = 0

for j in range(X + 1,Y+1):
    hantei1 = 0
    hantei2 = 0
    for k in range(N):
        if x[k] >= j:
           hantei1 = 1
           break
    for l in range(M):
        if y[l] < j:
           hantei1 = 1
           break
    if hantei1 == 0 and hantei2 == 0:
        print("No War")
        hantei = 1
        break
  
if hantei == 0:
    print("War")

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
const int INF = 1e+9;
int main(){
  int n,t;cin>>n>>t;
  int c[n],s[n];
  int d=INF;
  r(i,0,n){
    cin>>c[i]>>s[i];
    if(s[i]<=t&&d>c[i])d=c[i];
  }
  if(d==INF){
    cout<<"TLE"<<endl;
  }else{
    cout<<d<<endl;
  }
  return 0;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string
int digitsum(int a){
  int b=0;
  while(a){
    b+=a%10;
    a/=10;
  }
  return b;
}
signed main(){
  int N,M,O,P=0,c=1,co=0,cou=0,minN=mod;
  double D,Do;
  char C,Ca;
  str S,T;
  cin>>N>>M>>O;
  if(N==M&&M==O)cout<<"No"<<endl;
  else if(N==M&&N!=O)cout<<"Yes"<<endl;
  else if(N==O&&N!=M)cout<<"Yes"<<endl;
  else if(M==O&&M!=N)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  int M;
  cin>>M;
  vector<int>H(N);
  vector<int>A(M);
  vector<int>B(M);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  for(int i=0;i<M;i++){
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
  }
  vector<bool>k(N,true);
  int count=0;
  for(int i=0;i<M;i++){
    if(H[A[i]]<H[B[i]]){k[A[i]]=false;}
    else if(H[A[i]]>H[B[i]]){k[B[i]]=false;}
    else{k[A[i]]=false;k[B[i]]=false;}
  }
  for(int i=0;i<N;i++){
    if(k[i]){count++;}
  }
  cout<<count<<endl;
  return 0;}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
string s;
string t;
ll ret = 0;
vector<ll> table[26];

ll findIndex(ll i, ll c) {
  if (table[c].empty()) {
    return -1;
  } else {
    auto itr = upper_bound(ALL(table[c]), i);
    if (itr == table[c].end()) {
      return table[c][0];
    } else {
      return *itr;
    }
  }
}

void input() {
  IN(s);
  IN(t);
  N = s.size();
}

void solve() {
  ll c;
  REP(i, N) {
    c = s[i] - 'a';
    table[c].pb(i+1);
  }
  ll p = N;
  ll next;
  REP(i, t.size()) {
    c = t[i] - 'a';
    next = findIndex(p, c);
    if (next == -1) {
      ret = -1;
      break;
    }
    if (next > p) {
      ret += next - p;
    } else {
      ret += N - p + next;
    }
    p = next;
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 1724
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n;cin>>n;
    bool num[105]={};
    int ans=0;
    rep(i,0,n){
        int h;cin>>h;
        if(!num[h]){
            ans++;
            num[h]=true;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define MAX 305
using namespace std;
 
int C[MAX],V[MAX],D[MAX],L[MAX];
int n,cost;
int dp[MAX][MAX];
 
 
int recv(int i,int j){
  if(dp[i][j] != -1) return dp[i][j];
  if(i == n )return 0;
  int res =0;
  //if(j < C[i])return recv(i+1,j);
  //else{
    for(int k=0;k*C[i]<=j;k++){
      res = max(res,k*V[i]+recv(i+1,j-k*C[i]));
    }
    //}
   
  return dp[i][j]=res;
}
int recd(int i,int j){
  if(dp[i][j] != -1) return dp[i][j];
  if(i == n )return 0;
  int res =0;
  //if(j < C[i])return recd(i+1,j);
  //else{
    for(int k=0;k*C[i]<=j;k++){
      res = max(res,k*D[i]+recd(i+1,j-k*C[i]));
    }
    //}
   
  return dp[i][j]=res;
}
int recl(int i,int j){
  if(dp[i][j] != -1) return dp[i][j];
  if(i == n )return 0;
  int res =0;
  //if(j < C[i])return recl(i+1,j);
  //else{
    for(int k=0;k*C[i]<=j;k++){
      res = max(res,k*L[i]+recl(i+1,j-k*C[i]));
    }
    //}
   
  return dp[i][j]=res;
}
 
 
 
int main(){
 
  int iori,chihaya=0,makoto=0,miki=0;
 
 
  while( cin >> n >> cost ){
 
    for(int i=0;i<n;i++){
      char ch = getchar();
      while((ch=getchar())!='\n');
      cin >> C[i] >> V[i] >> D[i] >> L[i];
    }
 
    memset(dp,-1,sizeof(dp));
    chihaya = (chihaya,recv(0,cost));
    //cout << "DEBUG V = " << chihaya << endl;
    /*
    for(int i=0;i < 10;i++){
      for(int j=0;j<10;j++)cout << dp[i][j] << " " ;
      cout << endl;
    }
    */
    memset(dp,-1,sizeof(dp));
    makoto = recd(0,cost);
    //cout << "DEBUG D = " << makoto << endl;
    memset(dp,-1,sizeof(dp));
    miki = recl(0,cost);
    //  cout << "DEBUG L = " << miki << endl;
 
    iori=max(chihaya,max(makoto,miki));
 
    cout << iori << endl;
 
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int ans = 0;
int main() {
    int n,a,b;

    cin>>n>>a>>b;

    if(b>a*n)
        ans = a*n;
    else
        ans = b;
    cout << ans << endl;
    return 0;
}

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

int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(a.begin(), a.end());
  bool ans=true;
  rep(i,n){
    if(a[i]!=a[i+1]){
    }else{
      ans=false;
      break;
    }
  }
  if(ans){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    string solve(int k, string& s) {
        int n = s.size();
        if(n <= k) return s;
        else return s.substr(0, k) + "...";
    }
};

int main() {
    int k;
    string s;
    cin >> k >> s;
    Solution sol;
    auto ret = sol.solve(k, s);
    cout << ret << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef pii point;
using namespace std;

int main(){
  ll n; cin>>n;
  vi a(n); REP(i,n) cin>>a[i];
  if(n==2){
    cout<<max(a[0],a[1])<<' '<<min(a[0],a[1])<<endl;
    return 0;
  }
  sort(a.begin(),a.end());
  vpii v;
  REP(i,n) v.push_back(make_pair(min(a[i],a[n-1]-a[i]),a[i]));
  sort(v.begin(),v.end());
  cout<<a[n-1]<<' '<<v[n-1].second<<endl;
}


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

ll C[51][51];

void combinations()
{
	for (int i = 0; i < 51; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (i == j || j == 0)
			{
				C[i][j] = 1;
			}
			else
			{
				C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
			}
		}
	}
}

int main()
{
	int n;
	ll count = 0;
	cin >> n;

	int a, b;
	cin >> a >> b;

	ll v[n];
	combinations();

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

	sort(v, v + n);
	reverse(v, v + n);
	ll sum = 0;
	for (int i = 0; i < a; i++)
	{
		sum += v[i];
	}

	ll max = v[0];
	ll min = v[a - 1];

	if (max != min)
	{
		int mincount = 0;
		int min_in_set = a;
		for (int i = 0; i < n; i++)
		{
			if (v[i] == min) mincount++;
		}
		for (int i = 0; i < a; i++)
		{
			if (v[i] > min)
			{
				min_in_set--;
			}
		}
		count += C[mincount][min_in_set];
	}
	else
	{
		int maxcount = 0;
		for (int i = 0; i < n; i++)
		{
			if (v[i] == max)
				maxcount++;
		}

		for (int i = a; i <= b; i++)
		{
				count += C[maxcount][i];
		}

	}
	cout << fixed << setprecision(7);
	cout << sum * 1.0 / a << endl;
	cout << count << endl;

}

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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

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

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            xy[i][1] -= xy[i][0], xy[i][2] -= xy[i][0], xy[i][0] = 0;
        }
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(!(xy[0][i] == xy[1][i] && xy[1][i] == xy[2][i])){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main()
{
    int k,a,b;
    scanf("%d\n",&k);
    scanf("%d %d",&a,&b);
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            printf("OK");
            return 0;
        }
    }
    printf("NG");
    return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
void solve()
{
	COMinit();
	int S;
	cin>>S;
	ll ans=0;
	rep(i,S/3+1){
		ans+=COM(S-3*i+i-1,i-1);
		ans%=M;
	}
	cout<<ans<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 15608
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <climits>
#include <string>
#include <string.h>
#include <algorithm>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<int, int> pii;
//const ll mod = (ll)1e9 + 7;
const int N = (int)1e5 + 7;

int main() {
    ll n,a[N],b[N],s=0;
    cin>>n;
    forn(i,n) cin>>a[i]>>b[i];
    
    for(ll i=n-1;i>=0;i--){
        if((a[i]+s)%b[i]==0) continue;
        ll t=(a[i]+s)/b[i];
        s+=(t+1)*b[i]-(a[i]+s);
    }
    cout<<s<<endl;
    
    
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
#endif

	ll n;
	cin>>n;
	ll temp=log2(n);
	ll a=powl(2,temp+1)-1;
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 3808
#include <cstdio>

int main()
{
    int amida[33];
    for (int i = 0; i <= 31; ++i)
        amida[i] = i;
    int w, n;
    int a, b;
    std::scanf("%d %d", &w, &n);
    for (int i = 0; i < n; ++i) {
        std::scanf("%d,%d", &a, &b);
        amida[32] = amida[a];
        amida[a] = amida[b];
        amida[b] = amida[32];
    }
    for (int i = 1; i <= w; ++i)
        std::printf("%d\n", amida[i]);
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l)
{
    T tmp = r;
    r = l;
    l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
    return is;
}

ll bi(ll num)
{
    if (num == 1)
        return 1;
    ll ret = bi(num - 1);
    ret = (ret * num) % mod;
    return ret;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> d(k);
    // vector<vector<ll>> a(k);
    vector<ll>s(n,0);

    for (ll i = 0; i < k; i++)
    {
        cin >> d[i];
        for (ll j = 0; j < d[i]; j++){
            ll a;
            cin >> a;
            s[a-1]++;
        }
    }

    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        if (s[i]==0)ans++;
    }



    cout << ans;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M; 
	cin >> N >> M; 
	int A[1010] = {}, B[1010] = {}, C[1010] = {}; 
	int G[110][110] = {};  
	for(int i = 0; i < M; i++){
		cin >> A[i] >> B[i] >> C[i]; 
		G[A[i]-1][B[i]-1] = C[i]; 
		G[B[i]-1][A[i]-1] = C[i]; 
	}
	int WF[110][110] = {};
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(G[i][j] > 0) WF[i][j] = G[i][j];
			else if(i != j) WF[i][j] = 1e9; 
		}
	}
	for(int k = 0; k < N; k++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				WF[i][j] = min(WF[i][j], WF[i][k] + WF[k][j]); 
			}
		}
	}
	int ans = 0; 
	for(int e = 0; e < M; e++){
		bool necessary = false; 
		for(int i = 0; i < N; i++){
          for(int j = 0; j < N; j++){
			if(WF[i][j] == WF[A[e]-1][i] + WF[j][B[e]-1] + C[e]) necessary = true; 
          }
		}
		if(necessary) ans ++; 
	}
	cout <<	M - ans << endl; 
}

Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 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; }



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  for(int h=1;h<=3500;h++){
    for(int n=1;n<=3500;n++){
      if(4*h*n-N*h-N*n!=0&&N*h*n%(4*h*n-N*h-N*n)==0&&N*h*n/(4*h*n-N*h-N*n)>0){
        ll w=N*h*n/(4*h*n-N*h-N*n); cout<<h<<" "<<n<<" "<<w<<'\n'; return 0;
      }
    }
  }
  
  return 0;
}

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

int main()
{
	int K,a=0,b=0;

	cin >> K;

	for (int i = 1; i <= K; i++) {
		if (i % 2 == 0)a++;
		else b++;
	}

	cout << a*b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
 #include <algorithm>
 #include <cstring>
 #include <cstdio>
 #include <vector>
 #include <cstdlib>
 #include <iomanip>
 #include <cmath>
 #include <ctime>
 #include <map>
 #include <set>
 #include <queue>
 #include <stack>
 using namespace std;
 #define lowbit(x) (x&(-x))
 #define max(x,y) (x>y?x:y)
 #define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
 #define INF 0x3f3f3f3f3f
 #define mem(a) (memset(a,0,sizeof(a)))
 typedef long long ll;
 ll gcd(ll a,ll b){
     return b?gcd(b,a%b):a;
 }
 bool cmp(int x,int y)
 {
     return x>y;
 }
 const int N=10005;
 const int mod=1e9+7;
 int main()
 {
     std::ios::sync_with_stdio(false);
    int n,k,x,y;
     cin>>n>>k>>x>>y;
    ll s=0;
     if(n<=k) s+=n*x;
     else s+=k*x+(n-k)*y;
     cout<<s<<endl;
     return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <queue>

long long bfs(int);

long long bfs(int nth) {
	std::priority_queue<long long, std::vector<long long>, std::greater<long long> > heap;
	for (int i = 1; i <= 9; i++) {
		heap.push(i);
	}

	long long top;
	for (int i = 1; i <= nth; i++) {
		top = heap.top();
		heap.pop();
		
		if (top % 10 - 1 >= 0) {
			heap.push(top * 10 + top % 10 - 1);
		}
		
		if (top % 10 + 1 <= 9) {
			heap.push(top * 10 + top % 10 + 1);
		}

		heap.push(top * 10 + top % 10);
	}

	return top;
}

int main() {
	std::ios::sync_with_stdio(false);

	int k;
	std::cin >> k;
	std::cout << bfs(k);

	return 0;
}

Measured memory_bytes: 2420
#include<cstdio>
#include<algorithm>
using namespace std;

bool ok(char ch) {
	return ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T';
}

int main() {
	char s[111];
	scanf("%s", s);
	
	int cnt = 0, ans = 0;
	for(int i=0;s[i];i++)
		if (ok(s[i])) {
			cnt++;
			ans = max(ans, cnt);
		} else {
			cnt = 0;
		}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

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

        int bis = 0;

        bis = b*(t/a);
        System.out.println(bis);

        sc.close();
    }
}

Measured memory_bytes: 22740