akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
 
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))
 
typedef long long ll;

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int n, a[3][3], b[10];
  bool appear[3][3];
  
  rep(i,3) {
    rep(j,3) {
      cin>>a[i][j];
    }
  }
  
  cin>>n;
  
  rep(i,n) {
    cin>>b[i];
  }
  
  rep(i,3) {
    rep(j,3) {
      appear[i][j]=false;
      rep(k, n) {
        if(a[i][j]==b[k]){
          appear[i][j]=true;
        }
      }
    }
  }
  
  string ans="No";

  rep(i,3){
    if(appear[i][0] and appear[i][1] and appear[i][2]) {
      ans = "Yes";
    }
  }
  
  rep(i,3){
    if(appear[0][i] and appear[1][i] and appear[2][i]) {
      ans = "Yes";
    }
  }
  
  if(appear[0][0] and appear[1][1] and appear[2][2]) {
      ans = "Yes";
   }
  
  if(appear[0][2] and appear[1][1] and appear[2][0]) {
      ans = "Yes";
   }
  
  cout<<ans;
  return 0;
}

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

#define endl '\n'

int const N = 2002;
pair<long long, int> a[N];
long long dp[N][N];
int n;

long long solve(int l, int r){
    if (dp[l][r] != -1) return dp[l][r];
    int pos = l + n - 1 - r;
    if (l == r) return dp[l][r] = (a[pos].first * abs(a[pos].second - l));
    return dp[l][r] = max(solve(l+1, r) + a[pos].first*abs(a[pos].second - l), solve(l, r-1) + a[pos].first*abs(a[pos].second - r));
}

bool comp(pair<int,int> a, pair<int, int> b){
    return a.first > b.first;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> a[i].first; a[i].second = i;
    }
    sort(a, a+n, comp);
    cout << solve(0, n-1) << endl;
}

Measured memory_bytes: 35092
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
char a,b;
  int n,m,x;
  cin>>a>>b;
  if(a=='H') n=1;
  else n=0;
  if(b=='H') m=1;
  else m=0;
  x=n^m;
  if(x) cout<<'D'<<endl;
  else cout<<'H'<<endl;
  return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  int N;
  cin >> N >> S;
  int count = 0;
  for(int i = 0; i < N - 2; i++){
    if(S.substr(i, 3) == "ABC")count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
using namespace std;

// x,y,d = exgcd(m, n)
// x*m+y*n = d = gcd(m, n)
pair<pair<long long, long long>, long long> exgcd(long long m, long long n)
{
    if (n>0)
    {
        auto r = exgcd(n, m%n);
        long long y = r.first.first;
        long long x = r.first.second;
        long long d = r.second;
        return make_pair(make_pair(x, y-m/n*x), d);
    }
    else
    {
        return make_pair(make_pair(1LL, 0LL), m);
    }
}

int main()
{
    long long N;
    cin>>N;

    long long ans = N;

    //  TODO N=1
    vector<long long> F;
    vector<int> C;
    N *= 2;
    for (long long f=2; f*f<=N; f++)
    {
        if (N%f==0)
        {
            F.push_back(f);
            int c = 0;
            while (N%f==0)
            {
                N /= f;
                c++;
            }
            C.push_back(c);
        }
    }
    if (N>1)
    {
        F.push_back(N);
        C.push_back(1);
    }

    function<void(int, long long , long long)> f = [&](int p, long long x, long long y)
    {
        if (p==(int)F.size())
        {
            if (x==1LL || y==1LL)
                return;
            auto r = exgcd(x, y);
            long long a = r.first.first;
            long long b = r.first.second;
            long long m = r.second;
            if (m!=1)
                return;
            if (a<0)
                ans = min(ans, -a*x);
            else
                ans = min(ans, -b*y);
            return;
        }

        for (int i=0; i<=C[p]; i++)
        {
            long long x2 = x;
            long long y2 = y;
            for (int j=0; j<i; j++)
                x2 *= F[p];
            for (int j=i; j<(int)C[p]; j++)
                y2 *= F[p];
            f(p+1, x2, y2);
        }
    };
    f(0, 1, 1);
    cout<<ans<<endl;
}


Measured memory_bytes: 3204
#include<iostream>
#include<iomanip>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<utility>
#define For(a,b) for(int i=(a);i<(b);i++)
#define Rep(n) for(int i=0; i<(n); ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
//----------program from here----------

int main(){
    int S=0,a=0,b=0;
    cin >> S;
    a=S/100;
    b=S-a*100;
    cout << (0<a&&a<13?(0<b&&b<13?"AMBIGUOUS":"MMYY"):(0<b&&b<13?"YYMM":"NA")) << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[101],Y[101];
ll V[101];
int L[101],R[101],U[101],D[101];

int M;
string S[333];
int A[333],B[333];

template<int NV,class V> class MinCostFlow {
public:
	struct edge { int to; V capacity; V cost; int reve;};
	vector<edge> E[NV]; int prev_v[NV], prev_e[NV]; V dist[NV];
	void add_edge(int x,int y, V cap, V cost) {
		E[x].push_back((edge){y,cap,cost,(int)E[y].size()});
		E[y].push_back((edge){x,0, -cost,(int)E[x].size()-1}); /* rev edge */
	}
	
	V mincost(int from, int to, ll flow) {
		V res=0; int i,v;
		ZERO(prev_v); ZERO(prev_e);
		while(flow>0) {
			fill(dist, dist+NV, numeric_limits<V>::max()/2);
			dist[from]=0;
			priority_queue<pair<V,int> > Q;
			Q.push(make_pair(0,from));
			while(Q.size()) {
				V d=-Q.top().first;
				int cur=Q.top().second;
				Q.pop();
				if(dist[cur]!=d) continue;
				if(d==numeric_limits<V>::max()/2) break;
				FOR(i,E[cur].size()) {
					edge &e=E[cur][i];
					if(e.capacity>0 && dist[e.to]>d+e.cost) {
						dist[e.to]=d+e.cost;
						prev_v[e.to]=cur;
						prev_e[e.to]=i;
						Q.push(make_pair(-dist[e.to],e.to));
					}
				}
			}
			
			if(dist[to]==numeric_limits<V>::max()/2) return -1;
			ll lc=flow;
			for(v=to;v!=from;v=prev_v[v]) lc = min(lc, E[prev_v[v]][prev_e[v]].capacity);
			flow -= lc;
			res += lc*dist[to];
			for(v=to;v!=from;v=prev_v[v]) {
				edge &e=E[prev_v[v]][prev_e[v]];
				e.capacity -= lc;
				E[v][e.reve].capacity += lc;
			}
		}
		return res;
	}
};

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>X[i]>>Y[i]>>V[i];
	cin>>M;
	FOR(i,M) cin>>S[i]>>A[i]>>B[i];
	
	ll ret=0;
	for(int K=1;K<=N;K++) {
		MinCostFlow<450,ll> mcf;
		ZERO(L);
		ZERO(D);
		FOR(x,101) U[x]=R[x]=100;
		FOR(i,M) if(B[i]<K) {
			if(S[i]=="L") L[B[i]]=max(L[B[i]],A[i]+1);
			if(S[i]=="D") D[B[i]]=max(D[B[i]],A[i]+1);
			if(S[i]=="R") R[K-B[i]-1]=min(R[K-B[i]-1],A[i]-1);
			if(S[i]=="U") U[K-B[i]-1]=min(U[K-B[i]-1],A[i]-1);
		}
		for(i=1;i<K;i++) L[i]=max(L[i],L[i-1]), D[i]=max(D[i],D[i-1]);
		for(i=K-2;i>=0;i--) R[i]=min(R[i],R[i+1]), U[i]=min(U[i],U[i+1]);
		
		FOR(i,K) {
			mcf.add_edge(0,1+i,1,0);
			mcf.add_edge(101+i,100,1,0);
		}
		FOR(i,N) {
			mcf.add_edge(200+i,300+i,1,1000000000000000LL-V[i]);
			FOR(j,K) {
				if(L[j]<=X[i] && X[i]<=R[j]) mcf.add_edge(1+j,200+i,1,0);
				if(D[j]<=Y[i] && Y[i]<=U[j]) mcf.add_edge(300+i,101+j,1,0);
			}
		}
		ll v=mcf.mincost(0,100,K);
		if(v>=0) ret=max(ret,K*1000000000000000LL-v);
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1268
a, b, c, d = [int(_) for _ in input().split()]
mod = 998244353
dp = [0] * 3005
dp[b] = 1

for y in range(b + 1, d + 1):
    dp[y] = dp[y - 1] * a % mod
for x in range(a + 1, c + 1):
    dp2 = [0] * 3005
    dp2[b] = dp[b] * b % mod
    for y in range(b + 1, d + 1):
        dp2[y] = (dp[y] * y + dp2[y - 1] * x - dp[y - 1] * (x - 1) *
                  (y - 1)) % mod
    dp = dp2
print(dp[d])


Measured memory_bytes: 68120
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  const int Ap = 500, Bp = 100, Cp = 50;
  int A, B, C, X = 0;
  std::cin >> A >> B >> C >> X;

  int ok = 0;
  for (int a = std::min(X / Ap, A); a >= 0; a--) {
    for (int b = std::min((X - Ap * a) / Bp, B); b >= 0; b--) {
      for (int c = std::min((X - Ap * a - Bp * b) / Cp, C); c >= 0; c--) {
        if (a * Ap + b * Bp + c * Cp == X) {
          ok++;
        }
      }
    }
  }

  std::cout << ok << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    bool f=false,ans[1024][1024]={};
    int n,m;
    in>>n>>m;
    if(n<m){
        swap(n,m);
        f=true;
    }
    int t=1;
    fr(_,m){
        fr(i,t) fr(j,t){
            ans[i+t][j]=ans[i][j+t]=ans[i][j];
            ans[i+t][j+t]=!ans[i][j];
        }
        t<<=1;
    }
    int u=t;
    fr(_,n-m){
        fr(i,u) fr(j,t){
            ans[i+u][j]=ans[i][j];
        }
        u<<=1;
    }
    /*if(f){
        fr(i,(1<<m)){
            fr(j,(1<<n)) cout<<ans[j][i];
            cout<<endl;
        }
    }
    else{
        fr(i,(1<<n)){
            fr(j,(1<<m)) cout<<ans[i][j];
            cout<<endl;
        }
    }
    cout<<endl;*/
    fr(i,1<<n){
        iFr(j,(1<<m)-1){
            //cout<<i<<" "<<j<<" "<<ans[i][j]<<" "<<ans[i][j-1]<<" ";
            ans[i][j]=ans[i][j]^ans[i][j-1];
            //cout<<ans[i][j]<<endl;
        }
    }
    /*if(f){
        fr(i,(1<<m)){
            fr(j,(1<<n)) cout<<ans[j][i];
            cout<<endl;
        }
    }
    else{
        fr(i,(1<<n)){
            fr(j,(1<<m)) cout<<ans[i][j];
            cout<<endl;
        }
    }
    cout<<endl;*/

    iFr(i,(1<<n)-1){
        fr(j,1<<m){
            //cout<<i<<" "<<j<<" "<<ans[i][j]<<" "<<ans[i-1][j]<<" ";
            ans[i][j]=ans[i][j]^ans[i-1][j];
            //cout<<ans[i][j]<<endl;
        }
    }
    if(f){
        Fr(i,(1<<m)-1){
            Fr(j,(1<<n)-1) cout<<ans[j][i];
            cout<<endl;
        }
    }
    else{
        Fr(i,(1<<n)-1){
            Fr(j,(1<<m)-1) cout<<ans[i][j];
            cout<<endl;
        }
    }
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007
int acs(const void* a, const void* b) { return *(int*)a - *(int*)b; } // 1,2,3,4
int des(const void* a, const void* b) { return *(int*)b - *(int*)a; } // 8,7,6,5
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
//temmie_のsnippet

#define N 100009

int main(){
    int n,k,r,s,p,i;
    int cr=0,cs=0,cp=0;
    char t[N];
    scanf("%d%d%d%d%d%s",&n,&k,&r,&s,&p,t);

    Rep(i,k,n)if(t[i]==t[i-k])t[i]='a';
    i=0;
    while(t[i]){
        if(t[i]=='r')cp++;
        else if(t[i]=='s')cr++;
        else if(t[i]=='p')cs++;
        i++;
    }

    printf("%d",r*cr+s*cs+p*cp);
    return 0;
}

Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  string S,T;
  cin >> S >> T;
  int ns = S.length(), nt = T.length();
  ll ans = 10000000;
  for (int i = 0; i < ns; ++i) {
    string s = S.substr(i, nt);
    if (s.length() < nt) break;
    ll n_diff = 0;
    for (int j = 0; j < nt; ++j) n_diff += s[j] != T[j];
    ans = min(ans, n_diff);
  }
  cout << ans << endl;
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;


struct LowLink{
    vector<vector<int>>& edges;
    // 関節点
    vector<int> art;
    vector<pair<int,int>> bridge;

    vector<int> used, ord, low;
    int k;

    void dfs(int idx, int par){
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_art = false;
        int cnt = 0;
        for(auto& to : edges[idx]){
            if(ord[to] == -1){
                ++cnt;
                dfs(to, idx);
                low[idx] = min(low[idx], low[to]);
                is_art |= par != -1 && low[to] >= ord[idx];
                if(ord[idx] < low[to])
                    bridge.emplace_back(idx, to);
            }else if(to != par)
                low[idx] = min(low[idx], ord[to]);
        }
        is_art |= (par == -1 && cnt > 1);
        if(is_art)
            art.emplace_back(idx);
    }

    LowLink(vector<vector<int>>& edges) :
        edges(edges),
        ord(edges.size(), -1),
        low(edges.size(), 0),
        k(0)
    {
        for(int i = 0; i < edges.size(); ++i)
            if(ord[i] == -1)
                dfs(i, -1);
        for(auto& b : bridge)
            b = make_pair(min(b.first, b.second), max(b.first, b.second));
        sort(art.begin(), art.end());
        sort(bridge.begin(), bridge.end());
    }
};


signed main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        vector<int> l(2);
        for(auto& x : l)
            cin >> x;
        sort(l.begin(), l.end());
        v[i] = make_pair(l.front(), l.back());
        edges[l[0]].emplace_back(l[1]);
        edges[l[1]].emplace_back(l[0]);
    }
    LowLink ll(edges);
    for(auto& x : ll.bridge)
        cout << x.first << " " << x.second << endl;
}



Measured memory_bytes: 4756
N, M = map(int, input().split())

mod = 10 ** 9 + 7
ans = 1
if abs(N - M) >= 2:
    print(0)

else:
    for i in range(1, N+1):
        ans *= i
        ans %= mod
    for i in range(1, M+1):
        ans *= i
        ans %= mod
    if N == M:
        ans *= 2
        ans %= mod        
    print(ans)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final UnionFindTree tree = new UnionFindTree(n + 1);
        final boolean[] exists = new boolean[n + 1];
        for (int i = 0; i < m; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            tree.unit(a, b);
            exists[a] = true;
            exists[b] = true;
            scanner.nextInt();
        }

        final Set<Integer> countSet = new HashSet<>();
        final long count = IntStream.rangeClosed(1, n)
                .mapToObj(i -> exists[i])
                .filter(b -> !b)
                .count();

        IntStream.rangeClosed(1, n)
                .filter(i -> exists[i])
                .mapToObj(tree::getRoot)
                .forEach(countSet::add);

        System.out.println(count + countSet.size());
    }

    private static class UnionFindTree {
        private Integer[] nodes;
        private final List<Integer> indices = new ArrayList<>();

        UnionFindTree(final int numOfNodes) {
            this.nodes = init(numOfNodes);
        }

        private Integer[] init(final int numOfNodes) {
            return IntStream.rangeClosed(0, numOfNodes)
                    .boxed()
                    .toArray(Integer[]::new);
        }

        int getRoot(final int nodeNumber) {
            final int rootNode = nodes[nodeNumber];
            if (rootNode == nodeNumber) {
                for (final Integer index : indices) {
                    nodes[index] = rootNode;
                }
                indices.clear();
                return nodeNumber;
            }

            indices.add(nodeNumber);
            return getRoot(rootNode);
        }

        boolean isSame(final int nodeA, final int nodeB) {
            return getRoot(nodeA) == getRoot(nodeB);
        }

        void unit(final int nodeA, final int nodeB) {
            final int rootA = getRoot(nodeA);
            final int rootB = getRoot(nodeB);

            if (rootA == rootB) {
                return;
            }

            nodes[Math.max(rootA, rootB)] = Math.min(rootA, rootB);
        }
    }
}


Measured memory_bytes: 99400
N, K = map(int, input().split())
dic = {}
for i in range(N):
  a, b = map(int, input().split()) 
  if dic.get(a) is None:
    dic[a] = b
  else:
    dic[a] += b

ans = -1  
now = 0
for k, v in sorted(dic.items()):
  now += v
  if now >= K:
    ans = k
    break
print(ans)

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

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

    ll ans=0;
    rep(i,n){
        // same
        while(i+1<n && a[i]==a[i+1]) ++i;

        //up
        if(i+1<n && a[i]<a[i+1]){
            while(i+1<n && a[i]<=a[i+1]) ++i;
        }

        //down
        else if(i+1<n && a[i]>a[i+1]){
            while(i+1<n && a[i]>=a[i+1]) ++i;
        }
        
        ++ans;

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

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    vector<bool>b(49,0);
    rep(i,n)cin>>a[i];
    rep(i,49){
        int counter=0;
        ll s=((ll)1<<i);
        rep(j,n)if(s&a[j])counter++;
        if(counter>=n-counter)b[i]=1;
    }
    ll x=0;
    bool f=1;
    for(int i=49;i>=0;i--){
       if(f&&(k&((ll)1<<i))){
           if(b[i]){
               f=0;
            }
            if(b[i]==0) x+=((ll)1<<i);
        }
        else if(!f){
            if(!b[i])x+=((ll)1<<i);
        }
    }
    ll ans=0;
    rep(i,n)ans+=x^a[i];
    cout<<ans<<endl;
}

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


int main(){
  string S;
  ll ans=0;
  cin >> S;
  for (int tmp = 0; tmp < (1 <<(S.size()-1)); tmp++) {
    bitset<9> s(tmp);
    ll t=(S.at(S.size()-1)-'0'),x=1;
    rep(i,S.size()-1){
      if(s.test(i)){
        ans+=t;
        x=1;
        t=S.at(S.size()-2-i)-'0';
      }else{
        t+=(S.at(S.size()-2-i)-'0')*(ll)pow(10,x);
        x++;
      }
    }
    ans+=t;
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    double r;
    cin >> r;
    cout << 2 * r * M_PI << endl;

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    int count =0;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i+=2){
        if(a[i]%2==1){
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 3584
#B
n = int(input())
cnt = 0
merge = 0
for _ in range(n):
    v = int(input())
    if v==0:
        merge = 0
    else:
        q,r = divmod(v,2)
        cnt += q
        cnt += (merge * r)
        merge = (1-merge)*r + (1-r)*merge
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int d = (h2-h1)*60+m2-m1;
    cout << d-k << endl;
}

Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 2;
constexpr lint LINF = LLONG_MAX / 2;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
int n,cnt;
std::string s;
void func(int m){
	if(m==0){
		std::cout<<s<<std::endl;
		return;
	}
	rep(i,cnt+1){
		if(i==cnt){
			cnt++;
			s+='a'+i;
			func(m-1);
			s.pop_back();
			cnt--;
		}
		else{
			s+='a'+i;
			func(m-1);
			s.pop_back();
		}
	}
}
int main() {
	std::cin>>n;
	func(n);
	return 0;
}

Measured memory_bytes: 1536
(let* ((n (read))
       (lst (loop :repeat n :collect (cons (read) (read-line))))
       (res 0))
  (mapcar (lambda (k)
            (if (equal "JPY" (cdr k))
                (setq res (+ res (car k)))
                (setq res (+ res (* (car k) 380000))))) lst)
  (princ res))

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

int main(){
    int n, k;
    cin >> n >> k;
    int h[n], diff, min = 1000000009;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h, h + n); // shojun
    //sort(h, h + n, greater<int>()); // kojun
    for(int i = 0; i < n - (k - 1); i++){
        diff = h[i + k - 1] - h[i];
        if(diff < min){
            min = diff;
        }

        if(min == 0){
            break;
        }
    }
    cout << min;
    cout << endl;
    return 0;
}

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

ll n , a[501] , d[501] , k , mx , ans;
ll sum;
vector <ll> fuck;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) sum += a[i];
    for (ll i = 1; i * i <= sum; i++)
        if (sum % i == 0) fuck.push_back(i), fuck.push_back(sum / i);
    for (ll num: fuck){
        for (int i = 0; i < n; i++) d[i] = a[i] % num;
        sort(d , d + n);
        ans = 0;
        for (int i = 0 , r = n - 1; i < r; i++){
            while (i < r && num - d[r] < d[i])
                ans += num - d[r] , d[i] -= num - d[r] , d[r] = num , r--;
            if (i < r)
                ans += d[i] , d[r] += d[i] , d[i] = 0;
        }
        bool can = true;
        for (int i = 0; i < n; i++) can &= (d[i] == num) || !d[i];
        if (ans <= k && can) mx = max(mx , num);
    }
    cout << mx;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 3
#define TRUE 1
#define FALSE 0

int judge(void);
int dfs(int,int,int,int,int);

int answer[MAX][MAX] = {
  {1,2,3},
  {4,5,6},
  {7,8,0}
};

int f[MAX][MAX];
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

int main(){
  int x,y;
  int result;
  int i,j;

  for (i = 0;i < MAX;i++)
    for (j = 0;j < MAX;j++){
      scanf("%d",&f[i][j]);

      if (f[i][j] == 0){
	y = i;
	x = j;
      }	
    }

  for (i = 1;i < 10000;i++){
    result = dfs(x,y,-1,0,i);

    if (result >= 0)
      break;
  }

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

  return 0;
}

//判定用
int judge(void){
  int i,j;

  for (i = 0;i < MAX;i++)
    for (j = 0;j < MAX;j++)
      if (f[i][j] != answer[i][j])
	return FALSE;

  return TRUE;
}

int dfs(int x,int y,int v,int d,int l){
  int i,j;
  int result;
  int nx,ny;

  if (judge())
    return d;

//深さが基準値を超えていたら
  if (d > l)
    return -1;

//移動することを考える
  for (i = 0;i < 4;i++){
    nx = x + dx[i];
    ny = y + dy[i];

//範囲を超えないかチェック
    if (nx < 0 || nx > 2 || ny < 0 || ny > 2 || (i + 2) % 4 == v)
      continue;

//移動後の情報をｙ、ｘに移動
    f[y][x] = f[ny][nx];
    f[ny][nx] = 0;

//更に掘り下げる
    if ((result = dfs(nx,ny,i,d + 1,l)) > 0)
      return result;

    f[ny][nx] = f[y][x];
    f[y][x] = 0;
  }

  return -1;
}



Measured memory_bytes: 2148
n = int(input())
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))
ab |= {(-1, -1)}

ans = 0
for c, d in cd:
    tmp = max((b, a) for a, b in ab if (a < c and b < d))
    if tmp != (-1, -1):
        ab.remove(tmp[::-1])
        ans += 1
print(ans)


Measured memory_bytes: 65876
#include<iostream>
#define int long long
using namespace std;
const int N=2e5+2;
const int mod=1e9+7;
int dp[N],sum[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,max1,ans=0,m;
	string s;
	cin>>n>>m>>s;
	if(s[0]=='B'){
		for(i=0;i<m;i++){
			if(s[i]=='B'){
				s[i]='R';
			}
			else{
				s[i]='B';
			}
		}
//		cout<<s<<endl;
	}
	bool cac=true;
	for(i=1;i<m;i++){
		if(s[i]!=s[i-1]){
			cac=false;
			break;
		}
	}
	if(cac){
//		cout<<0<<endl;
		dp[0]=1;
		sum[0]=1;
		ans=1;
		for(i=1;i<=n;i++){
			if(i!=1){
				dp[i]=sum[i-2];
			}
			sum[i]=sum[i-1]+dp[i];
			if(sum[i]>=mod){
				sum[i]-=mod;
			}
		}
		for(i=1;i<=n-1;i++){
			ans+=(i+1)*dp[n-i-1];
			ans%=mod;
		}
		cout<<ans;
	}
	else{
		if(n&1){
			cout<<0;
			return 0;
		}
		max1=n-1;
		cac=true;
		j=1;
		for(i=1;i<m;i++){
			if(s[i]==s[i-1]){
				j++;
			}
			else{
				if(s[i]=='B'){
					if(cac){
						if(j&1){
							max1=min(max1,j);
						}
						else{
							max1=min(max1,j+1);
						}
						cac=false;
					}
					else{
						if(j&1){
							max1=min(max1,j);
						}
					}
				}
				j=1;
			}
		}
		dp[0]=1;
		sum[0]=1;
		for(i=1;i<=n;i++){
			sum[i]=sum[i-1];
			if(i&1){
				continue;
			}
			dp[i]=sum[i-2];
			if(i-max1-2>=0){
				dp[i]-=sum[i-max1-2];
				if(dp[i]<0){
					dp[i]+=mod;
				}
			}
			sum[i]+=dp[i];
			if(sum[i]>=mod){
				sum[i]-=mod;
			}
		}
		for(i=1;i<=max1;i+=2){	
			ans+=(i+1)*dp[n-i-1];
			ans%=mod;
		}
		cout<<ans;
	}
}

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

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

    //左側からスタートし、続いている区間の数をactiveで記録する
    int ans=0;
    int active=0;
    rep(i,n){
        //もしactiveが足りていたらactiveをh[i]に合わせる
        //新たに区間を始める必要はない
        if(active >= h[i]){
            active = h[i];
        }
        //activeが足りていなかったらそこから足りない分の区間を始める
        else{
            ans += h[i]-active;
            active=h[i];
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define maxn 2000010
#define ll long long

const int g = 2;
const ll mod = 75161927681ll;
const ll p = 200003;
ll ans,w1[maxn],w2[maxn],w3[maxn];
int a[maxn],n,vis[maxn],rev[maxn];

ll qpow(ll a,ll b){
	if (b==0)return 1;
	ll d=qpow(a,b>>1);d=d*d%p;
	if (b&1)d=d*a%p;
	return d;
}

ll qpow1(ll a,ll b){
	if (b==0)return 1;
	__int128 d=qpow1(a,b>>1);d=d*d%mod;
	if (b&1)d=d*a%mod;
	return d;
}

void NTT( ll *a, int lim, int flag ) {
	for (int i = 1; i < lim; ++ i) rev[i] = (rev[i>>1]>>1) | (i&1) * (lim>>1);
	for (int i = 0; i < lim; ++ i) if (i < rev[i]) std::swap(a[i], a[rev[i]]);
	for (int i = 1; i < lim; i <<= 1) {
		ll wn = qpow1(3,(mod-1)/(i<<1));
		if (flag == -1) wn = qpow1(wn, mod - 2);
		for (int j = 0; j < lim; j += (i<<1)) {
			ll w =1;
			for (int k = 0; k < i; w=(__int128)w*wn%mod,++k) {
				ll a1 = a[j+k];
				ll a2 = (__int128) w * a[j+k+i] % mod;
				a[j+k] = (a1 + a2) % mod; a[j+k+i] = (a1 - a2 + mod) % mod;
			}
		}
	} if (flag == -1) {
		ll inv=qpow1(lim,mod-2);
		for (int i = 0; i < lim; ++i) a[i] = (__int128) a[i] * inv % mod;
	}
}


int main() {
	scanf("%d",&n);
//	printf(">%lld\n",mod);
	for(int i=1,f=g;i<p;++i){vis[f] = i;f=(ll)f*g%p;}
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		if (!a[i]) continue;
		int d = vis[a[i]];
	//	printf("%d %d\n",d,qpow(g,d));
		w1[d]++; w2[d]++;
	} 
	
	int lim = 1;
	while (lim<=p+p+1) lim<<=1;
//	printf(">%d\n",lim);
	NTT(w1,lim,1); 
	for (int i = 0; i < lim; ++ i) w3[i] = (__int128) w1[i] * w1[i] % mod;
	NTT(w3,lim,-1); 
	for (int i=1;i<p;++i) w3[i+i] -= w2[i];
	for(int i=1;i<2*p;++i)  {
		ans += qpow(g,i) * w3[i] / 2;
	//	if (w3[i]) printf("%d %lld\n",i,w3[i]);
	}
	printf("%lld",ans);
	return 0;
}
	



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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=2e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n;
map<string,bool> var;
string s;
int ans;

int main()
{
    read(n);
    Rep(i,1,n){
        cin>>s;
        if(!var[s])ans++,var[s]=true;
    }
    printf("%d\n",ans);
    return 0;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int n,ans=0;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  rep(i,n-2){
    if(v[i]<v[i+1] && v[i+1]<v[i+2] || v[i+2]<v[i+1] && v[i+1]<v[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int n,m,i,j,d[10005],ans;
struct edge{
    int v,d,c;
    edge(int vv,int dd,int cc){
        v=vv,d=dd,c=cc;
    }
};
struct de{
    int u,d;
    de(int uu,int dd){
        u=uu,d=dd;
    }
	bool operator<(const de &a)const
	{
		return d < a.d;
	}
};

priority_queue<de> q;
vector <edge> e[20005];
int main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    int u,v,d1,c;
    while(~scanf("%d %d",&n,&m)&&n)
    {
        ans=0;
       /* ;
        if(n==0||m==0)
            return 0;*/
        while(!q.empty())
            q.pop();
        for(i=1;i<=n;i++)
        {
            e[i].clear();
            d[i]=2147483647;
        }
        for(i=1;i<=m;i++)
        {
            scanf("%d %d %d %d",&u,&v,&d1,&c);
            e[u].push_back(edge(v,d1,c));
            e[v].push_back(edge(u,d1,c));
        }
        d[1]=0;
        q.push(de(1,0));
        while(!q.empty())
        {
            de k=q.top();
            q.pop();
            if(d[k.u]<k.d)continue;
            for(i=0;i<int(e[k.u].size());i++)
            {
                if(d[e[k.u][i].v]>=e[k.u][i].d+d[k.u])
                {
                    d[e[k.u][i].v]=e[k.u][i].d+d[k.u];
                    q.push(de(e[k.u][i].v,d[e[k.u][i].v]));
                }
            }
        }
        ans=0;
        int mi=2147483647;
        for(i=2;i<=n;i++)
        {
            for(j=0;j<int(e[i].size());j++)
            {
                if(d[e[i][j].v]+e[i][j].d==d[i]&&mi>e[i][j].c)
                    mi=e[i][j].c;
            }
            if(mi!=2147483647)
            ans=ans+mi;
            mi=2147483647;
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 4748
from collections import Counter

N = int(input())
D = list(map(int,input().split()))

d = Counter(D)
Dmax = max(D)
ans = d[0]**d[1]
for i in range(1,Dmax):
	ans = (ans*d[i]**d[i+1])%998244353
if d[0] != 1 or D[0] != 0:
	ans = 0
print(ans)

Measured memory_bytes: 19936
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<pair<int, int>> p(n);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p.begin(), p.end());

    int ans = p.back().first + p.back().second;

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

Measured memory_bytes: 1024
zero=3
one=4
zero2ten=[i for i in range(3,14)]
flag=14
bin1=15
bin2=45
var=75
# variable 16~
ans=[]
def debug(i):
    global ans
    ans.append(("d",i,0,0))
def zeroclear(i):
    upper(i,zero,i)
def add(i,j,k):
    global ans
    ans.append(("+",i,j,k))
def upper(i,j,k):
    global ans
    ans.append(("<",i,j,k))
def and11(i,j,k):
    upper(i,j,k)
    upper(k,j,k)
def copy_if(src,dst):
    global var
    global flag
    one=var+1
    one2=var
    zeroclear(one)
    zeroclear(one2)
    zeroclear(dst)
    add(one,flag,one)
    for _ in range(10):
        upper(dst,src,one2)
        and11(one,one2,one)
        add(one,dst,dst)
    zeroclear(one)
    zeroclear(one2)
def int2bin(src,dstl):
    global var
    sum=var
    cur=var+1
    tmpsum=var+2
    src2=var+3
    var+=3
    zeroclear(sum)
    zeroclear(cur)
    zeroclear(tmpsum)
    zeroclear(src2)
    add(one,src,src2)
    for i in range(29,-1,-1):
        ii=i
        zeroclear(cur)
        add(one,cur,cur)
        for j in range(i):
            add(cur,cur,cur)
        add(sum,cur,tmpsum)
        upper(tmpsum,src2,cur)
        upper(tmpsum,src2,dstl+ii)
        for j in range(i):
            add(cur,cur,cur)
        add(sum,cur,sum)
    zeroclear(sum)
    zeroclear(cur)
    zeroclear(tmpsum)
    zeroclear(src2)
    var-=3
def binprod(src1l,src2l,dst):
    global var
    global flag
    cur=var
    tmp=var+1
    var+=2
    zeroclear(cur)
    zeroclear(var+1)
    zeroclear(dst)
    for i in range(30):
        for j in range(30):
            zeroclear(cur)
            and11(src1l+i,src2l+j,cur)
            for _ in range(i+j):
                add(cur,cur,cur)
            add(cur,dst,dst)
    var-=2

        
        


tmp=var
var=var+1
upper(zero,0,zero2ten[1])
for i in range(9):
    add(zero2ten[i+1],zero2ten[1],zero2ten[i+2])
int2bin(0,bin1)
int2bin(1,bin2)
binprod(bin1,bin2,2)
print(len(ans))
for i in ans:
    print(i[0],i[1],i[2],i[3])

Measured memory_bytes: 11884
#include<iostream>
#include<climits>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef pair<int ,int> ipair;
bool greaterPair(const ipair& l, const ipair& r){return l.second < r.second;}
typedef long long ll;
int main(){

	int n;
	cin >> n;
	
	vector< int > x(n);
	vector< int > x_sorted(n);
	for(int i = 0; i < n; i++)
	{
		cin >> x[i];
		x_sorted[i]  = x[i];

	}
	sort(x_sorted.begin(), x_sorted.end());

	int m1 = x_sorted[n/2-1];
	int m2 = x_sorted[n/2];
	for(int i = 0; i < n; i++)
	{
		if(x[i] >= m2){
			cout << m1 << endl;
		}else{
			cout << m2 << endl;
		}
	}
		
	return 0;
}

Measured memory_bytes: 3712
//https://vjudge.net/contest/286896

#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>

/*int a[20000];
// int main()
// {
//     int g[10];
//     memset(g,0,sizeof(g));
//     int temp, digit, n, i, j = 0;
//     std::cin >> n;
//     a[0] = 1;
//     digit = 1;
//     for (i = 2; i <= n; i++)
//     {
//         int num = 0;
//         for (j = 0; j < digit; j++)
//         {
//             temp = a[j] * i + num;
//             a[j] = temp % 10;
//             num =temp/ 10;
//         }
//         while (num)
//         {
//             a[digit] = num % 10;
//             num /= 10;
//             digit++;
//         }
//     }
//     for (i = digit - 1; i >= 0; i--)
//         std::cout << a[i];
//     return 0;
// }这段代码是大数阶乘
*/
long long mod=1000000007;
int prime[1005];//1000以内的素数
int cnt=0;//素数个数
bool vi[1005];
int main(){
    int n;
    std::cin>>n;
    long long ans=1;
    for(int i=2;i<=n;i++){
        if(!vi[i]){
            prime[cnt++]=i;
        }
        for(int j=0;j<cnt;j++){
            if(i*prime[j]>n) break;
            vi[i*prime[j]]=1;
            if(i%prime[j]==0) break;
        }
    }//线性素数筛
    long long num[1005]={0};
    for(int i=2;i<=n;i++){
        int nu=i;
        for(int j=0;j<cnt;j++){
            if(nu==1)
                break;
            else
            {
                while(nu%prime[j]==0){
                    nu/=prime[j];
                    num[prime[j]]++;
                }
            }
        }
    }
    for(int i=0;i<cnt;i++){
        ans*=num[prime[i]]+1;
        ans%=mod;
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
n, m, k, p = map(int, input().split())
p -= 1
edges = [[] for _ in range(n)]
for _ in range(m):
  x, y, w = map(int, input().split())
  x -= 1
  y -= 1
  edges[x].append((y, w))
  edges[y].append((x, w))

point = []
for _ in range(k):
  s, t = map(int, input().split())
  s -= 1
  t -= 1
  point.append(s)
  point.append(t)

INF = 10 ** 20
def dist(x):
  mem = [INF] * n
  mem[x] = 0
  que = []
  heappush(que, (0, x))
  while que:
    total, node = heappop(que)
    for to, cost in edges[node]:
      new_total = total + cost
      if new_total < mem[to]:
        mem[to] = new_total
        heappush(que, (new_total, to))
  return mem

dist_dic = [[None] * (2 * k) for _ in range(2 * k)]
for i in range(2 * k):
  mem = dist(point[i])
  for j in range(2 * k):
    dist_dic[i][j] = mem[point[j]]

start_mem = dist(p)
start_cost = []
for i in range(2 * k):
  start_cost.append(start_mem[point[i]])


dic = {}
end = 2 ** (2 * k) - 1
def min_cost(stat, pos):
  if (stat, pos) in dic:
    return dic[(stat, pos)]
  if stat == end:
    dic[(stat, pos)] = 0
    return 0

  ret = INF
  mask = 1
  for i in range(2 * k):
    if stat & mask or (i % 2 == 1 and not (stat & (mask >> 1))):
      mask <<= 1
      continue
    ret = min(ret, dist_dic[pos][i] + min_cost(stat | mask, i))
    mask <<= 1
  dic[(stat, pos)] = ret
  return ret

ans = INF
for i in range(0, k * 2, 2):
  ans = min(ans, start_cost[i] + min_cost(2 ** i, i))
if ans == INF:
  print("Cannot deliver")
else:
  print(ans)


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

int main(void) {
	int X, A, B;
	scanf("%d %d %d", &X, &A, &B);
	if (B <= A) printf("delicious\n");
	else if (B <= A + X) printf("safe\n");
	else printf("dangerous\n");

	return 0;
}


Measured memory_bytes: 3724
fun main(arg: Array<String>) {
    val S = next()
    val N = S.length - 1
    var ans = 0L
    for (b in 0 until 1.shl(N)) {
        val P = BooleanArray(N + 1)
        for (n in 0 until N) {
            if (b.shr(n).and(1) == 1) P[n] = true
        }
        val Ex = StringBuilder()
        for (n in 0 until N + 1) {
            Ex.append(S[n])
            if (P[n]) Ex.append('+')
        }
        ans += fun (S: String): Long {
            var nums = 0L
            var num = 0L
            for (c in S) {
                if (c in '0'..'9') num = num * 10 + (c - '0')
                else {
                    nums += num
                    num = 0L
                }
            }
            if (num > 0) nums += num
            return nums
        }(Ex.toString())
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }




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

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

using ll = long long;
#define INF 1e9

ll gcd(ll a, ll b){
  if(a < b){
    ll box = a;
    a=b;
    b = box;
  }
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}

int main(){
  int N;
  cin >> N;
  vector<ll> T(N);
  REP(i, N){
    cin >> T[i];
  }

  ll ans = T[0];

  REP(i, N-1){
    ll g = gcd(T[i+1], ans);
    ans = T[i+1]/ g * ans;
  }
  cout << ans << endl;

  return 0;
}


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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int, P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};

void chmax(int &a, int b){
    a = max(a, b);
}

bool solve(){
    int H, N;
    cin >> H >> N;
    vector<vector<bool> > ng(H,vector<bool>(4,false));
    for(int i=0;i<N;i++){
        int x, y;
        cin >> x >> y;
        ng[y][x] = true;
    }
    vector<vector<int> > dp(H*4,vector<int>(1<<4));
    int ans = 0;
    for(int i=0;i<(H-1)*4;i++){
        int y = i/4, x = i%4;
        for(int S=0;S<1<<4;S++){
            chmax(dp[i+1][S>>1], dp[i][S]);
            if(x==3) continue;
            if(ng[y][x] || ng[y][x+1] || ng[y+1][x] || ng[y+1][x+1]) continue;
            if((S&3)!=0) continue;
            chmax(dp[i+2][(S>>2)|(3<<2)],dp[i][S]+1);
        }
    }
    for(int i=0;i<H*4;i++){
        for(int S=0;S<1<<4;S++){
            chmax(ans, dp[i][S]);
        }
    }
    cout << ans << endl;
    return false;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 7628
#include<iostream>
using namespace std;
int main(void){
	int r;
	cin>>r;
	if(r<1200){
		cout<<"ABC"<<endl;
	}
	else if(r<2800){
		cout<<"ARC"<<endl;
	}
	else {
		cout<<"AGC"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0;i<n;i++) {
            for (int j = 0;j<d;j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;
        for (int i = 0;i<n;i++) {
            for (int j = i+1;j<n;j++) {
                int dis = 0;
                for (int k = 0;k<d;k++) {
                    dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean flag = false;
                //System.out.println(dis);
                for (int l = 1;l <= dis;l++) {
                    if (l * l == dis) {
                        flag = true;
                        break;
                    } 
                }
                if (flag) ans++;
            }
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var S string

func main() {
	sc.Split(bufio.ScanWords)

	S = nextStr()
	ans := 0
	num := 0
	for i := 0; i < len(S); i++ {
		if string(S[i]) == "W" {
			ans += num
		} else {
			num++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 2504