akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/



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



int main(){
    ll x;cin>>x;ll ans=(x/11)*2;
    if(x%11>=1&&x%11<=6)ans++;
    else if(x%11>=7)ans+=2;
    cout<<ans<<endl;
    return 0;
}


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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	ll a, b, c;
	cin >> a >> b >> c;
	if(a == 0) cout << b/c + 1 << endl;
	else cout << b/c - (a-1)/c << endl;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

divlist = make_divisors(N)
count = 0
for i in divlist[1:]:
    n = N
    while n % i == 0:
        n = n // i
    if n % i == 1:
        count += 1

print(count + len(make_divisors(N-1))-1)

Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int A[] = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            Stack<Integer> idx = new Stack<>();
            int left[] = new int[N];
            for (int i = 0; i < N; i++) {
                while (!idx.isEmpty() && A[idx.peek()] > A[i]) {
                    idx.pop();
                }

                int last = idx.isEmpty() ? -1 : idx.peek();
                left[i] = i - last;
                idx.push(i);
            }

            int right[] = new int[N];
            idx.clear();

            for (int i = N - 1; i >= 0; i--) {
                while (!idx.isEmpty() && A[idx.peek()] > A[i]) {
                    idx.pop();
                }

                int last = idx.isEmpty() ? N : idx.peek();
                right[i] = last - i;
                idx.push(i);
            }

            long ans = 0L;
            for (int i = 0; i < N; i++) {
                ans += (long) left[i] * right[i] * A[i];
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


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

int main(){
	int a,b,c;
	int tyo = 0,hishi = 0;
	while(scanf("%d,%d,%d\n",&a,&b,&c) != EOF){
		if(a*a+b*b == c*c)
			tyo++;
		if(a == b)
		 	hishi++;
	}
	cout<<tyo<<endl;
	cout<<hishi<<endl;

	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
auto &errStream = cerr;
#ifdef LOCAL
#define cerr (cerr << "-- line " << __LINE__ << " -- ")
#else
class CerrDummy {
} cerrDummy;
template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) {
  return cd;
}
using charTDummy = char;
using traitsDummy = char_traits<charTDummy>;
CerrDummy &operator<<(CerrDummy &cd,
                      basic_ostream<charTDummy, traitsDummy> &(
                          basic_ostream<charTDummy, traitsDummy> &)) {
  return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr << "reached" << endl
#define DMP(x) cerr << #x << ":" << x << endl
#define ZERO(x) memset(x, 0, sizeof(x))
#define ONE(x) memset(x, -1, sizeof(x))

using pi = pair<int, int>;
using vi = vector<int>;
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;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T> T Sq(const T &t) { return t * t; }

#define CAPITAL
void Yes(bool ex = true) {
#ifdef CAPITAL
  cout << "YES" << endl;
#else
  cout << "Yes" << endl;
#endif
  if (ex)
    exit(0);
}
void No(bool ex = true) {
#ifdef CAPITAL
  cout << "NO" << endl;
#else
  cout << "No" << endl;
#endif
  if (ex)
    exit(0);
}

const ll infLL = LLONG_MAX / 3;

#ifdef int
const int inf = infLL;
#else
const int inf = INT_MAX / 2 - 100;
#endif

signed main() {
  int N = read();
  string A = readString(), B = readString(), C = readString();

  int ans = 0;
  REP(i, N) {
    if (!(A[i] == B[i] && B[i] == C[i])) {
      if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i]) {
        ans++;
      } else {
        ans += 2;
      }
    }
  }

  print(ans);

  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

struct UnionFind {
	vector<int> d; // d[i]:iの親の番号　(例) d[3] = 2 : 3の親が2 d[3] = -3 : 3は根で、その連結成分のサイズは3

	UnionFind(int N) : d(N, -1) {} // 負なら根である 非負なら子である

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (d[x] < 0) return x; //負なら根であるから根を返す
		return d[x] = root(d[x]);
	}

	bool unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return false; //xとyの根が同じ(=同じ木にある)時はそのまま
		if (d[rx] > d[ry])swap(rx, ry); //木のサイズが大きいほうにくっつける
		d[rx] += d[ry]; //サイズが上乗せされる
		d[ry] = rx; //yの根はxになる
		return true;
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
	int size(int x) {
		return -d[root(x)];
	}
};

signed main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>>v(M);
	rep(i, N) {
		int K;
		cin >> K;
		rep(j, K) {
			int L;
			cin >> L;
			L--;
			v[L].push_back(i);
		}
	}
	UnionFind tree(N);
	rep(i, M) {
		if (v[i].size() <= 1)continue;
		rep(j, v[i].size() - 1) {
			tree.unite(v[i][0], v[i][j + 1]);
		}
	}
	if (tree.size(0) == N)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 4736
N = int(input())
statement = {}
ans = 0
for i in range(N):
  l = []
  n = int(input())
  for j in range(n):
    l.append(list(map(int, input().split())))
  statement[i+1] = l
#print(statement)
def det(stat, hypo):
  D = True
  for i in range(1, N+1):
    if hypo[i] == "1":
#      print("{} is Honest".format(i))
      for j in range(len(stat[i])):
        if int(hypo[stat[i][j][0]]) != stat[i][j][1]:
#          print("{} says {} is not {}".format(i, stat[i][j][0], hypo[stat[i][j][0]]))
          D = False
#          print("The hypothesis {} is False".format(hypo))
          break
    if D == False:
      break
  return D
for i in range(2**N):
  Hypo = format(2**N - i - 1, "017b")[-(N+1):]
#  print(Hypo)
  if Hypo.count("1") > ans:
    if det(statement, Hypo):
      ans = Hypo.count("1")
print(ans)
    

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin>>n;
    int a[1000000];
    for(int i=0;i<n;i++)cin>>a[i+1];
    a[0]=0;
    a[n+1]=0;
    int cost=0;
    for(int i=1;i<n+2;i++){
        cost+=abs(a[i]-a[i-1]);
    }
    for(int i=1;i<n+1;i++){
        int d = abs(a[i-1]-a[i+1])-abs(a[i]-a[i-1])-abs(a[i]-a[i+1]);
        cout<<cost+d<<endl;
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
        long long int t=0;
        string c;
        string s;
       long long int n,m,o=0,l,d=1,i,j,p=0,f;
       double pie=3.141592653589793238;
    long long int MOD=1000000007;
    double k;
    cin>>n>>k;
    k=k*10;
    for(i=0;i<9;i++)
    {
        if(floor(k*(.08))==n)
        {
            cout<<k;
            break;}
            k++;
    }
    if(i==9)
    cout<<"-1";
 return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))

L=0
C=[0]*N

for i in range(N):
    C[A[i]-1]+=1

for i in range(N):
    L+=int(C[i]*(C[i]-1)/2)
    
for i in A:
    print(L-C[i-1]+1)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    int N,B[1000],A[1111]={};
    ll sum = 0;
    cin >> N ;
    rep(i,N-1) cin >> B[i];
    rep(i,N-2){
        if(B[i]<=B[i+1]){
            sum+=B[i];
        }else{
            sum+=B[i+1];
        }
    }
    sum+=B[0]+B[N-2];
    cout << sum << endl;
    
    return 0;
    

}

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


char grid[1001][1001];

int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cin>>grid[i][j];

    int step[h+1][w+1];

    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            step[i][j] = 0;
    for(int i=1;i<=w;i++)
    {
        if(grid[1][i] == '.')
            step[1][i] = 1;
        else
            break;
    }

    for(int i=1;i<=h;i++)
    {
        if(grid[i][1] == '.')
            step[i][1] = 1;
        else
            break;
    }

    for(int i=2;i<=h;i++)
        for(int j=2;j<=w;j++)
    {
        if(grid[i][j] == '#')
            step[i][j] = 0;
        else
        {
            step[i][j] = ((long long)step[i-1][j]+step[i][j-1])%mod;
        }
    }
    cout<<step[h][w];
    return 0;
}


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int const MAX = 1e5 + 41;
string const F = "Alice";
string const S = "Bob";

int n;
ll l;
string s[MAX];

ll getgr(ll x) {
	ll res = 1;
	while (x % 2 == 0) {
		res *= 2;
		x /= 2;
	}
	return res;
}

vector<ll> st;

struct Trie {
	Trie *one, *zero;
	int h;
	Trie () {
		one = zero = 0;
	};
	int getq() {
		int res = 0;
		if (one) res++;
		if (zero) res++;
		return res;
	}
	void push(int p, string &s) {
		if (p == sz(s)) return;
		if (s[p] == '1') {
			if (!one) one = new Trie();
			one->push(p + 1, s);
		}	else {
			if (!zero) zero = new Trie();
			zero->push(p + 1, s);
		}
		h = p;
	}
	void dfs() {
		if (getq() == 1) {
			st.pb(l - h);
		}
		if (one) one->dfs();
		if (zero) zero->dfs();
	}
};

Trie root;

void solve() {	
	fi(1, n) {
		root.push(0, s[i]);		
	}
	root.dfs();
	ll xr = 0;
	for (ll x : st) {
		xr ^= getgr(x);
	}
	if (xr) { 
		printf("%s\n", F.c_str());
	} else { 
		printf("%s\n", S.c_str());
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	cin >> n >> l;
	fi(1, n) {
		cin >> s[i];				
	}  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 8696
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main(){
	priority_queue<int> S;
	string tem1;
	int tem2;
	while(cin>>tem1){
		if(tem1=="insert"){
			cin>>tem2;
			S.push(tem2);
		}
		else if(tem1 == "extract"){
			cout<<S.top();
			S.pop();
			cout<<endl;
		}
		else{
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 7128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;
string S;

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

    if (N % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < N / 2; i++) {
        if (S[i] != S[i + N / 2]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    if(A < K) {
        K -= A;
        A = 0;
        if (B < K) {
            B = 0;
        } else {
            B -= K;
        }
    } else {
        A -= K;
    }
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
AB=[0]*N
for i in range(N):
    A,B=map(int,input().split())
    AB[i]=[A,B]
    
AB.sort(key=lambda x:x[1])
nunc=0

for i in range(N):
    nunc+=AB[i][0]
    if nunc>AB[i][1]:
        print('No')
        break
else:
    print('Yes')

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, K;
ll A[200100];
vector<ll> B;

// I want to delete this stupid solution ;(
#define sandwich(x) [](auto a, auto b){return (x)(a, b);}

template <typename T>
using F2 = std::function<T(T,T)>;

template <typename T, int N, typename F = std::plus<T>>
    struct SegmentTree{
        SegmentTree(T u, F f = F()){
            size = 1;
            while(size < N){
                size <<= 1;
            }

            unit = u;
            func = f;

            init();
        }
        void init(){
            for(int i=0;i<size;++i){
                data[i+size] = unit;
            }

            for(int i=size-1;i>0;--i){
                data[i] = func(data[i*2], data[i*2+1]);
            }
        }
        void update(int k, T v){
            k += size;
            data[k] = v;

            while(k > 1){
                k >>= 1;
                data[k] = func(data[k*2], data[k*2+1]);
            }
        }
        inline T query(int l, int r){
            return _query(l, r, 1, 0, size);
        }
        T _query(int a, int b, int k, int l, int r){
            if(b <= l || r <= a){return unit;}
            if(a <= l && r <= b){return data[k];}
            int mid = (l + r) >> 1;
            return func(_query(a, b,   2*k,   l, mid),
                        _query(a, b, 2*k+1, mid, r  ));
        }

        T unit, data[N*4];
        int size;
        F func;
    };

SegmentTree<ll, 200100> segtree(0);

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

    std::cin >> N >> K;

    for(int i=1;i<=N;++i){
        std::cin >> A[i];
    }

    for(int i=0;i<N;++i){
        A[i+1] += A[i] - K;
    }

    B.resize(N+1);
    for(int i=0;i<=N;++i){
        B[i] = A[i];
    }
    
    sort(B.begin(), B.end());
    B.erase(unique(B.begin(), B.end()), B.end());
    
    for(int i=0;i<=N;++i){
        A[i] = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
    }

    ll res = 0ll;
    for(int i=0;i<=N;++i){
        res += segtree.query(0, A[i] + 1);
        segtree.update(A[i], segtree.query(A[i], A[i]+1) + 1);
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 9472
/* SmartCoder Apr 7, 2019 */
#include <bits/stdc++.h>
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end();i++)
#define present(c,x)  ( (c).find(x) !=(c).end())
#define cpresent(c,x) (find(all(c),x)!= (c).end() )
#define minei(x)  min_element(x.begin(),x.end())-(x).begin()
#define maxei(x)  max_element(x.begin(),x.end())-(x).begin()

#define uns(v)     sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define acusum(x)  accumulate(x.begin(),x.end(),0)
#define acumul(x)  accumulate(x.begin(),x.end(),1, multiplies<int>());
#define bits(x)     __builtin_popcount( x )
#define oo INT_MAX
#define inf 1000000000

const double pi = acos(-1.0);
const double eps = 1e-11;
#define MAXN 1007
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
void fastIO() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll dp[MAXN][MAXN];
char mat[MAXN][MAXN];
int main() {
	fastIO();
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++)
			cin >> mat[i][j];
	}
	dp[1][1] = 1;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (i == 1 && j == 1)
				continue;
			dp[i][j] = mat[i][j] == '.' ? (dp[i - 1][j] + dp[i][j - 1]) % MOD : 0;
		}
	}
	cout << dp[h][w] << endl;

	return 0;
}


Measured memory_bytes: 9088
while line = gets
  def erato(n)
    numbers = (0..n).to_a
    numbers[0], numbers[1] = nil
    m = []
    for d in numbers
      next unless(d)
      break if (Math::sqrt(n) < d)
      (2*d..n).step(d){|e| numbers[e] = nil}
      (2*d..n).step(d){|e| m << e}
    end
    numbers.delete(nil)
    s = numbers.size
    return s
  end
  p erato(line.to_i)
end

Measured memory_bytes: 111708
import java.util.*;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), X = sc.nextInt(), Y = sc.nextInt(),
				sum = 2 * C * (Math.max(X, Y));
		if (X < Y) {
			sum = Math.min(2 * C * X + B * (Y - X), 2 * C * Y);
		} else {
			sum = Math.min(2 * C * Y + A * (X - Y), 2 * C * X);
		}
		System.out.println(A * X + B * Y > sum ? sum : A * X + B * Y);
	}
}

Measured memory_bytes: 35708
#include <iostream>

using namespace std;

char g[1010][1010];
int dp[1010][1010];

const int mod = 1e9 + 7;

int main()
{
    int h, w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> g[i][j];
        }
    }
    dp[1][1] = 1;
    for(int i = 2; i <= h; i++){
        if(g[i][1] != '#')
            dp[i][1] = dp[i - 1][1];
        else
            dp[i][1] = 0;
    }
    for(int i = 2; i <= w; i++){
        if(g[1][i] != '#')
            dp[1][i] = dp[1][i - 1];
        else
            dp[1][i] = 0;
    }
    for(int i = 2; i <= h; i++){
        for(int j = 2; j <= w; j++){
            if (g[i][j] != '#'){
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[h][w];
    return 0;
}


Measured memory_bytes: 5248
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    t = input()

    sl = len(s)
    tl = len(t)

    if t in s:
        for i in range(sl):
            if s[i]=='?':
                print('a', end='')
            else:
                print(s[i], end='')
        print()
        return

    for i in range(sl-1, -1, -1):
        if i+tl-1>=sl:
            continue
        ok = 1
        for j in range(tl):
            if s[i+j] not in ['?', t[j]]:
                ok = 0
                break
        if ok:
            s = s[:i] + t + s[i+tl:]
            for i in range(sl):
                if s[i]=='?':
                    print('a', end='')
                else:
                    print(s[i], end='')
            
            print()
            return

    print('UNRESTORABLE')
            

solve()


Measured memory_bytes: 3064
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
total = [a[0]] * n
cnt = defaultdict(int)
cnt[a[0]] += 1
for i in range(1, n):
    total[i] = total[i - 1] + a[i]
    cnt[total[i]] += 1

ans = 0
for k, v in cnt.items():
    if k == 0:
        ans += v
    ans += v * (v - 1) // 2
#print(total)
print(ans)


Measured memory_bytes: 43188
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		long a[]=new long[n];
		long c[]=new long[n*(n+1)/2];
		int m=40;
		int count=0;
		for(int i=0;i<n;++i) {
			a[i]=sc.nextLong();
		}
		for(int i=0;i<n;++i) {
			c[count]=a[i];
			++count;
			for(int j=i+1;j<n;++j) {
				c[count]=c[count-1]+a[j];
				++count;
			}
		}
		long x=0L;
		for(int j=40;j>=0;--j) {
			count =0;
			for(int i=0;i<c.length;++i) {
				if((c[i] & (long)(x+Math.pow(2, j))) == x+Math.pow(2, j))++count;
				if (count==k)break;
			}
			if(count==k)x=x+(long)Math.pow(2, j);
		}
		
		System.out.println(x);


	}
}


Measured memory_bytes: 29140
#include <bits/stdc++.h>
#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++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
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;
}
long long dp[200000];
  
int main()
{
  string S;
  cin >> S;
  int N = S.size();
  map<int,int> mp;
  mp[S.at(N-1)-'0']++;
  int cnt = 1;
  int pre = S.at(N-1)-'0';
  FOR(i,1,N){
    mp[(((cnt*10)%2019)*(S.at(N-1-i)-'0')+pre)%2019]++;
    pre=(((cnt*10)%2019)*(S.at(N-1-i)-'0')+pre)%2019;
    cnt=(cnt*10)%2019;
  }

  mp[0]++;
  ll ans = 0;
  for(auto x:mp){
    ans+=x.second*(x.second-1)/2;
  }

  cout << ans << endl;
}

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

int main() {
  int n, k;
  cin>>n>>k;
  int p[n];
  for (int i=0; i<n; i++) cin>>p[i];

  int i = 0;
  int ans = 0;
  set<int> nums;
  for (int i=0; i<k-1; i++) {
    nums.insert(p[i]);
  }
  while (i + k - 1 < n) {
    ++ans;
    nums.insert(p[i+k-1]);
    nums.erase(p[i]);
    while (i + k < n) {
      int min_nums = *nums.begin();
      auto it = nums.end();
      int max_nums = *(--it);
      if (!(p[i] < min_nums && max_nums < p[i+k])) {
        break;
      }
      ++i;
      if (i + k - 1 == n) {
        break;
      }
      nums.insert(p[i+k-1]);
      nums.erase(p[i]);
    }
    ++i;
  }
  int cnt_inc_seq = 0;
  i = 1;
  while (i < n) {
    int len = 0;
    while (i < n && p[i-1] < p[i]) {
      ++len;
      ++i;
    }
    if (len >= k - 1) {
      ++cnt_inc_seq;
    }
    ++i;
  }
  if (cnt_inc_seq > 1) {
    ans -= cnt_inc_seq - 1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
int n,q,a[100010],l,r;
char s[100010];
int main()
{
    cin>>n>>q;
    for(int i=1;i<=n;i++)
        cin>>s[i];
    for(int i=2;i<=n;i++)
    {
        a[i]=a[i-1];
        if(s[i]=='C'&&s[i-1]=='A')
            a[i]++;
    }
    for(int i=1;i<=q;i++)
    {
        cin>>l>>r;
        cout<<a[r]-a[l]<<'\n';
    }
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  string s;
  in(s);
  bool f=true;
  long n=s.size();
  rep(i,n){
    if(i%2==0&&(s[i]!='R'&&s[i]!='U'&&s[i]!='D'))f=false;
    if(i%2&&(s[i]!='L'&&s[i]!='U'&&s[i]!='D'))f=false;
  }
  out(f?"Yes":"No");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;

int dp[1100][1100];

void solve()
{
	string s1,s2;
	cin>>s1>>s2;
	memset(dp,0,sizeof(dp));
	for(int i=0;i<s1.length();i++)
		for(int j=0;j<s2.length();j++)
			dp[i+1][j+1]=(s1[i]==s2[j]?dp[i][j]+1:max(dp[i+1][j],dp[i][j+1]));
	printf("%d\n",dp[s1.length()][s2.length()]);
}

int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
		solve();
	return 0;
}

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

int main(void) {
	int n; cin >> n;
	int p[n];
	int i, sum = 0;
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}

	sort(p, p + n);

	p[n - 1] /= 2;

	for (i = 0; i < n; i++) {
		sum += p[i];
	}

	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>


using namespace std;
using ll = long long int; 

int main(void){

    string x;
    cin>>x;

    if(x[0]==x[1] && x[1]==x[2]){
        cout<<"No"<<endl;
        return 0;
    }

    cout<<"Yes" <<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(str(input())[-1])
ans = ""
if N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
    ans = "hon"
elif N == 0 or N == 1 or N == 6 or N == 8:
    ans = "pon"
elif N == 3:
    ans = "bon"

print(ans)


Measured memory_bytes: 9168
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int cnt[51] = {0};
	int a, b;
	for( int i=0; i<m; i++ ) {
		cin >> a >> b;
		cnt[a]++;
		cnt[b]++;
	}
	for( int i=1; i<=n; i++ ) {
		cout << cnt[i] << endl;
	}
	
	return 0;
}

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

using namespace std;

bool satisfy(int num,vector<int> &d)
{
    while(num)
    {
	int x = num % 10;
	num /= 10;
	for(int i = 0;i < d.size();i++)
	{
	    if(x == d[i])
		return false;
	}
    }

    return true;
}

int main(void)
{
    int n,k;
    vector<int> d;

    cin>>n>>k;

    for(int i = 0;i < k;i++)
    {
	int temp;
	cin>>temp;

	d.push_back(temp);
    }

    int minimum = n;
    for(;!satisfy(minimum,d);minimum++)
	;

    cout<<minimum<<endl;

    return 0;
}


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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  
  int n = min(a, b);
  
  vector<int> check(n);
  
  for (int i = 0; i < check.size(); i++) {
    if (a % (i+1) == 0 && b % (i+1) == 0) {
      check.at(i) = 1;
    }
    else {
      check.at(i) = 0;
    }
  }
  
  int count = 0;
  int ans = 1;
  
  for (int i = n-1; i >= 0; i--) {
    if (check.at(i) == 1) {
      count++;
    }
    if (count == k) {
      ans = i+1;
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;









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

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


	int ans=1;
	if (n % 2 == 0) {
		rep(i, 0, n) {
			if (2 * (i / 2 + 1) - 1 != v[i]) {
				cout << "0" << endl;
				exit(0);
			}
		}
		
		rep(i, 0, n / 2) {
			ans = (ans * 2) % MOD;
		}
		cout << ans << endl;
	}
	else {
		rep(i, 0, n) {
			if (i == 0){
				if (v[i] != 0) {
					cout << "0" << endl;
					exit(0);
				}
			}else if(2 * ((i-1) / 2 + 1) != v[i]){
				cout << "0" << endl;
				exit(0);
			}
		}

		rep(i, 0, (n - 1) / 2) {
			ans = (ans * 2) % MOD;
		}
		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e15
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector<int> vi;



int main() {
    fast;

    string s; cin >> s;
    cout << s.substr(0, 3) << "\n";
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define int long long
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)


int32_t main()
{
	fastio;
	int n;
	cin >> n;
	vector <int> v(n);
	for(int i=0;i<n;i++)
		cin >> v[i];
	int cnt[n+10][67];
	memset(cnt, 0, sizeof cnt);
	int N = 63;
	int ans = 0;
	for(int i=n-1;i>=0;i--){
		// pr(i);
		for(int j=0;j<N;j++){
			// pr(j);
			cnt[i][j] += cnt[i+1][j];
			if((1LL<<j)&v[i])
				ans = (ans + ((1LL<<j)%M)*(n-1-i-cnt[i][j])%M)%M;
			else
				ans = (ans + ((1LL<<j)%M)*(cnt[i][j])%M)%M;
		}

		for(int j=0;j<N;j++)
			if(v[i]&(1LL<<j))
				cnt[i][j]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 159616
#include<stdio.h>
int main()
{
    long long n,i,j,k,temp,ar[1000],c=0;
    while(scanf("%lld",&n)!=EOF)
    {

        for(i=1; i<=n; i++)
        {
            scanf("%lld",&ar[i]);
        }

        for(j=1; j<=n; j++)
        {
            if(j!=ar[j])c++;

        }
       if(c==0 || c==2)
        printf("YES\n");
       else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        System.out.println(S.substring(0, N/2).equals(S.substring(N/2, N)) ? "Yes":"No");
    }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  char a, b;
  cin >> a >> b;

  if (a == b) cout << 'H' << "\n";
  else cout << 'D' << "\n";

  return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, input().split())
    mod = 10 ** 9 + 7

    table = [1]
    tmp = 1
    for i in range(1, N + M + 1):
        tmp *= i
        tmp %= mod
        table.append(tmp)

    if abs(N - M) > 1:
        print(0)
    elif abs(N - M) == 1:
        print(table[N] * table[M] % mod)
    else:
        print(2 * table[N] * table[M] % mod)



if __name__ == '__main__':
    main()


Measured memory_bytes: 11052
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

int main(int argc, char* argv[]) {
  using std::vector;
  using std::cin;
  using std::cout;
  using std::endl;
  using std::max;
  using std::min;
  using std::lower_bound;
  using std::upper_bound;
  
  int a, b, q;
  vector<long> s, t, xs;
  cin >> a >> b >> q;
  for (int i = 0; i < a; ++i) {
    long ss;
    cin >> ss;
    s.push_back(ss);
  }
  for (int i = 0; i < b; ++i) {
    long tt;
    cin >> tt;
    t.push_back(tt);
  }
  for (int i = 0; i < q; ++i) {
    long x;
    cin >> x;
    xs.push_back(x);
  }

  for (int i = 0; i < q; ++i) {
    long se_dist = -1;
    long te_dist = -1;
    long sw_dist = -1;
    long tw_dist = -1;
    
    auto se = lower_bound(s.begin(), s.end(), xs[i]);
    if (se != s.end()) {
      se_dist = *se - xs[i];
    }
    auto te = lower_bound(t.begin(), t.end(), xs[i]);
    if (te != t.end()) {
      te_dist = *te - xs[i];
    }
    auto sw = upper_bound(s.begin(), s.end(), xs[i]);
    if (sw != s.begin()) {
      sw_dist = xs[i] - *(sw - 1);
    }
    auto tw = upper_bound(t.begin(), t.end(), xs[i]);
    if (tw != t.begin()) {
      tw_dist = xs[i] - *(tw - 1);
    }

    long min_dist = LONG_MAX;

    if (se_dist != -1 && te_dist != -1) {
      min_dist = min(min_dist, max(se_dist, te_dist));
    }
    if (sw_dist != -1 && tw_dist != -1) {
      min_dist = min(min_dist, max(sw_dist, tw_dist));
    }

    if (se_dist != -1 && tw_dist != -1) {
      if (se_dist < tw_dist) {
	min_dist = min(min_dist, se_dist * 2 + tw_dist);
      } else {
	min_dist = min(min_dist, se_dist + tw_dist * 2);
      }
    }
    if (sw_dist != -1 && te_dist != -1) {
      if (sw_dist < te_dist) {
	min_dist = min(min_dist, sw_dist * 2 + te_dist);
      } else {
	min_dist = min(min_dist, sw_dist + te_dist * 2);
      }
    }

    cout << min_dist << endl;
  }
  
  return 0;
}


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

using namespace std;

int n = 0, m = 0, c = 0;

int main(){
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0; i < m; ++i){
        cin >> b[i];
    }
    int ans = 0, x = 0;
    for(int i = 0; i < n; ++i){
        int res = 0;
        for(int j = 0; j < m; ++j){
            cin >> x;
            res+=x*b[j];
        }
        res+=c;
        if(res > 0){
            ++ans;
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vpll adj[MAXN];ll visit[MAXN]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
unsigned long long n,x,y,m;
string s,t;
vll a;
// <------------- Implement Functions Here ----------> //

long long exponentiation(long long base, 
                        long long exp) 
{ 
    if (exp == 0) 
        return 1; 
  
    if (exp == 1) 
        return base % MOD; 
  
    long long t = exponentiation(base, exp / 2); 
    t = (t * t) % MOD; 
  
    // if exponent is even value 
    if (exp % 2 == 0) 
        return t; 
  
    // if exponent is odd value 
    else
        return ((base % MOD) * t) % MOD; 
} 

// <------------- Start of main() -------------------> //

void MAIN() {
	vll cnt0(60), cnt1(60);
	cin>>n;
	for(ll k=0;k<n;k++) {
		cin>>x;
		for(ll i=0;i<60;i++) {
			unsigned long long val = pow(2,i);
			if((x & val)) {
				cnt1[i]++;
			}
			else {
				cnt0[i]++;
			}
		}
	}


	ll ans = 0;
	for(ll i=0;i<60;i++) {
		ans += (exponentiation(2,i) * ((cnt0[i] * cnt1[i])%MOD))%MOD;
		//cout<<ans<<" ";
		ans%=MOD;
	}
	cout<<ans;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 238444
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)



int main() {
    ll n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n){
        cin >> p.at(i);
    }
    rep(i,n){
        cin >> q.at(i);
    }

    ll tmp = 1;

    vector<ll> kaijo(9);

    rep(i,n){
        tmp *= (i+1);
        kaijo.at(i+1) = tmp;
    }

    ll p_num = 0;
    ll q_num = 0;
    vector<ll> p_tmp(8);
    vector<ll> q_tmp(8);
    ll count = 0;

    rep(i,n){
        ll p_count = 0;
        ll q_count = 0;
        rep(j,p.at(i)){
            if(p_tmp.at(j) == 1){
                p_count++;
            }
        }
        rep(j,q.at(i)){
            if(q_tmp.at(j) == 1){
                q_count++;
            }
        }

        //cout << p.at(i) - p_count << endl;
        //cout << q.at(i) - q_count << endl;

        p_tmp.at(p.at(i)-1) = 1;
        q_tmp.at(q.at(i)-1) = 1;

        //cout << "----" << endl;

        p_num += (p.at(i) - p_count - 1) * kaijo.at(n-i-1);
        q_num += (q.at(i) - q_count - 1) * kaijo.at(n-i-1);

        //cout << p_num << endl;
        //cout << q_num << endl;
        //cout << "--------" << endl;

    }


    if(p_num - q_num < 0){
        cout << q_num - p_num << endl;
    }else{
        cout << p_num - q_num << endl;
    }
    

}


Measured memory_bytes: 256
unsort_list = list(map(int, input().strip().split()))

for j in range(3):
    for i in range(2):
        if unsort_list[i] > unsort_list[i+1]:
            unsort_list[i], unsort_list[i+1] = unsort_list[i+1], unsort_list[i]
print(*unsort_list)


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

int n, m;
int ufs[100010], siz[100010];
int prt(const int &u);

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		ufs[i] = i, siz[i] = 1;
	int ans = n - 1;
	while (m--) {
		int a, b; scanf("%d%d", &a, &b);
		int u = prt(a), v = prt(b);
		if (u != v) {
			if (siz[u] < siz[v])
				swap(u, v);
			siz[u] += siz[v];
			ufs[v] = u;
			--ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

int prt(const int &u) {
	return ufs[u] == ufs[ufs[u]] ? ufs[u] : ufs[u] = prt(ufs[u]);
}


Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n, k, x, y;
    cin >> n >> k >> x >> y;
    cout << x * min(k, n) + y * max(n - k, 0LL) << endl;
}

Measured memory_bytes: 256