akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;

const int INF = 1000000007;

// aとbを掛けた値をmodする(a * b mod p)
int modmulti(int a, int b)
{
    int res = 0;
    int mod = a % INF;
    while (b > 0)
    {
        if ((b & 1) == 1)
        {
            res += mod;
            if (res > INF)
            {
                res -= INF;
            }
        }
        mod <<= 1;
        if (mod > INF)
        {
            mod -= INF;
        }
        b >>= 1;
    }
    return res;
}

int main()
{
    int N;
    if (scanf("%d", &N) < 1) return 0;

    char S1[53];
    char S2[53];

    if (scanf("%s%s", S1, S2) < 2) return 0;

    bool flgt = false;
    bool flgy = false;

    int a = 1;
    for (int i = 0; i < N; i++)
    {
        if (!flgt && !flgy)
        {
            if (S1[i] == S1[i + 1])
            {
                a = modmulti(a, 6);
                flgy = true;
                flgt = false;
                i++;
            }
            else
            {
                a = modmulti(a, 3);
                flgt = true;
                flgy = false;
            }
        }
        else if (flgt)
        {
            a = modmulti(a, 2);
            if (S1[i] == S1[i + 1])
            {
                flgy = true;
                flgt = false;
                i++;
            }
            else
            {
                flgt = true;
                flgy = false;
            }
        }
        else
        {
            if (S1[i] == S1[i + 1])
            {
                a = modmulti(a, 3);
                flgy = true;
                flgt = false;
                i++;
            }
            else
            {
                flgt = true;
                flgy = false;
            }
        }
    }

    printf("%d\n", a);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rrep1(i,n) for(ll i=n;i>=1;i--)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const double INF=1000000000000000.0;
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(){
    ll A,B; cin>>A>>B;
  if(A+B==15) cout<<"+";
  else if(A*B==15) cout<<"*";
  else cout<<"x";
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------

int main(void){
	char s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	int ans = 0;
	if(s1 == '1')ans++;
	if(s2 == '1')ans++;
	if(s3 == '1')ans++;

	cout << ans << endl;
}

Measured memory_bytes: 256
ins=input()
ins=[int(r) for r in ins.split()]
A,B,C=ins
K=input()
K=int(K)

ans='No'

for i in range(K):
  for j in range(K-i+1):
    red=A
    green=B
    blue=C
    
    if red<green*(2**i) and green*(2**i) <blue*(2**j):
      ans='Yes'
      break
    elif red<green*(2**j) and green*(2**j) < blue*(2**i):
      ans='Yes'
      break


print(ans)

Measured memory_bytes: 9204
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];

    int ans = 1;
    int Hmax = H[0];
    for (int i = 1; i < N; i++) {
        if (H[i] >= Hmax) {
            ans++;
            Hmax = H[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
S = list(input())
q = int(input())
Q = [list(input().split()) for _ in range(q)]

ds = deque(S)

flg = True
for i in Q:
  if i[0] == "1":
    flg = not flg
  else:
    if flg == True:
      if i[1] == "1":
        ds.appendleft(i[2])
      else:
        ds.append(i[2])
    else:
      if i[1] == "2":
        ds.appendleft(i[2])
      else:
        ds.append(i[2])
if flg:
  print("".join(ds))
else:
  print("".join(ds)[::-1])

        

Measured memory_bytes: 36188
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  constexpr int inf = 1e9;

  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  VV<> g(n);
  for (int _ = 0; _ < n - 1; ++_) {
    int u, v; cin >> u >> v, --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int mn = inf;
  for (int r = 0; r < n; ++r) {
    V<> c(n), d(n);
    {
      auto dfs = [&](auto& F, int v, int p) -> void {
        c[v] = s[v] == '1';
        for (int u : g[v]) if (u != p) {
          F(F, u, v);
          c[v] += c[u];
          d[v] += d[u] + c[u];
        }
      };
      dfs(dfs, r, -1);
    }
    if (d[r] & 1) continue;
    auto dfs = [&](auto& F, int v, int p, int t) -> bool {
      if (!t) return true;
      V<> a;
      for (int u : g[v]) if (u != p) {
        a.push_back(c[u] + d[u]);
      }
      if (a.empty()) return false;
      sort(begin(a), end(a));
      int sum = accumulate(begin(a), end(a), 0);
      if (t <= min(sum, 2 * (sum - a.back()))) return true;
      for (int u : g[v]) if (u != p) {
        if (2 * (c[u] + d[u]) > sum) {
          return F(F, u, v, t - 2 * (sum - a.back()));
        }
      }
      return false;
    };
    if (not dfs(dfs, r, -1, d[r])) continue;
    mn = min(mn, d[r] / 2);
  }
  cout << (mn < inf ? mn : -1) << '\n';
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
  char S[10];
  scanf("%s",S);

  int N=0;
  while(S[N]!='\0') N++;

  int i;
  int X=0;
  int sa;
  int minsa=1000;
  for(i=0;i<N-2;i++){
    X=((int)S[i]-48)*100+((int)S[i+1]-48)*10+((int)S[i+2]-48);
    if(X-753>0) sa=X-753;
    else sa=753-X;

    if(minsa>sa) minsa=sa;
  }

  printf("%d\n",minsa);
  return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  ll x=0;
  ll n;cin>>n;
  string s;cin>>s;
  ll MAX=0;
  rep(i,n){
    if(s[i]=='I')x++;
    if(s[i]=='D')x--;
    MAX=max(MAX,x);
  }
  cout<<MAX<<endl;
}
   
    
    

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<int> vec1(3,0);
  vector<vector<int>> vec(n,vec1);
  
  vector<int> dp1(3,0);
  vector<vector<int>> dp(n,dp1);
  
  for(int i=0;i<vec.size();i++)
  {
      for(int j=0;j<vec[0].size();j++)
      {
          cin>>vec[i][j];
      }
  }
  dp[0][0]=vec[0][0];
  dp[0][1]=vec[0][1];
  dp[0][2]=vec[0][2];
  
  for(int i=1;i<vec.size();i++)
  {
      for(int j=0;j<vec[0].size();j++)
      {
         if(j==0)
         {
             dp[i][j]=max(vec[i][j]+dp[i-1][j+1],vec[i][j]+dp[i-1][j+2]);
         }
         if(j==1)
         {
             dp[i][j]=max(vec[i][j]+dp[i-1][j-1],vec[i][j]+dp[i-1][j+1]);
         }
         if(j==2)
         {
             dp[i][j]=max(vec[i][j]+dp[i-1][j-1],vec[i][j]+dp[i-1][j-2]);
         }
      }
    
  }
  cout<<*max_element(dp[n-1].begin(),dp[n-1].end());
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define msll multiset<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define gpl greater<pll>
#define spl set<pll>
#define mspl multiset<pll>
#define lb lower_bound
#define bp __builtin_popcount
#define ub upper_bound
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define mem(x,y) memset(x, y, sizeof x)
#define endl "\n"
#define sz(x) (ll)x.size()
#define sqr(x) x*x
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
ll mx=INT_MAX;
ll mn=INT_MIN;
ll MOD=1e9+7;
const ll maxs=1e5+5;
ll INF = 1e18;
const ll lg=22; 

ll fast(ll base , ll expo){
    ll res = 1;
    while(expo>=1){
        if(expo%2) res *= base;
        base *= base;
        expo /= 2;
    }
    return base;
}

void code_idhr_h(){
    ll N; cin>>N;
    ll A[N+1]; mll MAP; ll sum = 0;
    for(ll i=1; i<=N; i++){
        cin>>A[i];
        MAP[A[i]]++;
        sum += A[i];
    }
    ll Q; cin>>Q;
    while(Q--){
        ll X,Y; cin>>X>>Y;
        sum -= (MAP[X] * X);
        sum += (MAP[X] * Y);
        MAP[Y] += MAP[X];
        MAP[X] = 0;
        cout<<sum<<endl;
    }
}

int main(){
    rapido;
    ll T=1; //cin>>T;
    while(T--){
        code_idhr_h();
    }
    return 0;
}

Measured memory_bytes: 10164
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s; cin >> s;
    vector<int> dp(sz(s)+1);
    dp[0] = 0;
    rep(i, sz(s)) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            dp[i+1] = dp[i]+1;
        }
        else dp[i+1] = 0;
    }
    int ans = 0;
    rep(i, sz(s)+1) chmax(ans, dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int H, M, H2, M2, K; cin >> H >> M >> H2 >> M2 >> K;
  double t1 = 60 * H + M;
  double t2 = 60 * H2 + M2;
  cout << t2 - t1 - K << endl;
}


Measured memory_bytes: 3788
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = II()
    cnt = 0
    for _ in range(n):
        l, r = MII()
        cnt += r-l+1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
from collections import Counter
N = int(input())
M = [3, 5, 7]
num = []
def dfs(A):
    if A == "":
        pass    
    elif int(A) > N:
        return
    else:
        num.append(A)
    for v in M:
        A = A + str(v)
        dfs(A)
        A = A[:-1]
               
dfs("")
ans = []
for i in num:
    if len(Counter(i)) == 3:
        ans.append(i)
print(len(ans))

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

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

	a[n] = -1;

	int cnt = 1;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] != a[i + 1]) {
			ans += cnt / 2;
			cnt = 1;
		}
		else cnt++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3556
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define lengthof(array) (sizeof(array) / sizeof(*array))
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

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

	vector<long long> cnt(2001, 0);
	for(int i = 0; i <= 1000; ++i)
		for(int j = 0; j <= 1000; ++j)
			++cnt[i + j];

	for(int n; cin >> n;) {
		long long ans = 0;
		const int start = max(0, n - 2000), end = min(2000, n);
		for(int i = start; i <= end; ++i)
			ans += cnt[i] * cnt[n - i];

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1204
s = input()
a = 0 < int(s[:2]) <= 12
b = 0 < int(s[2:]) <= 12

if a:
    if b:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2940
import sys


def solv(nums):
    nums.sort()
    min_number = int(''.join(nums))
    nums.sort(lambda a, b: cmp(b, a))
    max_number = int(''.join(nums))
    return max_number - min_number


sys.stdin.readline()
for line in sys.stdin:
    nums = list(line.rstrip('\n'))
    print solv(nums)

Measured memory_bytes: 4228
N = int(input())
X = list(map(int,input().split()))

sortx = sorted(X)
bef = sortx[N//2-1]
aft = sortx[N//2]
for i in X:
    if(i <= bef):
        print(aft)
    else:
        print(bef)
        # print(aft if i <= bef else bef)
        

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

using namespace std;

vector< bool > get_prime(int n) {
  vector< bool > prime(n + 1, true);

  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;

  for(int i = 2; i * i <= n; i++) {
    if(prime[i]) {
      for(int j = i + i; j <= n; j += i) prime[j] = false;
    }
  }

  return (prime);
}

auto table = get_prime(1000000);
const int mod = 1e9 + 7;

int N, Q[100000];
int dp[100000];

int rec(int idx) {
  if(idx == N) return 1;
  if(~dp[idx]) return dp[idx];
  if(!table[Q[idx]]) return dp[idx] = 0;
  int ret = 0;
  if(idx + 1 == N || Q[idx] < Q[idx + 1]) {
    (ret += rec(idx + 1)) %= mod;
  }
  if(idx + 1 < N) {
    if(Q[idx + 1] > 1) {
      if(idx + 2 == N || Q[idx] < Q[idx + 2]) {
        (ret += rec(idx + 2)) %= mod;
      }
    }
  }
  return dp[idx] = ret;
}

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> Q[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0) << endl;
}


Measured memory_bytes: 7484
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << min(P + Q, min(Q + R, P + R)) << endl;
    return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=100010;
int n;
ll c[N],f[N],s[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline void add(int x,ll y) {
    while(x) c[x]=min(c[x],y),x-=(x&-x);
}
inline ll query(int x) {
    ll ret=1LL<<60;
    while(x<=n+1) ret=min(ret,c[x]),x+=(x&-x);
    return ret;
}
int main() {
    int E,T;
    ll la=1LL<<60;
    cin>>n>>E>>T;
    for(int i=1;i<=n;i++) s[i]=gi();
    memset(c,127/3,sizeof(c));
    f[0]=0,f[1]=s[1]+T;
    for(int i=0;i<2;i++) add(i+1,f[i]-s[i]);
    for(int i=2,j=0;i<=n;i++) {
	while(2*(s[i]-s[j+1])>T)
	    la=min(la,f[j]-s[j]-2*s[j+1]),++j;
	f[i]=min(la+3*s[i],query(j+1)+T+s[i]);
	add(i+1,f[i]-s[i]);
    }
    cout<<f[n]+E-s[n];
    return 0;
}

Measured memory_bytes: 2688
from sys import stdout
import fractions
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

a,b = inm()
m = fractions.gcd(a,b)
print((a*b)//m)


Measured memory_bytes: 5076
s = int(input())
mod = 10**9 + 7
dp = [0]*(s + 1)
dp[0] = 1

for i in range(1, s+1):
    for j in range(0, (i-3)+1):
        dp[i] += dp[j]
        dp[i] %= mod

print(dp[s])


Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
#define Senky_Bansal ios::sync_with_stdio(0); 
#define IIIT_ALLAHABAD cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
const int N=1e5+5;
int Dp[N];
vector<ll>adj[N];
ll dfs(ll p)
{
	int &ans=Dp[p];
	if(ans!=-1)
		return ans;
	ans=0;
	for(auto i:adj[p])
		ans=max(ans,1+dfs(i));
	return ans;
}
signed main()
{
	Senky_Bansal
	IIIT_ALLAHABAD
    memset(Dp,-1,sizeof(Dp));
    ll n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
    	ll a,b;
    	cin>>a>>b;
    	adj[a].push_back(b);
    }
    ll ann=0;
    for(int i=1;i<=n;i++)
    {
    	ann=max(ann,dfs(i));
    }
    cout<<ann<<endl;
	return 0;
}

Measured memory_bytes: 7936
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    s = "#" + s;
    t = "$" + t;
    vector<vector<int>> dp(t.size(),vector<int>(s.size()));

    for (int i = 1;i < t.size();i++){
        for (int j = 1;j < s.size();j++){
            if (t[i] == s[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else {
                dp[i][j] = (dp[i-1][j] > dp[i][j-1]) ? dp[i-1][j] : dp[i][j-1];
            }
        }
    }
    int i = t.size() - 1;
    int j = s.size() - 1;
    int len = dp[i][j];
    string ans(len,'0');
    while (len > 0){
        if (t[i] == s[j]){
            len--;
            ans[len] = t[i];
            i--;
            j--;
        }else if(dp[i][j] == dp[i-1][j]){
            i--;
        }else{
            j--;
        }
    }
    cout << ans << endl;
    
    return 0;


}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


int main() {
  lint n,m; cin >> n >> m;

  vector<lint> a(n,1),c(n,0);
  c[0] = 1;

  for(lint i=0;i<m;i++) {
    lint x,y; cin >> x >> y;
    a[x-1]--;
    a[y-1]++;
    if(c[x-1] == 1 && c[y-1] == 0) { c[y-1] = 1; }
    if(a[x-1] == 0) { c[x-1] = 0; }
  }

  lint ans=0;
  for(lint i=0;i<n;i++) { ans += c[i]; }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }

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

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

int main(void) {
	ll n,k;

	cin >> n>>k;

	int i = 1;
	while (1) {
		if (n < pow(k,i)) {
			break;
		}
		else {
			i++;
		}
	}

	cout << i << endl;
	return 0;
}

Measured memory_bytes: 4012
#include<stdio.h>

int main(){
  int h[100000];
  int w[100000];
  int count = 0;
  while(true){
    scanf("%d %d", &h[count], &w[count]);
    if(h[count] == 0 && w[count] == 0) break;
    count ++;
  }

  for(int i=0; i < count; i++){
    for(int yoko=0; yoko < w[i]; yoko++){
      printf("#");
    }
    printf("\n");
    for(int tate=0; tate < h[i]-2; tate++){
      printf("#");
      for(int yoko=0; yoko < w[i]-2; yoko++){
	printf(".");
      }
      printf("#\n");
    }
    for(int yoko=0; yoko < w[i]; yoko++){
      printf("#");
    }
    printf("\n\n");
  }
  
  return 0;
}



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

#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define all(c) begin(c),end(c)
#define mt make_tuple

using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;

constexpr ll INF=1e18;

struct Edge{
	int u,v,w;
	Edge(){}
	Edge(int u,int v,int w):u(u),v(v),w(w){}
};
using Tree=vector<vector<Edge>>;

vector<tuple<ll,ll>> dfs(const Tree& t,ll x,int p)
{
	if(t[p].empty()) return {mt(0,0)};
	auto e0=t[p][0],e1=t[p][1];
	auto s0=dfs(t,x,e0.v),s1=dfs(t,x,e1.v);

	vector<tuple<ll,ll>> res;
	rep(_,2){
		for(int i=0,j=0;i<s0.size();i++){
			ll a,b; tie(a,b)=s0[i];
			for(;j<s1.size();j++){
				ll c,d; tie(c,d)=s1[j];
				if(e0.w+b+c+e1.w>x) break;
			}
			if(j>0){
				ll d=get<1>(s1[j-1]);
				res.emplace_back(e0.w+a,d+e1.w);
			}
		}
		swap(e0,e1); swap(s0,s1);
	}

	sort(all(res),[](auto a,auto b){return a<b;});
	res.erase(unique(all(res),[](auto a,auto b){return get<1>(a)<=get<1>(b);}),end(res));
	return res;
}

bool ok(const Tree& t,ll x)
{
	return dfs(t,x,0).size();
}

int main()
{
	for(int n;cin>>n&&n;){
		Tree t(n);
		rep(i,n-1){
			int u,v=i+1,w; cin>>u>>w; u--;
			t[u].emplace_back(u,v,w);
		}
		ll lo=-1,hi=INF;
		while(hi-lo>1){
			ll mi=(lo+hi)/2;
			(ok(t,mi)?hi:lo)=mi;
		}
		cout<<hi<<endl;
	}
}


Measured memory_bytes: 19712
n,m = map(int,input().split())
food = [0]*(m+1)
for i in range(n):
    temp = list(map(int,input().split()))
    for a in temp[1:]:
        food[a] += 1
ans = 0
for f in food:
    if f == n:
        ans += 1
        
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
    int x;
    scanf("%d", &x);
    switch(x%7) {
        case 0: puts("thu");
                break;
        case 1: puts("fri");
                break;
        case 2: puts("sat");
                break;
        case 3: puts("sun");
                break;
        case 4: puts("mon");
                break;
        case 5: puts("tue");
                break;
        case 6: puts("wed");
    }

    return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
  vector<vector<int>> x(N);
  for (int i = 0; i < M; i++) {
    x[a[i]-1].pb(b[i]);
    x[b[i]-1].pb(a[i]);
  }
  vector<int>n;
  ll ans = 0;
  for (int i = 0; i < N; i++)n.pb(i+1);
  do{
    bool add = true;
    if(n[0] != 1)continue;
    for (int i = 0; i < N-1; i++) {
      bool can = false;
      for (auto next : x[n[i]-1]) {
        if(next == n[i+1])can = true;
      }
      if(!can)add = false;
    }
    if(add)ans++;
  }while(next_permutation(all(n)));
  cout << ans << endl;
}

int main(){
    long long N;
	scanf("%lld",&N);
	long long M;
	scanf("%lld",&M);
	std::vector<long long> a(M);
	std::vector<long long> b(M);
	for(int i = 0 ; i < M ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
	}
    solve(N, M, std::move(a), std::move(b));
}


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

vector<int> RLE(string s) {
  vector<int> ans;
  s.push_back('S');
  int counter = 0;
  while (true) {
    int count = 1;
    while (true) {
      if (s[counter] != s[counter + 1]) {
        ans.push_back(count);
        break;
      }
      counter++;
      count++;
    }
    if (counter == s.length() - 2)
      break;
    counter++;
  }
  return ans;
}

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  auto vec = RLE(s);
  int ans = 0;
  if (2 * k + 1 >= vec.size()) {
    for (int i = 0; i < vec.size(); i++) {
      ans += vec[i];
    }
    ans--;
  } else {
    for (int i = 0; i < 2 * k + 1; i++) {
      ans += vec[i];
    }
    ans--;
    for (int i = 2 * k + 1; i < vec.size(); i++) {
      ans += --vec[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll sum=0, n,m,l;
    cin>>n;
     for(int i=1;i<=n;i++)
     {
       cin>>m;
       if(i&1 && m&1)sum++;
     }
  cout<<sum;

}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
string S;
vector<vector<int>> v(26);
int A[26] = {0},id[26] = {0};

ll merge_count(vector<ll> &a){
	int n = a.size();
	if(n<=1) return 0;
	ll cnt = 0;
	vector<ll> b(a.begin(),a.begin() + n/2);
	vector<ll> c(a.begin() + n/2, a.end());
	cnt += merge_count(b);
	cnt += merge_count(c);
	int ai = 0,bi = 0,ci = 0;
	while(ai<n){
		if(bi<b.size() && (ci == c.size() || b[bi] <= c[ci])){
			a[ai++] = b[bi++];
		}else{
			cnt += n/2 - bi;
			a[ai++] = c[ci++];
		}
	}
	return cnt;
}


int main(){
	cin >> S;
	string T = "";
	int N = S.size();
	for(int i=0;i<N;i++){
		int t = S[i]-'a';
		T = T + S[N-i-1];
		A[t]++;
		v[t].push_back(-1);
	}
	int count = 0;
	for(int i=0;i<26;i++){
		if(A[i]%2==1) count++;
	}
	if(count>=2){
		cout << -1 << endl;
		return 0;
	}
	vector<ll> L,R;
	int l = 0;
	for(int i=0;i<N;i++){
		int c = S[i]-'a';
		if(A[c]%2==1 && 2*id[c]+1==v[c].size()){
			L.push_back(N/2);
			id[c]++;
		}
		else{
			if(id[c]*2<v[c].size()){
				L.push_back(l);
				v[c][id[c]] = l;
				l++;
				id[c]++;
			}else{
				int t = v[c].size()-id[c]-1;
				L.push_back(N-v[c][t]-1);
				id[c]++;
			}
		}
	}
/*	l = 0;
	for(int i=0;i<26;i++) id[i] = 0;
	for(int i=0;i<N;i++){
		int c = T[i]-'a';
		if(A[c]%2==1&& 2*id[c]+1==v[c].size()){
			R.push_back(N/2);
			id[c]++;
		}
		else{
			if(id[c]*2<v[c].size()){
				R.push_back(l);
				v[c][id[c]] = l;
				l++;
				id[c]++;
			}else{
				int t = v[c].size()-id[c]-1;
				R.push_back(N-v[c][t]-1);
				id[c]++;
			}
		}
	}
	cout << min(merge_count(L),merge_count(R)) << endl;*/
	cout << merge_count(L) << endl;
}

Measured memory_bytes: 6436
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, x := nextInt(), nextInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	sum := make([]int, n)
	for i := 0; i < n-1; i++ {
		sum[i] = a[i] + a[i+1]
	}

	// cost := 0
	// for i := 0; i < len(sum); i++ {
	// 	if sum[i] > x {
	// 		c := sum[i] - x
	// 		sum[i] -= c
	// 		sum[i+1] -= c
	// 		cost += c
	// 	}
	// 	// fmt.Println(sum)
	// }

	// fmt.Println(cost)

	count := 0
	for i := 0; i < n-1; i++ {
		if a[i]+a[i+1] > x {
			c := a[i] + a[i+1] - x
			count += c
			if a[i+1] > c {
				a[i+1] -= c
			} else {
				c -= a[i+1]
				a[i+1] = 0
				a[i] -= c
			}

			// if a[i] > a[i+1] {
			// 	a[i] -= c
			// 	count += c
			// } else if a[i] < a[i+1] {
			// 	a[i+1] -= c
			// 	count += c
			// } else {
			// 	a[i+1] -= c
			// 	count += c
			// }

		}
	}

	// fmt.Println(a)

	fmt.Println(count)
}


Measured memory_bytes: 3840
N = gets.to_i
b = gets.split.map(&:to_i)

res = []

until b.empty? do
  (1..b.length).reverse_each do |i|
    if b[i-1] == i
      res << i
      b.delete_at(i-1)
      break
    end

    if i == 1
      puts -1
      exit
    end
  end
end

puts res.reverse


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

int main(){
  int count=0;
  long N;
  cin>>N;
  vector<long>dis;
  vector<long>em;
  long a=sqrt(N);
  for(int i=1;i<=a;i++){
    if(N%i==0){
      em.push_back(i);
    }
  }
  dis=em;
  rep(i,em.size()){
    dis[i]=em[i]+N/em[i];
  }
  cout<<*min_element(dis.begin(),dis.end())-2;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    unsigned long int x;
    cin >> x;
    unsigned long int i, val;
    val = 100;
    
    for (i=1; i<10E5; i++) {
      val = val * 1.01;
      if (x <= val) {
        cout << i << endl ;
        return 0;
      }
    }
    return 0;
}


Measured memory_bytes: 3632
// A - Circle
// https://atcoder.jp/contests/abc145/tasks/abc145_a
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;
const ll mxsize = 3e5 + 5;
const ll linf = 1e9;
const long double inf = 10000000000.0;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1e9 + 7;

/******************************************** CODE STARTS FROM HERE *************************************************/ 

int main()
{
  ll r;
  cin >> r;
  cout << r * r << endl;
}

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

int main() {
    ll K;
    cin >> K;
    ll x = 7;
    for (int i = 0; i < K; ++i) {
        if (x % K == 0) {
            cout << i+1 << endl;
            return 0;
        }
        x = (x*10 + 7) % K;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3632
h,w = map(int,input().split())
a = []
for i in range(h):
    b = [int(i) % 2 for i in input().split()]
    a.append(b)
c = []
odd = 0
n = 0
while n <h:
    if odd == 0:
        for i in range(w):
            c.append([n,i])
        odd = 1
    elif odd == 1:
        for i in range(w-1,-1,-1):
            c.append([n,i])
        odd = 0
    n +=1
ans = []
for i in range(len(c)):
    if a[c[i][0]][c[i][1]] == 1:
        if i == len(c)-1:
            break
        ans.append([str(c[i][0]+1), str(c[i][1]+1), str(c[i+1][0]+1), str(c[i+1][1]+1)])
        a[c[i+1][0]][c[i+1][1]] +=1
print(len(ans))
for i in range(len(ans)):
    print(' '.join(ans[i]))

Measured memory_bytes: 81724
n=int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

m=0
at=-1
for i,ai in enumerate(a):
    m+=b[ai-1]
    if ai == at+1:
        m+=c[at-1]
    at=ai
print(m)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

typedef long long int64;

struct shop {
  int64 price;
  int number;
};

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

int asc(const void *a, const void *b){
    struct shop *x = (struct shop *)a;
    struct shop *y = (struct shop *)b;

    if(x->price > y->price)
        return 1;
    if(x->price < y->price)
        return -1;
    return 0;
}

void arrdump(struct shop *arr, int len) {
  for (int i = 0; i < len; i++) {
    eprintf("[%d].number = %d\n", i, arr[i].number);
    eprintf("[%d].price = %lld\n", i, arr[i].price);
  }
}

int main(int argc, const char *argv[])
{
  int n, m;
  scanf("%d%d", &n, &m);
  struct shop s[100000];
  for (int i = 0; i < n; i++) {
    scanf("%lld%d", &s[i].price, &s[i].number);
  }
  qsort(s, n, sizeof(struct shop), asc);
  // arrdump(s, n);
  int64 bought = 0;
  int64 sum = 0;
  for (int i = 0; i < n; i++) {
    int64 rest = m - bought - s[i].number;
    if ( rest < 0 ) {
      int64 buy = s[i].number + rest;
      bought += buy;
      eprintf("sum(%lld) += buy(%lld) * [%d].price(%lld)\n", sum, buy, i, s[i].price);
      sum += buy * s[i].price;
      break;
    } else {
      bought += s[i].number;
      sum += s[i].number * s[i].price;
      eprintf("sum(%lld) += [%d].number(%d) * [%d].price(%lld)\n", sum, i, s[i].number, i, s[i].price);
    }
  }
  printf("%lld\n", sum);

  return 0;
}

Measured memory_bytes: 3324
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int h,w;
    cin >> h >> w;
    int a[h+2][w+2];

    for (int i = 0; i < h+2; i++){
        for (int k = 0; k < w+2; k++){
            a[i][k] = 0;
        }
    }
    char x;
    for (int i = 1; i < h+1; i++){
        for (int k = 1; k < w+1; k++){
            cin >> x;
            if (x == '.'){
                a[i][k] = 0;
            } else {
                a[i][k] = 10;
            }
        }
    }
    for (int i = 1; i < h+1; i++){
        for (int k = 1; k < w+1; k++){
            if (a[i][k] >= 10){
                for (int p = i-1; p < i+2; p++){
                    for (int m = k-1;  m < k+2; m++){
                        if (p == i && m == k) continue;
                        a[p][m]++;
                    }
                }
            }
        }
    }
    for (int i = 1; i < h+1; i++){
        for (int k = 1; k < w+1; k++){
            if (a[i][k] >= 10){
                cout << "#" ;
            } else {
                cout << a[i][k];
            }
        }
        cout << endl;
    }
    return 0;

}


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

using namespace std;

int main()
{
	int A, B;

	cin >> A;
	cin >> B;

	if (A > 9 || B > 9)
	{
		cout << "-1";
	}
	else
	{
		cout << A * B;
	}


	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 二項係数(N<=10^7) //////////

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

// テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll 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;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//////////////////////////////////////////////////

int main(){
  ll N,ans=0,cnt=0;
  cin>>N;
  ll A[N+1],S[N+1],SS[N+1];
  S[0]=0;
  SS[0]=0;
  RREP(i,N){
    cin>>A[i];
    S[i]=(S[i-1]+A[i])%MOD;
    SS[i]=(SS[i-1]+S[i])%MOD;
  }
  COMinit();
  
  ans+=S[N];
  for(int i=1; i<N; ++i){
    ans+=(S[i]-S[0])*inv[i+1];
    ans+=(S[N]-S[N-i])*inv[i+1];
    ans%=MOD;
  }
  
  for(int i=1; i<=N-2; ++i){
    cnt=2*inv[i+1]*inv[i+2]%MOD;
    cnt*=(SS[N-1]-SS[i])-(SS[N-i-1]-SS[0]);
    cnt%=MOD;
    ans+=cnt;
    ans%=MOD;
  }
  
  ans*=fac[N];
  ans%=MOD;
  if(ans<0) ans+=MOD;
  co(ans);
  return 0;
}

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

int main() {
	long long int m,i,k,n,flag=0;
	string s,t,temp;
	cin>>s;
	int cnt1=0,cnt2=0;
	for(i=0;i<3;i++){
        if(s[i]=='A'){
            cnt1++;

        }
        else{
            cnt2++;
        }
	}
	if(min(cnt1,cnt2)!=0){
        cout<<"Yes";
	}
	else{
        cout<<"No";
	}


	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, A, B = LI()
    print(min(N*A, B))




main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, m;
    cin >> n >> m;
    int x[m];
    for (int i = 0; i < m; i++) cin >> x[i];
    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    sort(x, x+m);
    vector<int> t;
    for (int i = 1; i < m; i++) {
        t.push_back(abs(x[i] - x[i - 1]));
    }
    sort(t.begin(), t.end(), greater<int>());
    ll ans = 0;
    for (int i = n - 1; i < m; i++) ans += t[i];
    cout << ans << endl;
}

Measured memory_bytes: 1276
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
}
int32_t main() {
	int t;
	t = 1;
	int cnt = 1;
	while (t--)
	{
		solve();
	}
}


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

I = 999999
minT = 999999
def temp(x):
    return t - x*0.006

for i in range(n):
    if minT >= abs(a - temp(H[i])):
        minT =  abs(a - temp(H[i]))
        I = i+1

print(I)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

class dice{
public:
  int label[7];
  void turn(char c) {
    int temp;
    if (c=='S') {
      temp=label[1];
      label[1]=label[5];
      label[5]=label[6];
      label[6]=label[2];
      label[2]=temp;
    } else if (c=='E') {
      temp=label[1];
      label[1]=label[4];
      label[4]=label[6];
      label[6]=label[3];
      label[3]=temp;
    } else if (c=='W') {
      temp=label[1];
      label[1]=label[3];
      label[3]=label[6];
      label[6]=label[4];
      label[4]=temp;
    }  else if (c=='N') {
      temp=label[1];
      label[1]=label[2];
      label[2]=label[6];
      label[6]=label[5];
      label[5]=temp;
    } else if (c=='T') {
      temp=label[2];
      label[2]=label[3];
      label[3]=label[5];
      label[5]=label[4];
      label[4]=temp;
    }
  }
  void out(int k){
    cout << label[k] << endl;
  }
};

int main(){
  int i,n,u,m,flag[101][102],j,k,ii;
  cin >> n;
  dice d[100];
  for (j=0;j<101;j++) {
    for (i=0;i<102;i++) {
      flag[j][i]=0;
    }
  }

  for (j=0;j<n;j++) {
    for (i=1;i<7;i++){
      cin >> d[j].label[i];
      flag[j][d[j].label[i]]+=1;
      flag[j][101]+=d[j].label[i];
    }

    for (k=0;k<j;k++) {
      if (flag[j][101]==flag[k][101]) {
        for (ii=1;ii<7;ii++){
          if (flag[j][d[j].label[ii]]!=flag[k][d[j].label[ii]]) break;
          if (ii==6) {
            if (d[j].label[2]==d[k].label[1]) {
              d[j].turn('N');
            } else if (d[j].label[5]==d[k].label[1]) {
              d[j].turn('S');
            } else {
              while (d[j].label[1]!=d[k].label[1]) {
                d[j].turn('W');
              }
            }
            int f=0;
            while (d[j].label[2]!=d[k].label[2]) {
              ii++;
              d[j].turn('T');
              if (ii==10) break;
            }
            for (i=3;i<7;i++) {
              if (d[j].label[i]!=d[k].label[i]) {
                f=1;
                break;
              }
            }
            if (f==0) {
              cout << "No" << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 3128
import java.util.Scanner;

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

			int cnt = 0;
			for (int x = 0; x <= maxValue; x++) {
				for (int y = 0; y <= maxValue; y++) {
					int z = S - x - y;
					if (z >= 0 && z <= maxValue) cnt++;
				}
			}
			System.out.println(cnt);

		}
	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
int main(void) {
    long long a, b, c, k, i, s;

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> k;
    s = 0;
    if (k - a < 0) {
        s += k;
        k = 0;
    }
    else {
        //cout << k << " " <<s << endl;
        s = s + 1 * a;
        k -= a;
        if (k - b < 0) {
            k = 0;
        }
        else {
            k = k - b;
            //cout << k << " " << s << endl;
            if (k - c < 0) {
                s = s -k;
            }
            else {
                s = s  -c;
            }
        }
    }
    cout << s;

    return 0;
}

Measured memory_bytes: 3636
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Q] = [int(input_raw[0]), int(input_raw[1])]

    input_raw = read_func().strip().split()
    S = input_raw[0]
    AC_count = [0 for i in range(len(S) + 1)]
    for i in range(1, len(S)):
        if S[i - 1] + S[i] == "AC":
            AC_count[i] = AC_count[i - 1] + 1
        else:
            AC_count[i] = AC_count[i - 1]
    for i in range(Q):
        input_raw = read_func().strip().split()
        [L, R] = [int(input_raw[0]), int(input_raw[1])]
        print AC_count[R - 1] - AC_count[L - 1]


if __name__ == '__main__':
    main()


Measured memory_bytes: 9988
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int l[100100];
    int r[100100];
    int ans = 0;
    for(int i = 0; i < m; i++) cin >> l[i] >> r[i];
    sort(l, l+m);
    sort(r, r+m);
    int rmin = r[0];
    int lmax = l[m-1];
    
    if(rmin < lmax) cout << 0 << endl;
    else cout << rmin - lmax + 1 << endl;
}


Measured memory_bytes: 1024
/*                                                                                 
	Author :- Gaurang_Kothiya
	
	Quote :- " Practice makes a man perfect. "		
*/  
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  
 
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 998244353



void Solve()
{
	ll a,v,b,w;
	ld t;
	cin>>a>>v>>b>>w>>t;
	if(w>=v) cout<<"NO";
	else
	{
		ll dist= abs(a-b);
		ll dif= abs(v-w);
		ld tm= (1.0*dist) / (1.0*dif) ;
		if(tm <= t) cout<<"YES";
		else cout<<"NO"; 
	}
} 
 
signed main() 
{
	speed		
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
} 

Measured memory_bytes: 3744