akhauriyash/Code-Regression huggingface dataset:
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

int cm[200000];

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}
string s;


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}

int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);
 string s=RS();
 for(int i=0;i<s.size();++i){
  if(s[i]=='9'){
   cout<<"Yes\n";
  
   return 0;
 }}
  cout<<"No\n";
  
 }




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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> X(M);
  for(int i=0;i<M;i++)cin>>X.at(i);
  sort(X.begin(),X.end());
  int kyori=X.at(M-1)-X.at(0);
  
  if(M==1||N>=M){
    cout << 0 << endl;
  }else{
    vector<int> sa(M-1);
    for(int i=0;i<M-1;i++){
      sa.at(i)=X.at(i+1)-X.at(i);
    }
    sort(sa.begin(),sa.end());
    int minos=0;
    for(int i=0;i<N-1;i++){
      minos += sa.at(M-2-i);
    }
    cout << kyori-minos << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 3e5+9;
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    // submit at https://atcoder.jp/contests/abc108/
    int x; cin >> x;
    int n = __lg(x)+1;
    int m =  (n-1)*2 + __builtin_popcount(x) - 1;
    cout << n << " " << m << "\n";
    for(int i = 1; i < n; i++) {
        cout << i << " " << i+1 << " " << 0 << "\n";
        cout << i << " " << i+1 << " " << (1<<(n-i-1)) << "\n";
    }
    for(int b = 0; b < n-1; b++) {
        if((x >> b) & 1) {
            cout << 1 << " " << n-b << " " << ((x >> (b+1)) << (b+1)) << "\n";
        }
    }

    

    return 0;
    
}

Measured memory_bytes: 256
n,d=map(int,input().split())
x = [[int(i) for i in input().split()] for _ in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        check = 0
        for k in range(d):
            check += (x[i][k]-x[j][k])**2
        if check**.5 == int(check**.5):
            ans +=1
print(ans)

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

int main(){
	int N, i;
	string s;
	cin >> N;

	int y=0;
	for( i=0; i<N; i++ ){
		cin >> s;
		if ( s == "Y") y=1;
	}
	if( y ){
	        cout << "Four" << endl;
	}
	else{
		cout << "Three" << endl;
	}
}


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

using namespace std;

int main()
{
    int h, n; cin >> h >> n;
    vector<int> a(n);
    int t = 0;
    string ans = "No";

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

    for (int i = 0; i < n; ++i) {
        t += a[i];
        if (t >= h) {
            ans = "Yes";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    int n, t;
    cin >> n >> t;
    
    int A[n];
    REP(i, n) cin >> A[i];
    long long cnt = t;
    if(n > 1){
        FOR(i, 1, n){
            if(A[i - 1] + t <= A[i]) cnt += t;
            else cnt += A[i] - A[i - 1];
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
#include <queue>
 

using namespace std;

int main() {
    char s;
    cin >> s;
    
    if(isupper(s)){
        cout << "A" << endl;
    }
    else cout << "a" << endl;
    return 0;
 }


Measured memory_bytes: 3556
import java.util.*;

public class Main {
  public static void main(final String[] args) {
    final Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    sc.close();

    int start = Math.max(A, C);
    int end = Math.min(B, D);
    int ans = end - start;
    if (ans < 0) {
      ans = 0;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
mod = 10**9 + 7

def nCk(n,k,p):
    global mod
    k = min(k, n-k)
    
    X = 1
    for i in range(k):
        X = X * (n - i) % p
        X = X * pow(i + 1, p - 2, p) % p
    return X

X,Y = map(int, input().split())

ans = 0
if X <= 2*Y and Y <= 2*X and (X + Y) % 3 == 0:
    a = (2*Y-X) // 3
    b = (2*X-Y) // 3
    ans = nCk(a + b, b, mod)
print(ans)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vi w;
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	bool on = false;
	for(int i=0;i<n;i++) {
		int val = s[i]-'1';
		w.push_back(val);
		on = on || (val == 1);
	}
	int cho = n-1;
	int res = 0;
	if(on) {
		for(int i=0;i<n;i++) {
			if((w[i] == 1) && ((i & cho) == i)) {
				res ^= 1;
			}
		}
	} else {
		for(int i=0;i<n;i++) {
			if((w[i] == 2) && ((i & cho) == i)) {
				res ^= 2;
			}
		}
	}
	cout << res << '\n';
}


Measured memory_bytes: 7804
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

char s[10];

int main(void) {
    std::scanf("%s", s);
    for (int i = 0; s[i + 1] != '\0'; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            std::puts("Yes");
            return 0;
        }
    }
    std::puts("No");
    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const ll inf = 1e18 + 5;

struct UnionFind {
  vi parent, rank, count;
  UnionFind(const int nodeSize)
    : parent(nodeSize), rank(nodeSize, 1), count(nodeSize) {
    rep(i, nodeSize) parent[i] = i, count[i] = 1;
  }
  int find(int x) {
    if (parent[x] == x) return x;
    return parent[x] = find(parent[x]);
  }
  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    if (rank[rx] < rank[ry]) swap(rx, ry);
    parent[ry] = rx;
    count[rx] += count[ry];
    if (rank[rx] == rank[ry]) ++rank[rx];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int num(int x) {
    return count[find(x)];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  struct Edge { int to, cost; };
  vector<vector<Edge>> tree(n);
  rep(i, n-1) {
    int u, v, w; std::cin >> u >> v >> w;
    u--, v--, w = w & 1;
    tree[u].pb({v, w}), tree[v].pb({u, w});
  }
  vl ans(n, inf);
  ans[0] = 0;
  vi que; que.pb(0);
  rep(i, que.size()) {
    int cur = que[i];
    for (auto edge : tree[cur]) {
      if (ans[edge.to] != inf) continue;
      ans[edge.to] = (ans[cur]+edge.cost)&1;
      que.pb(edge.to);
    }
  }
  rep(i, n) std::cout << (ans[i]&1) << "\n";
}


Measured memory_bytes: 7804
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

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

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll l = a * (n - 1) + b, u = a + b * (n - 1);
    cout << max(0ll, u - l + 1) << endl;
}

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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    string S;

    cin>>S;

    if(S=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(S=="Cloudy")
        cout<<"Rainy"<<endl;
    else
        cout<<"Sunny"<<endl;
    


    return 0;
}

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

for i in range(n):
    a[i] -= 1

l = [-1] * n
l[0] = 0
now = 0

while True:
    nex = a[now]
    if l[nex] != -1:
        lap = l[now] + 1 - l[nex]
        break
    l[nex] = l[now] + 1
    now = nex

if k <= l[now]:
    print(l.index(k) + 1)
else:
    k = l[nex] + (k - l[nex]) % lap
    print(l.index(k) + 1)

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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll mod = 1000000007;
const ll INF = 1ll << 50;


ll n;
ll k;
ll a[1 << 20];
unordered_map<ll,ll> m;
ll ans;

int main(){
  cin >> n >> k;
  for(ll i = 1;i <= n;i++) cin >> a[i];
  for(ll i = 1;i <= n;i++) a[i] = a[i]+k-1;
  for(ll i = 1;i <= n;i++) a[i] += a[i-1];
  for(ll i = 1;i <= n;i++) a[i] = (a[i]+k)%k;
  // for(ll i = 0;i <= n;i++){
  //   cerr << a[i] << " ";
  // }
  // cerr << endl;
  queue<ll> q;
  for(ll i = 0;i <= n;i++){
    ans += m[a[i]];
    m[a[i]]++;
    q.push(a[i]);
    if(q.size() >= k){
      m[q.front()]--;
      q.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 11720
#include <iostream>
#include <algorithm>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b;
 	cin >> a>>b;
 	int x[3];
 	x[0]=a-b;
 	x[1]=a+b;
 	x[2]=a*b;
 	sort(x,x+3);
 	cout << x[2] << endl;
 }

Measured memory_bytes: 256
N, M = map(int, input().split())
l = [-1]*N
f = []
cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if l[a] < 0 and l[b] < 0:
        f.append([a, b])
        l[a] = cnt
        l[b] = cnt
        cnt += 1
    elif l[a] >= 0 and l[b] < 0:
        f[l[a]].append(b)
        l[b] = l[a]
    elif l[b] >= 0 and l[a] < 0:
        f[l[b]].append(a)
        l[a] = l[b]
    elif l[b] != l[a]:
        if len(f[l[a]]) > len(f[l[b]]):
            for i in f[l[b]]:
                l[i] = l[a]
                f[l[a]].append(i)
        else:
            for i in f[l[a]]:
                l[i] = l[b]
                f[l[b]].append(i)
ans = 1
for l in f:
    ans = max(ans, len(l))
print(ans)


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

using namespace std;

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


int main() {
    /* code */
    int n;
    cin>>n;
    vector<long long> A(n+10);
    A.at(0)=2;
    A.at(1)=1;
    rep(i,n-1){
        A.at(i+2)=A.at(i+1)+A.at(i);

    }
    cout<<A.at(n)<<endl;
    return 0;
    
}



Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 2e5 + 10;
int n, k;
int a[maxN];
int delta[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> k;
//    n = 2e5;
//    k = 2e5;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i < k; i++) {
        memset(delta, 0, sizeof delta);
        for (int j = 1; j <= n; j++) {
            int l = max(1, j - a[j]);
            int r = min(n + 1, j + a[j] + 1);
            delta[l]++;
            delta[r]--;
        }
        bool is_b = false;
        for (int p = 1; p <= n; p++) {
            delta[p] += delta[p - 1];
            a[p] = delta[p];
            if (a[p] < n) is_b = true;
        }
        if (!is_b) break;
    }
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
    return 0;
}

Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k)
    cout<<s<<endl;
    else
    {
        string t=s.substr(0,k)+"...";
        cout<<t<<endl;
    }
    
}

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

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<int> score(N);
    for(int i = 0; i < N; i++)
      cin >> score[i];
    sort(score.begin(), score.end());
    cout << accumulate(&score[1], &score[N-1], 0) / (N - 2) << endl;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int dp[100100];
    rep(i, 100100) dp[i] = 2 * pow(10, 9);
    dp[0] = 0;
    rep(i, n) {
        chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 3976
#include <stdio.h>

int main(){

int a=0,b=0,c=0;

	scanf("%d %d %d",&a,&b,&c);

	if(a<=b&&b<=c)
	printf("%d %d %d\n",a,b,c);
	else if (a<=c&&c<=b)
    printf("%d %d %d\n",a,c,b);
	else if(b<=c&&c<=a)
	printf("%d %d %d\n",b,c,a);
	else if(b<=a&&a<=c)
	printf("%d %d %d\n",b,a,c);
	else if(c<=a&&a<=b)
	printf("%d %d %d\n",c,a,b);
	else if(c<=b&&b<=a)
	printf("%d %d %d\n",c,b,a);
	
	return 0;
	
}

Measured memory_bytes: 596
#include<iostream>
#include<map>
using namespace std;
using I = long long;
#define rep(i,n) for(I i=0;i<n;++i)
int main(){
  I n;
  cin>>n;
  map<I,I> m;
  I a=0;
  I ans=0;
  m[a]=1;
  rep(i,n){
    I b;
    cin>>b;
    a+=b;
    ans+=m[a]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 12800
import Data.List

main=do
    n <- getLine
    xs <- words <$> getLine
    print $ ans (read n :: Int) (sort (map (read::String -> Int) xs))

ans n xs = ans' n (drop (div (n) 2) xs)

ans' n xs = if (even n)
            then (sum xs)*2 - (last xs)
            else (sum xs)*2 - (last xs) - (head xs)

Measured memory_bytes: 89548
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n; cin>>n;
    set<ll> s;
    vector<ll> q;
    rep(i,n){
        ll a; cin>>a;
        if(s.count(a)){
            q.push_back(a); s.erase(a);
        }
        else s.insert(a);
    }
    if(q.size()<=1){
        cout<<0<<endl;
    }
    else{
        sort(al(q));
        ll N=q.size();
        cout<<q[N-1]*q[N-2]<<endl;
    }
}

Measured memory_bytes: 8276
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,x,y;
	cin >> n;
	vector<P> r(n);
	vector<P> b(n);
	for(int i = 0; i < n; i++) {
		cin >> x >> y;
		r[i] = mp(x,y);
	}
	for(int i = 0; i < n; i++) {
		cin >> x >> y;
		b[i] = mp(x,y);
	}

	sort(ALL(r));
	sort(ALL(b));
	vector<int> used(n,0);
	int ans = 0;
	for(int i = 0; i < n; i++) {//青のループ
		int index = -1;
		int ymax = -1;
		for(int j = 0; j < n; j++) {//赤のループ x,yが青より小さいなかで、yが最大のものを探索
			if (used[j] == 0 && r[j].fs < b[i].fs && r[j].sc < b[i].sc && ymax < r[j].sc){
				ymax = r[j].sc;
				index = j;
			}
		}
		if(index > -1){
			used[index] = 1;//rを使用済みにする。
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
mod = 998244353
frac = [1]*3000000
for i in range(2,3000000):
    frac[i] = i * frac[i-1]%mod
fraci = [None]*3000000
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -3000000-1, -1):
    fraci[i] = fraci[i+1] * (3000000+ i + 1) % mod
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%mod


N, M = map(int, input().split())
A = (comb(3*M+N-1, 3*M) - N*(comb(N+M-2, M-1)))%mod
B = 0
if N >= M+1:
    for j in range(M+1, 3*M+1):
        if (3*M-j)%2 == 1:
            continue
        k = (3*M-j)//2
        B = (B+comb(N, j)*comb(k+N-1,k))%mod
        
print((A-B)%mod)


Measured memory_bytes: 158044
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a,n) for(int i = 0; i < n; i++) cin >> a[i];
#define ffor(n) for(int i = 0; i < n; i++)
 
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef unordered_map<string,int> umsi;

int a[100005], dp[100005];
int n, k;

int frog(int index)
{
    if(index == n-1)
        return 0;

    if(dp[index] != -1)
        return dp[index];    
    int low = INT_MAX;
    for(int i = index + 1; i <= min(n-1, index+k); i++)
    {
        low = min(low, abs(a[i] - a[index]) + frog(i));
    }
    return dp[index] = low;
}
 
int32_t main()
{
    fast_io;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    { 
        cin >> a[i];    
        dp[i] = -1;
    }

    cout << frog(0);

    return 0;
}

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

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> x(n), l(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> l[i];

    vector<pair<int, int>> p(n);
    for(int i = 0; i < n; i++) p[i] = make_pair(x[i] + l[i], x[i] - l[i]);

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

    int cor = -1e18;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(cor <= p[i].second) {
            ans++;
            cor = p[i].first;
        }
    }

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

Measured memory_bytes: 6432
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
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; }

int main() {
    string s, t; cin >> s >> t;

    vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1, 0));
    for (int i = 0; i < s.length(); i++) {
        for (int j = 0; j < t.length(); j++) {
            if (s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1);
            chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }
    string res = "";
    int i = s.length(), j = t.length();
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i - 1][j]) {
            --i;
        } else if (dp[i][j] == dp[i][j - 1]) {
            --j;
        } else {
            res += s[i - 1];
            --i, --j;
        }
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <utility>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <cmath>
#define ls(x) x<<1
#define rs(x) x<<1|1
#define low(x) (x&-x)
#define mp make_pair
#define X first
#define Y second
#ifdef _DEBUG
    const int N=1e3+10;
#else
    const int N=2e3+10;
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef double db;
const ll mod=1e9+7;
template<typename T> inline T gcd(T a,T b){return !b?a:gcd(b,a%b);}
template<typename T> inline T q_pow(T a,T x){T ans=1,tmp=a;while(x){if(x&1)(ans*=tmp)%=mod;(tmp*=tmp)%=mod;x>>=1;}return ans;}
template<typename T> inline void re(T &N){int f=1;char c;while((c=getchar())< '0'||c> '9')if(c=='-')f=-1;N=c-'0';while((c=getchar())>='0'&&c<='9')N=N*10+c-'0';N*=f;}
int m,n,t=1;
ll d[N][N];
pl a[N];
ll dfs(int l,int r)
{
    if(d[l][r]!=-1)return d[l][r];
    if(l==r)return a[1].X*abs(a[1].Y-l);
    d[l][r]=max(d[l][r],dfs(l+1,r)+abs(l-a[r-l+1].Y)*a[r-l+1].X);
    d[l][r]=max(d[l][r],dfs(l,r-1)+abs(r-a[r-l+1].Y)*a[r-l+1].X);
    return d[l][r];
}
int main()
{
    // freopen("data.txt","r",stdin);
    memset(d,-1,sizeof(d));
    re(n);
    for(int i=1;i<=n;i++)re(a[i].X),a[i].Y=i;
    sort(a+1,a+n+1);
    printf("%lld\n",dfs(1,n));
    return 0;
}

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

using namespace std;

int main(){
    long long N,ans=0;

    cin>>N;

    for(long long i=1;i<=N;i++){
        if(i%3 ==0 || i%5 ==0)continue;

        ans=ans+i;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
S = input()

if 'N' in S and 'S' not in S:
    print('No')
elif 'S' in S and 'N' not in S:
    print('No')
elif 'W' in S and 'E' not in S:
    print('No')
elif 'E' in S and 'W' not in S:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9040
#include<iostream>
#include<string>
using namespace std;
int main(){
	char b;
	cin>>b;
	if(b=='A'){
		cout<<"T"<<endl;
	}
	else if(b=='C'){
		cout<<"G"<<endl;
	}
	else if(b=='G'){
		cout<<"C"<<endl;
	}
	else if(b=='T'){
		cout<<"A"<<endl;
	}
}


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

int main() {
  
  int N = 0,Alice = 0,Bob = 0 , x = 0;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0 ; i < N ; i++) cin >> vec.at(i);
  //以上で入力を受け取る
  
  
  for(int j = 0 ; j < N ; j++) {
    
    
  for(int i = 0 ; i < N ; i++) {
    if(x < vec.at(i)) x = vec.at(i);
  }
  //この時点でのxは最大値
	
    
  if(j % 2 == 0) Alice += x;
  else Bob += x;
  //加点
    
  for(int i = 0 ; i < N ; i++) {
    if(vec.at(i) == x)  {
      vec.at(i) = 0;
      break;
    }
  }
  //ここでぶっ潰す
    
    x = 0;
  
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
sa = input()
sb = input()
sc = input()

ai, bi, ci = 0, 0, 0
turn = "a" 
while ai <= len(sa) and bi <= len(sb) and ci <= len(sc):
    if turn == "a":
        if ai == len(sa):
            print("A")
            break
        turn = sa[ai]
        ai += 1
    elif turn == "b":
        if bi == len(sb):
            print("B")
            break
        turn = sb[bi]
        bi += 1
    elif turn == "c":
        if ci == len(sc):
            print("C")
            break
        turn = sc[ci]
        ci += 1


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

int main(){
  int n;
  cin >> n;
  vector<int> A(n,0);
  for (int i=0; i<n; i++){
    cin >>A[i];
  }
  sort(A.begin(),A.end());
  int sum = 0;
  int i = 0;
  while(i<n){
    int count = 0;
    int tmp = A[i];
      while(tmp == A[i]){
        i++;
        count ++;
      }
    sum += count % 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
    long long int n, m;
    cin >> n >> m;
    long long int ans = 0;
    if(m>=2*n){
        ans = n; m-=2*n;
    }
    else if(m<2*n){
        ans = m/2; m=0;
    }
    ans+=(m/4);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int x;
  int y;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0 && y ==0)break;
    if(x > y){
      printf("%d %d\n",y,x);
    }
    else{
      printf("%d %d\n", x , y);
    }
  }
  return 0;
}



Measured memory_bytes: 1980
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

divisors x = divs' x 1 []
  where divs' x i ds | i*i > x        = sort ds
                     | x `mod` i == 0 = divs' x (i+1) (i:(x`div`i):ds)
                     | otherwise      = divs' x (i+1) ds

main = do
    [n, m] <- getIntList
    let ds = divisors m
        ans = head $ dropWhile (> m `div` n) $ reverse ds
    print ans

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

#define ll long long

struct UnionFind {
  vector<int> r;
  
  UnionFind(int N) {
    r = vector<int>(N, -1);
    
  }
  
  int root(int x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }
  
  
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    
    r[x] += r[y];
    r[y] = x;
    
    return true;
  }
  
  int size(int x) {
    return -r[root(x)];
  }
  
};


int main() {
  ll N, M;
  cin >> N >> M;
  
  vector<pair<int, int>> bridge(M);
  
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    
    bridge[i] = {a, b};
  }
  
  vector<ll> ans(M+1);
  
  UnionFind UF(N);

  ll temp = N * (N-1)/2;
  ans[M] = temp;
  
  for (int i = M-1; i >= 0; i--) {
    
    int A = bridge[i].first, B = bridge[i].second;
    A--; B--;
    
    if (UF.root(A) != UF.root(B)) {
      temp -= (ll)UF.size(A) * (ll)UF.size(B);
    }  
    ans[i] = temp;
    
    
    UF.unite(A, B);
    
  }
  
  for (int i = 1; i <= M; i++) {
    cout << ans[i] << endl;
  } 
  
}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define mp make_pair;
#define pb push_back;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int P,Q,R;
  cin >> P >> Q >> R;

  cout << P*Q/2 << endl;


  return 0;
    

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
int a[LIMIT2]={0},b[LIMIT1]={0};
int tmp(const void *p, const void *q){
  int n = b[*(int *)p] - b[*(int *)q];
  if(n == 0) return a[*(int *)p] - a[*(int *)q];
  else return n;
}
int main(void){
  initialize();
  ll n,m,i,j,result=1,task=0;
  int c[LIMIT1]={0};
  char s[LIMIT1];

  scanf("%lld",&n);
  rep(i,n) c[i]=i;
  rep(i,n) scanf("%d %d",&a[i],&b[i]);
  
  qsort(c,n,sizeof(int),tmp);
  
  rep(i,n){
    task += a[c[i]];
    if(task > b[c[i]]){
      result = 0;
      break;
    }
  }
  
  if(result == 1) printf("Yes");
  else printf("No");

  return 0;
}



Measured memory_bytes: 3324
def solve():
    N = int(raw_input())
    arr = []
    for i in range(N):
        arr.append(int(raw_input()))
    turning_on = 1
    count = 0
    while turning_on != 2:
        count += 1
        turning_on = arr[turning_on - 1]
        if count > N + 1:
            count = -1
            break
    print str(count)

if __name__ == '__main__':
    solve()


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

int abs(int n)
{
	if (n > 0) return (n);

	return (n * -1);
}

int max(int a, int b)
{
	a = abs(a);
	b = abs(b);

	if (a > b) return (a);

	return (b);
}

int main(void)
{
	int i;
	int n;
	int x[3], y[3];
	int t[2];
	int sum;

	
	cin >> t[0] >> t[1] >> n;
	x[0] = y[0] = 1;
	sum = 0;
	
	cin >> x[0] >> y[0];
	for (i = 0; i < n - 1; i++) {
	
		cin >> x[1] >> y[1];

		x[2] = x[1] - x[0];
		y[2] = y[1] - y[0];

		if ((x[2] > 0 && y[2] > 0) || x[2] < 0 && y[2] < 0) {
			sum += max(x[2], y[2]);
		}
		else {
			sum += abs(x[2]) + abs(y[2]);
		}

		x[0] = x[1];
		y[0] = y[1];
	}

	
	cout << sum << endl;

	return 0;
}


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

using namespace std;


int main(void){
    int n, m;
    cin >> n >> m;
    
    vector<string> a(n);
    vector<string> b(m);
    
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    
    for (int i = 0; i <= n-m; i++){
        for (int j = 0; j <= n-m; j++){
            
            bool temp_check = true;
            
            for (int k = 0; k <= m-1; k++){
                for (int l = 0; l <= m-1; l++){
                    if (a[i+k][j+l] != b[k][l]){
                        temp_check = false;
                    }
                }
            }
            
            if (temp_check == true){
                 cout << "Yes" << endl;
                 return 0;
            } 
            else continue;
            
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3608
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = read_line();

    let a = line.chars().filter(|&c| c == '0').count();
    let b = line.chars().filter(|&c| c == '1').count();
    println!("{}", cmp::min(a,b) * 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll h, w;
char s[52][52];
 
int main(int argc, char **argv) {
	cin >> h >> w;
	REP(i, 52) REP(j, 52) s[i][j] = '.';
	REP(i, h) REP(j, w) cin >> s[i+1][j+1];
	REP(i, h) REP(j, w) if (s[i+1][j+1] == '#' && s[i][j+1] == '.' && s[i+2][j+1] == '.' && s[i+1][j] == '.' && s[i+1][j+2] == '.') {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}
 

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

int main(){
  string S;
  cin >> S;
  
  if(S == "SUN")
      cout << 7;
  else if(S == "MON")
      cout << 6;
  else if(S == "TUE")
      cout << 5;
  else if(S == "WED")
      cout << 4;
  else if(S == "THU")
      cout << 3;
  else if(S == "FRI")
      cout << 2;
  else if(S == "SAT")
      cout << 1;
  
  return 0;
}


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

import sys
import os
import math


n = int(input())
p0 = (0, 0)
p1 = (100, 0)

def koch(depth, p0, p1):
    if depth == 0:
        return

    # s = 2/3 p0 + 1/3 p1
    sx = 2 / 3 * p0[0] + 1 / 3 * p1[0]
    sy = 2 / 3 * p0[1] + 1 / 3 * p1[1]
    s = (sx, sy)

    tx = 1 / 3 * p0[0] + 2 / 3 * p1[0]
    ty = 1 / 3 * p0[1] + 2 / 3 * p1[1]
    t = (tx, ty)

    theta = math.radians(60)
    ux = math.cos(theta) * (tx - sx) - math.sin(theta) * (ty - sy) + sx
    uy = math.sin(theta) * (tx - sx) + math.cos(theta) * (ty - sy) + sy
    u = (ux, uy)

    # ????????? s, u, t?????¨???
    koch(depth - 1, p0, s)
    print(*s)
    koch(depth - 1, s, u)
    print(*u)
    koch(depth - 1, u, t)
    print(*t)
    koch(depth - 1, t, p1)

print(*p0)
koch(n, p0, p1)
print(*p1)

Measured memory_bytes: 7856
#include <stdio.h>

int main() {
	int K, i, j, count = 0;

	scanf("%d", &K);
	
	for (i = 1; i <= K; i += 2) {
		for (j = 2; j <= K; j += 2) {
			count++;
		}
	}

	printf("%d", count);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  
  cin >> a >> b >> c;
  
  int total_time = c+0.5;
  
  int rounds_of_biscuit = total_time/a;
  
  cout << rounds_of_biscuit*b << endl;
  return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "Impossible"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    char c; cin >> c;
    cout << (c >= 'a' && c <= 'z' ? 'a' : 'A');
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3636
#include<map>
#include<iostream>
#include<string.h>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    int a=0,w=0,t=0,r=0;
    while(n--)

    {
        cin>>s;
        if(s[0]=='A')
            a++;
        else if(s[0]=='W')
            w++;
        else if(s[0]=='T')
            t++;
        else if(s[0]=='R')
            r++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
    return 0;
}


Measured memory_bytes: 3688
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
    int num,p;
    char name[17];
}a[107];
int cmp(node a,node b)
{
    if(strcmp(a.name,b.name)!=0)
        return strcmp(a.name,b.name)<0;
    if(a.p!=b.p)
        return a.p>b.p;
}
int main ()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s%d",a[i].name,&a[i].p);
        a[i].num=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
        printf("%d\n",a[i].num);
    return 0;
}


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

int main(){
   char ans[100];
   char s[100];scanf("%s",s);
   int i,j;
   for(i = 0;i < strlen(s);i++){
      if(s[i] == '1'){
         ans[j] = '1';
         j++;
      }else if(s[i] == '0'){
         ans[j] = '0';
         j++;
      }else 
         if(j)
            j--;
         
      
   }
   for(int i = 0;i < j;i++)
      printf("%c",ans[i]);
   
   printf("\n");
   return 0;
}

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

int MOD=1000000007;

int main(){
  string S;
  cin >> S;
  int s=S.size();
  vector<vector<long long>> dp(s,vector<long long>(13,0));
  if (S[0]=='?'){
    for (int i=0;i<10;i++){
      dp[0][i]=1;
    }
  }
  else {
    int x=S[0]-'0';
    dp[0][x]=1;
  }
  for (int i=0;i<s-1;i++){
    if (S[i+1]=='?'){
      for (int j=0;j<13;j++){
        for (int k=0;k<10;k++){
          dp[i+1][(j*10+k)%13]=(dp[i+1][(j*10+k)%13]+dp[i][j])%MOD;
        }
      }
    }
    else {
      int x=S[i+1]-'0';
      for (int j=0;j<13;j++){
        dp[i+1][(j*10+x)%13]=(dp[i+1][(j*10+x)%13]+dp[i][j])%MOD;
      }
    }
  }
  cout << dp[s-1][5] << endl;
}

Measured memory_bytes: 13696
import sys
N = int(input())
A = [int(c) for c in input().split()]
B = [0]*(N+1)
B[0] = 1
if A[0]>=1:
  if N==0 and A[0]==1:
    print(1)
  else:
    print(-1)
  sys.exit()
for i in range(1,N+1):
  B[i] = B[i-1]*2-A[i]
  if B[i]<0:
    print(-1)
    sys.exit()
ans = sum(A)
num = 0
for i in range(N,0,-1):
  num = min(num+A[i],B[i-1])
  ans += num
print(ans)

Measured memory_bytes: 705636
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, m; cin >> n >> m;
    if(n % 2 == 1) {
        rep(j, m) {
            cout << j + 1 << " " << n - j - 1 << endl;
        }
    } else {
        set<int> se;
        int co = 0;
        vector<bool> used(n + 1, 0);
        for(int i = n - 1; i >= 1; -- i) {
            if(i * 2 == n) continue;
            if(se.find(i) == se.end() && se.find(n - i) == se.end()) {
                if(used[co + 1] || used[co + 1 + i]) continue;
                cout << co + 1 << " " << co + 1 + i << endl;
                used[co + 1] = 1;
                used[co + 1 + i] = 1;
                se.insert(i);
                se.insert(n - i);
                ++ co;
            }
            if(co == m) break;
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 9964
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <vector>
#include <string>
#include <algorithm>

int parse(const std::string &s, size_t &i) {
  assert(s[i] == '[');
  ++i;
  if (isdigit(s[i])) {
    int res=s[i]-'0';
    while (++i < s.length() && isdigit(s[i])) {
      res = res*10 + s[i]-'0';
    }
    assert(s[i] == ']');
    ++i;
    return (res+1)/2;
  }

  std::vector<int> vec;
  while (s[i] == '[') {
    vec.emplace_back(parse(s, i));
  }
  std::sort(vec.begin(), vec.end());
  int res=0;
  for (size_t j=0; j<(vec.size()+1)/2; ++j)
    res += vec[j];

  assert(s[i] == ']');
  ++i;
  return res;
}

void solve_testcase() {
  char buf[16384];
  scanf("%s", buf);
  std::string s=buf;
  size_t i=0;
  printf("%d\n", parse(s, i));
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i=0; i<n; ++i)
    solve_testcase();
}



Measured memory_bytes: 2764
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-12;

class Compare {
  int monster_x;
  int monster_y;
public:
  Compare(int monster_x,int monster_y)
    : monster_x(monster_x), monster_y(monster_y) {}
  bool operator()(const P& ci,const P& cj) const{
    int dist_i = (ci.first - monster_x) * (ci.first - monster_x)
      + (ci.second - monster_y) * (ci.second - monster_y);
    int dist_j = (cj.first - monster_x) * (cj.first - monster_x)
      + (cj.second - monster_y) * (cj.second - monster_y);
    return dist_i < dist_j;
  }
};

class State{
  int x;
  int y;
  double dist;
};

bool dfs(int hero_x,
         int hero_y,
         double current_time,
         int S,
         int monster_x,
         int monster_y,
         const vector<P>& cristals){
  bool res = false;

  if(S == (1<<cristals.size()) - 1) return true;
  for(int i=0;i<cristals.size();i++){
    if(S & (1<<i)) continue;
    double add_time = sqrt((hero_x - cristals[i].first) * (hero_x - cristals[i].first)
                           + (hero_y - cristals[i].second) * (hero_y - cristals[i].second));
    
    double tmp_current_time = current_time + add_time;
    double impurity_arrive_time = sqrt((monster_x - cristals[i].first) * (monster_x - cristals[i].first)
                                       + (monster_y - cristals[i].second) * (monster_y - cristals[i].second));
    if(tmp_current_time >= impurity_arrive_time){
      return false;
    }
    
    res |= dfs(cristals[i].first,cristals[i].second,tmp_current_time,
               S | (1<<i),monster_x,monster_y,cristals);
  }
  return res;
}

int main(){
  int total_cristals;
  int hero_x;
  int hero_y;
  int monster_x;
  int monster_y;
  while(~scanf("%d %d %d %d %d",
               &total_cristals,
               &hero_x,
               &hero_y,
               &monster_x,
               &monster_y)){
    if(total_cristals == 0 && hero_x == 0 && hero_y == 0
       && monster_x == 0 && monster_y == 0) break;
    vector<P> cristals;
    for(int cristal_i = 0; cristal_i < total_cristals; cristal_i++){
      int x,y;
      scanf("%d %d",&x,&y);
      cristals.push_back(P(x,y));
    }
    Compare comp(monster_x,monster_y);
    sort(cristals.begin(),cristals.end(),comp);
    printf("%s\n", dfs(hero_x,hero_y,0,0,monster_x,monster_y,cristals)
           ? "YES" : "NO");
  }
}

Measured memory_bytes: 1168
N = int(input())

works = []

for i in range(N):
    a, b = map(int, input().split())
    works.append((a, b))

works = sorted(works, key=lambda w: w[1])

deadtime = works[-1][1]

t = 0
ok = True
for w in works:
    if t + w[0] <= w[1]:
        t += w[0]
    else:
        ok = False
        break


if ok:
    print("Yes")
else:
    print("No")


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

typedef long long ll;
ll const mod = 998244353;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m;
    cin >> n >> m;
    bool a[n][m];
    int r = 0;
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) cin >> a[i][j];
    for (int i = 0;i < min(n,m);++i) {
        int p = i,q = i;
        for (int j = i;j < n;++j) {
            if (a[p][q]) break;
            for (int k = i;k < m;++k) if (a[j][k]) {
                p = j;q = k;
                break;
            }
        }
        if (!a[p][q]) break;
        r = i+1;
        for (int j = i;j < n;++j) swap(a[j][i],a[j][q]);
        for (int j = i;j < m;++j) swap(a[i][j],a[p][j]);
        for (int j = i+1;j < n;++j) if (a[j][i]) for (int k = i;k < m;++k) a[j][k] ^= a[i][k];
        for (int j = i+1;j < m;++j) if (a[i][j]) for (int k = i;k < n;++k) a[k][j] ^= a[k][i];
    }
    int x = 1,y = 1;
    for (int i = 0;i < n+m-1;++i) {
        x <<= 1;
        x %= mod;
    }
    for (int i = 0;i < n+m-r-1;++i) {
        y <<= 1;
        y %= mod;
    }
    cout << (x-y+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 384