akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

bool era[100001]={false};

void makeERA(){
	for(int i=2;i<100001;i++){
		if(era[i]==true){
			int x=100000/i;
			for(int j=2;j<=x;j++){
				era[i*j]=false;
			}
		}
	}
	era[2]=true;
}


int main(){
	for(int i=0;i<100001;i++)era[i]=true;
	era[0]=false;era[1]=false;
	makeERA();
	
	vector<int> pr;
	pr.pb(0);
	rep(i,10001)if(era[i])pr.pb(i);

	for(int i=1;i<pr.size();i++){
		pr[i] +=pr[i-1];
	}

	int n;
	while(cin>>n&&n){
		int ans=0;
		rep(i,pr.size()){
			for(int j=i+1;j<pr.size();j++){
				if( pr[j]-pr[i]==n )ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3112
#include <iostream>
using namespace std;
int main(void){
    
    int a;
    int b;
    int c,z=0;
    
    cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        
        
        if(c%i==0){
            z++;
        }
        
    
    }
    cout<<z<<endl;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,ans=0;
  cin>>n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
      cin >> a[i];
      ans+=a[i]-1;
      }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
graph = [[] for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

stack = [0]
ans = K
mod = 10**9+7
r = [True] * N
r[0] = False
while stack:
    v = stack.pop()
    tmp = K - 1
    if v > 0:
        tmp -= 1
    for child in graph[v]:
        if r[child]:
            r[child] = False
            stack.append(child)
            ans *= tmp
            tmp -= 1
            ans %= mod
print(ans)


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

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    
    string s; cin>> s;
    int n = s.length();
    bool b = isPalindrome(s);
    string s2 = "", s3 = "";
    rep(i, 0, (n-1)/2) {
        s2 += s[i];
    }

    rep(i, (n+3)/2 - 1, n) {
        s3 += s[i];
    }

    bool b2 = isPalindrome(s2), b3 = isPalindrome(s3);

    cout << (b&&b2&&b3 ? "Yes": "No") << '\n';
    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



Measured memory_bytes: 256
// 2020-06-27 18:33:04
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  vector<pair<ll, int> > a(n);
  rep(i, n) {
    ll a_;
    cin >> a_;
    a[i] = make_pair(a_, i+1);
  }
  sort(ALL(a), greater<pair<ll, int>>());
  vector<vector<ll> > dp(n+1, vector<ll>(n+1, 0));
  ll ans = 0;
  REPC(i, 1, n) {
    repc(j, i) {
      int l = i - j, r = j;
      if(l) chmax(dp[l][r], dp[l-1][r] + a[i-1].first * abs(a[i-1].second - l));
      if(r) chmax(dp[l][r], dp[l][r-1] + a[i-1].first * abs(a[i-1].second - (n-r+1)));
      chmax(ans, dp[l][r]);
    }
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 34512
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		boolean[]used=new boolean[n];
		Arrays.fill(used, false);
		ArrayList<Integer>[]path=new ArrayList[n];
		for(int i=0;i<n;i++) {
			path[i]=new ArrayList<Integer>();
		}
		int[]a=new int[m];
		int[]b=new int[m];
		for(int i=0;i<m;i++) {
			a[i]=sc.nextInt()-1;
			b[i]=sc.nextInt()-1;
			path[a[i]].add(b[i]);
			path[b[i]].add(a[i]);
		}
		Queue<Integer>ans1=new LinkedList<Integer>();
		Stack<Integer>ans2=new Stack<Integer>();
		int start=0;
		used[start]=true;
		ans1.add(start);
		int end1=start;
		int end2=path[end1].get(0);
		used[end2]=true;
		ans1.add(end2);
		
		while(true) {
			int next=-1;
			for(int i=0;i<path[end2].size();i++) {
				if(!used[path[end2].get(i)]) {
					next=path[end2].get(i);
					ans1.add(next);
					used[next]=true;
					end2=next;
					break;
				}
			}
			if(next==-1)break;
		}
		while(true) {
			int next=-1;
			for(int i=0;i<path[end1].size();i++) {
				if(!used[path[end1].get(i)]) {
					next=path[end1].get(i);
					ans2.push(next);
					used[next]=true;
					end1=next;
					break;
				}
			}
			if(next==-1)break;
		}
		System.out.println(ans1.size()+ans2.size());
		while(!ans2.isEmpty()) {
			System.out.print(ans2.pop()+1);
			if(!ans2.isEmpty())System.out.print(" ");
			else if(!ans1.isEmpty())System.out.print(" ");
		}
		while(!ans1.isEmpty()) {
			System.out.print(ans1.poll()+1);
			if(!ans1.isEmpty())System.out.print(" ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 104784
#include<bits/stdc++.h>
using namespace std;
int main(){
  double n,k,ans=0;
  cin>>n>>k;
  for(int i=1;i<=n;i++){
    int now=i;
    double temp=1/n;
    while(now<k){
      now*=2;
      temp/=2;
    }
    ans+=temp;
  }
  printf("%.10f\n",ans);
  return(0);
}


Measured memory_bytes: 256
import copy

def check(ss, l):
    ns = []
    for s in ss:
        for i in range(4):
            if nmaze[s[0]+move[i][0]][s[1]+move[i][1]] == '.':
                nmaze[s[0]+move[i][0]][s[1]+move[i][1]] = l
                ns.append([s[0]+move[i][0], s[1]+move[i][1]])
    if len(ns) > 0:
        return check(ns, l+1)
    else:
        return l

H, W = map(int, input().split())
maze = []
for _ in range(H):
    maze.append(['#'] + list(input()) + ['#'])
maze = [['#']*(W+2)] + maze + [['#']*(W+2)]

move = [[-1, 0], [1, 0], [0, -1], [0, 1]]
ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if maze[i][j] == '.':
            nmaze = copy.deepcopy(maze)
            nmaze[i][j] = 0
            l = check([[i, j]], 0)
            if ans < l:
                ans = l
print(ans)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;
using usize = ::std::size_t;
//using u64 = ::std::int_least64_t;
using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;


int main(int argc, char *argv[])
{
    
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<vector<int>> D(N, vector<int>(2));
    for (int i = 0; i < N; i++) {
        cin >> D[i][0] >> D[i][1];
    }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        cnt = 0;
        for (int j = 0; j < 3 && i + j < N; j++) {
            if (D[i + j][0] == D[i + j][1]) {
                cnt++;
            }
        }
        if (cnt == 3) {
            break;
        }
    }
    
    cout << ((cnt == 3) ? "Yes" : "No") << endl;
    
    return 0;
    
}


Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nk = Input.ar;
        var str = ReadLine();
        var len1 = new List<int>();
        var len0 = new List<int>();
        var ct = 1;
        for (var i = 1; i < nk[0]; i++)
        {
            if (str[i - 1] == str[i])
                ct++;
            else
            {
                if (str[i - 1] == '0') len0.Add(ct);
                else len1.Add(ct);
                ct = 1;
            }
        }
        if (str[nk[0]-1] == '0') len0.Add(ct);
        else len1.Add(ct);
        var sum1 = new int[len1.Count + 2];
        for (var i = 1; i <= len1.Count; i++)
            sum1[i] = sum1[i - 1] + len1[i - 1];
        sum1[len1.Count + 1] = sum1[len1.Count];
        var sum0 = new int[len0.Count + 1];
        for (var i = 1; i <= len0.Count; i++)
            sum0[i] = sum0[i - 1] + len0[i - 1];
        var res = 0;
        if(len0.Count<nk[1])
        {
            res = str.Length;
        }
        for (var i = 0; i < len0.Count - nk[1]+1; i++)
        {
            var calc = sum0[i + nk[1]] - sum0[i];
            if (str[0] == '0')
            {
                if (i == 0)
                    calc += sum1[i + nk[1]] - sum1[i];
                else calc += sum1[i + nk[1]] - sum1[i - 1];
            }
            else
            {
                calc += sum1[i + nk[1] + 1] - sum1[i];
            }
            res = Max(res, calc);
        }
        if (len1.Count == 1) res = Max(len1[0], res);
        WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 12768
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
	int N, W, w[110], v[110];
    ll dp[2][100010];
	cin >> N >> W;
    for (int i = 1; i <= N; ++i){
        cin >> w[i] >> v[i];
    }

    
    for (int i = 0; i <= N; ++i){
        for (int j = 0; j <= W; ++j){
            if (i == 0) dp[i][j] = 0;

            else if (j-w[i] < 0){ 
                dp[i%2][j] = dp[(i-1)%2][j];
            } else {
                dp[i%2][j] = max(dp[(i-1)%2][j], dp[(i-1)%2][j-w[i]] + v[i]);
            }
        }
    }

    cout << dp[N%2][W] << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int k; cin >> k;
    string s; cin >> s;
    int len = s.length();

    if (len <= k) {
        cout << s << endl;
    } else {
        for (int i = 0; i < k; ++i) {
            cout << s[i];
        }
        cout << "...";
        cout << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A,P;
    cin >> A>> P;
    P += A*3;
    cout << P/2 << endl;
    return (0^_^0);
}



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

a1 = sum(a)**2 
a2 = 0
for i in range(len(a)):
    a2 = (a2 + (a[i]**2)) 

ans = ((a1 - a2) // 2) % 1000000007
print(ans)

Measured memory_bytes: 31752
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

const int NUMBER = 8;

int fanctional(int n)
{
    int c = 1;
    for (int i = 1;i <= n;i++){
        c *= i;
    }
    return c;
}

int abs(int a,int b)
{
    if (a > b){
        return a-b;
    }
    else {
        return b-a;
    }
}

int main()
{
    int n;
    int p[NUMBER];
    int q[NUMBER];
    
    cin >> n;
    for (int i = 0;i < n;i++){
        cin >> p[i];
    }
    for (int i = 0;i < n;i++){
        cin >> q[i];
    }
    
    int pn = 1;
    int qn = 1;
    bool b[NUMBER] = {0};
    int x;
    
    for (int i = 0;i < n;i++){
        b[p[i]] = true;
        x = 0;
        for (int j = 1;j < p[i];j++){
            
            if (b[j] == false){
                x++;
            }
        }
        pn += x*fanctional(n-1-i);
    }
    
    for (int i = 0;i < n;i++){
        b[i] = 0;
    }
    for (int i = 0;i < n;i++){
        b[q[i]] = true;
        x = 0;
        for (int j = 1;j < q[i];j++){
            
            if (b[j] == false){
                x++;
            }
        }
        qn += x*fanctional(n-1-i);
    }
    
    cout << abs(pn,qn) << endl;
}




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

using namespace std;

int main(int argc, const char * argv[]) {
    int n = 0, m = 0, c = 0;
    cin >> n >> m >> c;
    
    vector<int> cb(m, 0);
    for(int i = 0; i < m; ++i) {
        cin >> cb[i];
    }
    
    int result = 0;
    vector<int> ca(m, 0);
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            cin >> ca[j];
        }
        
        int sum = 0;
        for(int j = 0; j < m; ++j) {
            sum += ca[j] * cb[j];
        }
        sum += c;
        if(sum > 0) {
            result += 1;
        }
    }
    cout << result << endl;
    return 0;
}

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

const static inline void rec(int data)
{
  if(data == 0) return;
  int next = abs(data) % 10;
  if(data < 0) next = (10 - next) % 10;
  rec((data - next) / -10);
  cout << next;
}

int main()
{
  int N;
  while(cin >> N, N) { 
    rec(N);
    cout << endl;
  }
  return(0);
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int n;
  cin >> n;
  int* h = new int[n];
  for (unsigned int i = 0; i < n; i++)
  {
  	cin >> h[i];
  }
  
  int max = 0;
  int move = 0;
  
  for (int i = 1; i < n; i++)
  {
  	if (h[i-1] >= h[i])
  	{
  		move++;
  	}
  	else
  	{
  		if (move >= max)
  		{
  			max = move;
  		}
  		move = 0;
  	}
  }
  if (move >= max)
  {
  	max = move;
  }
  
  cout << max;
  
  delete[] h;
}

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

using namespace std;

const int N=1e5+10;
int a[N];

int main()
{
    int n,i,sum=0,l=1,t;
    cin >> n;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    t=a[0];
    for(i=1;i<n;i++)
    {
        if(a[i]==t) sum++;
        else
        {
            t=a[i];
            l++;
        }
    }
    if(sum%2==1)
    cout << l-1 << endl;
    else
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 640
if __name__ == '__main__':

	W = ["Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"]
	Y = [31,29,31,30,31,30,31,31,30,31,30,31]

	while True:
		m,d = map(int,input().split())
		if m == 0 and d == 0:
			break

		day = 0
		for i in range(m-1):
			day += Y[i]
		day += d

		ans = day % 7
		print(W[ans-1])




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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> B(N), C(N);
    for(unsigned long i{0}, A; i < N; ++i){
        cin >> A;
        B[i] = A + 1000000000 + N - i;
        C[i] = 1000000000 - A + N - i;
    }
    sort(B.begin(), B.end());
    unsigned long ans{0};
    for(const auto& i : C)ans += upper_bound(B.begin(), B.end(), i) - lower_bound(B.begin(), B.end(), i);
    cout << ans << endl;
    return 0;
}

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

using P = pair<int, vector<int> >;
int N;
vector<int> a, b;
int main()
{
    cin >> N;
    a.resize(N);
    b.resize(N);
    for (int i=0; i<N; i++) cin >> a[i];
    for (int i=0; i<N; i++) cin >> b[i];
    
    vector<vector<vector<int> > > patterns(N);
    for (int i=0; i<N; i++)
    {
        queue<P> q;
        q.push(make_pair(a[i], vector<int>(0)));
        while(!q.empty())
        {
            P p = q.front();
            q.pop();
            if (p.first == b[i]) patterns[i].push_back(p.second);
            else if (p.first < b[i]) continue;
            else
            {
                for (int j = b[i]+1; j<=p.first; j++)
                {
                    if (p.first%j>=b[i])
                    {
                        vector<int> hoge = p.second;
                        hoge.push_back(j);
                        q.push(make_pair(p.first%j, hoge));
                    }
                }
            }
        }
    }
    // for (auto i : patterns)
    // {
    //     for (auto j : i)
    //     {
    //         for (auto k : j) cout << k << " ";
    //         cout << endl;
    //     }
    //     cout << endl;
    // }

    vector<vector<long long> > scores(N);
    for (int i=0; i<N; i++)
    {
        for (auto vec : patterns[i])
        {
            long long tmp = 0;
            for (auto el : vec) tmp += 1LL << el;
            scores[i].push_back(tmp);
        }
        if (scores[i].size() == 0)
        {
            cout << -1 << endl;
            return 0;
        }
        sort(scores[i].begin(), scores[i].end());
    }

    long long scores_touse = 0;
    while (!scores.empty())
    {
        int maxtmp = 0;
        for (int i=1; i<scores.size(); i++) if (scores[i][0] > scores[maxtmp][0]) maxtmp = i;
        scores_touse = scores_touse | scores[maxtmp][0];
        scores.erase(scores.begin() + maxtmp);

        for (auto &vec : scores)
        {
            for (auto &i : vec) i = i & ~scores_touse;
            sort(vec.begin(), vec.end());
        }
    }
    cout << scores_touse << endl;
    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
struct Card {
  char suit[3];
  char value;
  int i;
};

void BubbleSort(struct Card[], int);
void SelectionSort(struct Card[], int);
void Stable(struct Card[], int);

int main(){
  int N, i;
  struct Card C1[36];
  struct Card C2[36];

  scanf("%d",&N);
  for( i = 0 ; i < N ; i++ ){
    scanf("%s",&C1[i].suit);
    C1[i].value = C1[i].suit[1];
    C1[i].i = i;
    C2[i] = C1[i];
  }

  BubbleSort(C1, N);
  SelectionSort(C2, N);

  printf("%s",C1[0].suit);
  for( i = 1 ; i < N ; i ++ ){
    printf(" %s",C1[i].suit);
  }
  printf("\n");

  Stable(C1, N);

  printf("%s",C2[0].suit);
  for( i = 1 ; i < N ; i ++ ){
    printf(" %s",C2[i].suit);
  }
  printf("\n");

  Stable(C2, N);

  return 0;
}

void BubbleSort(struct Card C[], int N){
  int i, j;
  struct Card tmp;
  for( i = 0 ; i < N ; i++ ){
    for( j = N-1 ; j >= i+1 ; j-- ){
      if( C[j].value < C[j-1].value ){
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
      }
    }
  }
}

void SelectionSort(struct Card C[], int N){
  int i, j, minj;
  struct Card tmp;
  for( i = 0 ; i < N ; i++ ){
    minj = i;
    for( j = i ; j < N ; j++ ){
      if( C[j].value < C[minj].value ) minj = j;
    }
    tmp = C[i];
    C[i] = C[minj];
    C[minj] = tmp;
  }
}

void Stable(struct Card C[], int N){
  int i, flag=0;
  for( i = 0 ; i < N-1 ; i++ ){
    if( C[i].value == C[i+1].value ){
      if( C[i].i > C[i+1].i ){
        printf("Not stable\n");
        flag = 1;
        break;
      }
    }
  }
  if( flag == 0  )printf("Stable\n");
}



Measured memory_bytes: 2144
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}
int main() {
	int N,K,a,i,ans=0;
	cin >> N >> K;
	vector<int> vec(200000);
	REP(i, N) {
		cin >> a;
		vec[a]++;
	}
	sortR(vec.begin(), vec.end());
	REP(i, K) {
		ans += vec[i];
	}
	cout << N - ans << endl;

}

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


int main() {
    string s, t;
    cin >> s >> t;
    int n=sz(s), m=sz(t);
    vector<int> is[26];
    rep(i,n) is[s[i]-'a'].push_back(i);
    rep(i,n) is[s[i]-'a'].push_back(i+n);
    ll ans=0;
    int p=0;
    rep(i,m){
        int c = t[i]-'a';
        if (sz(is[c])==0) {
            cout<<-1<<endl;
            return 0;
        }
        p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
        if (p>=n) {
            p -= n;
            ans+=n;
        }
    }
    ans += p;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

class union_find {
public:
vector<int> par,rank,lsize;
union_find(int n): par(n),rank(n),lsize(n){
   for (int i=0;i < n;i++){
      par[i]=i;
      rank[i]=0;
      lsize[i]=1;
   }
}

int find(int x){
   if (par[x]==x){
      return x;
   }
   else{
      return par[x] = find(par[x]); 
   }
}

void unite(int x ,int y){
   x=find(x);
   y=find(y);
   if (x==y) return;
   if (rank[x] < rank[y]){
      lsize[y]+=lsize[x];
      lsize[x] = -1;
      par[x] = y;
   }else{
      lsize[x]+=lsize[y];
      lsize[y]= -1;
      par[y]=x;
      if (rank[x]==rank[y]) rank[x]++;
   }
}
  

bool same(int x, int y){
   return find(x) == find(y);
}
int size(int x){
   if (lsize[x] == -1){
      x=find(x);
   }
   return lsize[x];
}
};

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  union_find tree(n);
  vector<int> t(n,0);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    tree.unite(a,b);
    t[a]++;
    t[b]++;
  
  }
  rep(j,k){
    int a,b;
    cin >> a >> b;
    a--;b--;
    if (tree.same(a,b)){
      t[a]++;
      t[b]++;
    }
  }
  rep(w,n){
    cout << tree.size(w)-t[w]-1 << " ";
  }
  cout << endl;

 return 0; 
}


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

using namespace std;
 int a[1000000] {0};
int main()
{
	int t;
	t=1;
	while(t--)
	{
    int i,j,k,n,m,x,y,z;
    
    cin>>n;
   
    for(i=1;i<=101;i++)
    {
    	
    	
    	for(j=1;j<=101;j++)
    	{
    		for(k=1;k<=101;k++)
    	    {
    	    	x=i+j;
    	    	y=j+k;
    	    	z=i+k;
    	    	
    	    	if(  ((x*x)+(y*y)+ (z*z))%2==0 )
    	    	a[  ( x*x +y*y +z*z )/2   ]++;
    	    	
    	    	
    	    	
			}
    		
    		
		}
    	
	}
	
	
	for(i=1;i<=n;i++)
	{   
	cout<<a[i]<<endl;
	
     }
     
     
	}



}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 1e5 + 10;
char s[N][5];
int ans[N];
int main(){
	int n, a[3];
	scanf("%d %d %d %d", &n, &a[0], &a[1], &a[2]);
	bool io = (1LL * a[0] + a[1] + a[2]) >= 3LL;
	for(int i = 1; i <= n; i++){
		scanf("%s", s[i]);
	}

	for(int i = 1; i <= n; i++){
		int pt1 = s[i][0] - 'A', pt2 = s[i][1] - 'A';
		if(a[pt1] == 0 && a[pt2] == 0) return !printf("No");
		if(io || (i == n || a[pt1] != 1 || a[pt2] != 1)){
			if(a[pt1] > a[pt2]) a[pt2]++, a[pt1]--, ans[i] = pt2;
			else a[pt1]++, a[pt2]--, ans[i] = pt1;
		}
		else{
			if(s[i + 1][0] == s[i][0] && s[i + 1][1] == s[i][1]) a[pt2]++, a[pt1]--, ans[i] = pt2;
			else if(s[i + 1][0] == s[i][0] || s[i + 1][1] == s[i][0]) a[pt1]++, a[pt2]--, ans[i] = pt1;
			else a[pt2]++, a[pt1]--, ans[i] = pt2;
		}
	}
	printf("Yes\n");
	for(int i = 1; i <= n; i++){ 
		printf("%c\n", 'A' + ans[i]);
	}

}

Measured memory_bytes: 4680
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int inf= 1e9+7;
const int nmax = 1e5+10;

//priority_queue<int,vector<int>,greater<int>>pq; //ascending

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n,t;
    cin>>n;
    map<ll,ll>mp;
    for(int i=0;i<n;i++){cin>>t;mp[t]++;}

    ll ans=0;

    for(auto i=mp.begin();i!=mp.end();i++)
    {
        //cout<<i->first<<" "<<i->second<<endl;

        if(i->second>=i->first)ans+=i->second-i->first;
        else ans+=i->second;
    }

    cout<<ans<<endl;





    return 0;
}


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

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

int main () {
    int x, y; cin >> x >> y;
    printf("%d\n", gcd(x, y));
    
    return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
#include <cstring>

using namespace std;

const int MAXN = 110;
const double eps = 1e-12;

double pro[MAXN][55][55];
double speed[MAXN], rest[MAXN], p[MAXN];
double to[MAXN][55];
double dis;
int n, m;

void read()
{
    for(int i = 0; i < n; ++i)
    {
        scanf("%lf%lf%lf", p + i, rest + i, speed + i);
        p[i] *= 0.01;
    }

    memset(pro, 0, sizeof(pro));
    for(int i = 0; i < n; ++i)
    {
        pro[i][0][0] = 1.0;
        for(int j = 1; j <= m; ++j)
        {
            pro[i][j][0] = pro[i][j - 1][0] * (1 - p[i]);
            for(int k = 1; k <= j; ++k)
                pro[i][j][k] = pro[i][j -  1][k] * (1 - p[i]) + pro[i][j - 1][k - 1] * p[i];
        }
    }

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j <= m; ++j)
            to[i][j] = dis / speed[i] + j * rest[i];
    }
}
double ans[MAXN];
int main()
{
    while(scanf("%d%d%lf", &n, &m, &dis) != EOF)
    {
        read();
        for(int i = 0; i < n; ++i)
        {
            ans[i] = 0.0;
            for(int j = 0; j <= m; ++j)
            {
                double hh(pro[i][m][j]);
                for(int k = 0; k < n; ++k)
                {
                    if(k == i)  continue;
                    double tmp = 1.0;
                    for(int u = 0; u <= m; ++u)
                    {
                        if(to[k][u] > to[i][j] + eps)  break;
                        tmp -= pro[k][m][u];
                    }
                    hh *= tmp;
                }
                ans[i] += hh;
            }
        }
        for(int i = 0; i < n; ++i)
            printf("%lf\n", ans[i]);
    }


    return 0;
}

Measured memory_bytes: 3404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEsL 2e9
#define PIE 3.1415a926535

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    string s;
    int q;
    cin >> s >> q;
    int query;
    int f;
    string c;
    bool bit = true;
    rep(i,q) {
        cin >> query;
        if (query == 1) {
            if (bit)
                bit = false;
            else
                bit = true;
        }
        else if (query == 2) {
            cin >> f >> c;
            if (f == 1) {
                if (bit)
                    s.insert(0, c);
                else
                    s.insert(s.size(), c);
            }
            else if (f == 2) {
                if (bit)
                    s.insert(s.size(), c);
                else
                    s.insert(0, c);
            }    
        }
    }
    if (!bit)
        reverse(s.begin(), s.end());
    cout << s << endl;
}

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

// why am I so weak

int n;
long long a[200055];

int main() {
	scanf("%d", &n);

	long long sum = 0;

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

	long long res = LLONG_MAX;

	for (int i = 0; i + 1 < n; i++) {
		if (i) a[i] += a[i - 1];

		res = min(res, abs(a[i] - (sum - a[i])));
	}

	printf("%lld\n", res);

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b;
int main(){
  cin>>a>>b;
  b/=__gcd(a,b);
  ll x=b;
  ll ans=1;
  map<ll,bool> mp;
  for(ll i=2;i*i<=b;i++){
    while(x%i==0){
      if(!mp[i])ans*=i;
      mp[i]=true;
      x/=i;
    }
  }
  if(x>1)ans*=x;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3120
# N,M = map(int, input().split())
N = int(input())
S = input()

from collections import Counter
c = Counter(S)
mod = 10**9 + 7
ans = 1

allc = "abcdefghijklmnopqrstuvwxyz"
for ch in allc:
    ans = ans * (c[ch]+1) % mod
print(ans-1)


Measured memory_bytes: 3444
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(500000)

n,m=map(int,input().split())

a=[[] for _ in range(n)]

for i in range(m):
    ta,tb=map(int, input().split())
    if ta!=1:
        a[tb-1].append(ta-1)
    if tb!=1:
        a[ta-1].append(tb-1)

KITENAI=900000
ans=[0]*n
mk=[KITENAI]*n
mk[0]=0
qu=[0]

def setnext(now):
    global mk
    global qu

    for i in a[now]:
        if mk[i]==KITENAI:
            qu.append(i)
            mk[i]=mk[now] + 1
            ans[i]=now+1

while len(qu)>0:
    setnext(qu.pop(0))

print("Yes")
for i in range(n-1):
    print(ans[i+1])

Measured memory_bytes: 37400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  ll K;
  cin>>N>>K;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  rep(i,N) A[i]--;

  vector<int> v;
  int now=0;
  vector<int> used(N,-1);
  int T;
  for(int i=0;;i++){
    if(used[now]!=-1){
      T=i-used[now];
      break;
    }
    v.push_back(now);
    used[now]=i;
    now=A[now];
  }

  if(K<=used[now]){
    cout<<v[K]+1<<endl;
    return 0;
  }

  K-=used[now];
  K%=T;
  cout<<v[used[now]+K]+1<<endl;

  return 0;
}


Measured memory_bytes: 5812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main()
{
ll n,c=0; cin>>n;
string s; cin>>s;
if(n%2==1) cout<<"No"<<endl;
else {
for(int i=0;i<n;i++)
{
    if(s[i]==s[n/2+i])
    {
        c++;
    }
}
if(c!=n/2) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}

}


Measured memory_bytes: 3564
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int a[100005];
        for(int i=1; i<=n; i++) cin>>a[i];
        int f,ans=0;
        if(n%2==0)
        {
            for(int i=1; i<=n; i++)
                if(a[i]==i) ans++,i++;
        }else{
            f=0;
            for(int i=1; i<n; i++)
                if(a[i]==i){
                    if(i==n-1) f=1;
                    ans++,i++;
                }
            if(!f&&a[n]==n) ans++;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 640
#include<iostream>

int Digit(int x)
{
	int n=0;

	do
	{
		x/=10;

		++n;
	}
	while(x>=1);

	return n;
}

int main()
{
	int a, b;

	while(std::cin >> a >> b)
	{
		std::cout << Digit(a+b) << '\n';
	}
}

Measured memory_bytes: 1160
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

nmk = input().split()
N = int(nmk[0])
M = int(nmk[1])
K = int(nmk[2])

uf = UnionFind(N+1)
block = [0]*(N+1)

for i in range(M):
    ab = input().split()
    A = int(ab[0])
    B = int(ab[1])
    block[A]+=1
    block[B]+=1
    uf.union(A,B)

ans = [0]*(N+1)

for i in range(1,N+1):
    ans[i] = uf.size(i)-1

for i in range(K):
    cd = input().split()
    C = int(cd[0])
    D = int(cd[1])
    if uf.same(C, D):
        block[C]+=1
        block[D]+=1

for i in range(1,N+1):
    print(ans[i]-block[i])






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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int d, t, s;
	cin >> d >> t >> s;
	if(s * t >= d) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3648
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String S = sc.next();
      	String T = sc.next();
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	String U = sc.next();
      	
      	if(U.equals(S)) A--;
      	else B--;
      
      	System.out.println(A + " " + B);
    }
}

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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    string s;
    cin >> s;

    bool c = false, f = false;    
    rep(i, s.size()){
        if(s[i] == 'C'){
            c = true;
        }

        if(s[i] == 'F' && c){
            f = true;
        }
    }

    if (c && f)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    vec<ll> A(N);
    for(auto& x:A) cin >> x;
    vec<ll> S(N+1),sum(N+1);
    for(int i=0;i<N;i++){
        S[i+1] = A[i];
        if(i-1>=0) S[i+1] += S[i-1];
        sum[i+1] = sum[i]+A[i];
    }

    auto solve = [&](ll x){
        int l = 0,r = (N+1)/2;
        //上からm番目を取れるか？
        while(l+1<r){
            int m = (l+r)/2;
            ll target = A[N-m-1];
            ll opp = A[N-2*m-1];
            if(abs(x-opp)<=abs(x-target)) l = m;
            else r = m;
        }
        ll res = sum[N]-sum[N-l-1];
        int ar = N-2*l-1;
//        cerr << x << " " << ar << "\n";
        if(ar) res += S[ar-1];
        return res;
    };

    while(Q--){
        ll x;
        cin >> x;
        cout << solve(x) << "\n";
    }
}

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

int n;
int a[35] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
	cin >> n;
	cout << a[n-1];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int n, maxsofar=0, curr, s=0;
  cin >> n;
  while(n--) {
    cin >> curr;
    if(maxsofar<=curr) {
      maxsofar=curr;
      s++;
    }
  }
  cout << s;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<functional>
#include<queue>

const int INF = 1 << 30;	
typedef std::pair<int, int> P;
struct edge{ 
	int to, cost; 

	edge(int to, int cost)
		: to(to), cost(cost)
	{}
};
const int V = 20;
std::vector<edge> G[V];
int d[V];

void dijkstra(int s){
	std::priority_queue<P, std::vector<P>, std::greater<P>> que;
	std::fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); ++i){
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i != m; ++i)
	{
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		G[a].push_back(edge(b, c));
		G[b].push_back(edge(a, d));
	}
	int x1, x2, y1, y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
	dijkstra(x1);
	y1 -= d[x2];
	dijkstra(x2);
	y1 -= d[x1];
	y1 -= y2;
	printf("%d\n", y1);
	return 0;
}

Measured memory_bytes: 1016
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def getLcm(a, b):
    return a * b // gcd(a, b)

def lcmArr(a):
    return reduce(getLcm, a)

n = int(input())
a = list(map(int, input().split()))

lcm = lcmArr(a)
lcm %= MOD
ret = 0
for val in a:
    ret += lcm * pow(val, MOD - 2, MOD)
    ret %= MOD
print(ret)


Measured memory_bytes: 4708
(defun split (input stack-string output-list)
  (let ((chara (car input)))
    (case chara
          ((nil) (append output-list (list stack-string)))
          (#\space (split (cdr input)
                                  '()
                                  (append output-list (list stack-string))))
          (otherwise (split (cdr input)
                                    (concatenate 'string stack-string (list chara))
                                    output-list)))))

(defun input-to-list (input)
  (mapcar #'parse-integer (split (concatenate 'list input)
                                 '()
                                 '())))
(defparameter param (input-to-list (read-line)))
(princ (cond ((<= (car param) 5) 0)
  ((and (<= (car param) 12)
        (>= (car param) 6)) (/ (cadr param) 2))
  (t (cadr param))))


Measured memory_bytes: 4576
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main()
{
#ifdef iq
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;
    vector <pair <int, int> > go;
    go.emplace_back(a, c);
    go.emplace_back(b, d);
    bool bad = false;
    vector <vector <bool> > reach;
    for (auto check : go) {
        int a = check.first, b = check.second;
        vector <bool> cur(n);
        while (a < b) {
            cur[a] = true;
            if (s[a + 1] == '.') {
                a++;
                continue;
            }
            if (a + 2 < n && s[a + 2] == '.') {
                a += 2;
                continue;
            }
            break;
        }
        cur[a] = true;
        reach.push_back(cur);
        if (a != b) {
            bad = true;
        }
    }
    if (bad) {
        cout << "No\n";
        return 0;
    } else {
        if (c < d) {
            cout << "Yes\n";
            return 0;
        }
        for (int i = b; i <= d; i++) {
            if (reach[1][i] && (i - 1 >= 0) && (i + 1 < n) && reach[0][i - 1] && reach[0][i + 1]) {
                cout << "Yes\n";
                return 0;
            }
        }
        cout << "No\n";
    }
}

Measured memory_bytes: 592
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	ll c;
	int n;
	ll x[100000];
	ll v[100000];
	ll migi[100000];
	ll hidari[100000];
	scanf("%d%lld",&n,&c);
	for(int i=0;i<n;i++) scanf("%lld%lld",x+i,v+i);
	ll sum = 0;
	for(int i=0;i<n;i++){
		sum += v[i];
		migi[i] = sum - x[i];
	}
	sum = 0;
	for(int i=n-1;i>=0;i--){
		sum += v[i];
		hidari[i] = sum - c + x[i];
	}
	ll ans = 0;
	for(int i=0;i<n;i++) ans = max(ans,migi[i]);
	for(int i=0;i<n;i++) ans = max(ans,hidari[i]);
	ll mimi[100000];
	ll hihi[100000];
	for(int i=0;i<n;i++){
		if(i==0) mimi[i] = migi[i] - x[i];
		else mimi[i] = max(migi[i]-x[i],mimi[i-1]);
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1) hihi[i] = hidari[i];
		else hihi[i] = max(hidari[i],hidari[i+1]);
	}
	for(int i=0;i<n-1;i++) ans = max(ans,mimi[i]+hihi[i+1]);

	for(int i=n-1;i>=0;i--){
		if(i==n-1) hihi[i] = hidari[i] - c + x[i];
		else hihi[i] = max(hidari[i]-c+x[i],hihi[i+1]);
	}
	for(int i=0;i<n;i++){
		if(i==0) mimi[i] = migi[i];
		else mimi[i] = max(migi[i],migi[i-1]);
	}
	for(int i=0;i<n-1;i++) ans = max(ans,mimi[i]+hihi[i+1]);
	printf("%lld\n",ans);
}


Measured memory_bytes: 4864
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
    static void Main(string[] args)
    {
        // 入力
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        List<List<int>> bridge = new List<List<int>>();

        for(int i = 0; i<M; i++)
        {
            input = Console.ReadLine().Split(' ');
            List<int> b = new List<int>() { int.Parse(input[0]) - 1 , int.Parse(input[1]) - 1};
            bridge.Add(b);
        }

        List<long> ret = new List<long>();
        long inc = (long)N * (N - 1) / 2;
        ret.Add(inc); // 全ての橋が崩落した場合の不便度

        //Console.WriteLine(inc + " first factor" );
        // 島が属するグループ - 島番号 のリストを作る
        List<List<int>> group_island = new List<List<int>>(); //{new int[N,0]};
        List<int> island_group = new List<int>();
        for (int i = 0; i < N; i++ )
        {
            List<int> a = new List<int>(){i};
            group_island.Add(a);
            island_group.Add(i);
        }
        //Console.WriteLine("map count:" + map.Count);
        for (int i = M - 1; i >= 0; i--)
        {
            //Console.WriteLine("i:" + i + " bridge:" + bridge.Count);
            // 橋を１本ずつ掛けていく
            long conv = howManyConvenience(bridge[i], ref group_island, ref island_group);

            //Console.WriteLine("decreese " + conv); 

            conv = ret[ret.Count - 1] - conv;
            //if (conv <= 0) break;

            ret.Add(conv);
        }

        for(int i=M-1; i>=0; i--)
        {
            Console.WriteLine(ret[i]);
        }
        
    }

    static long howManyConvenience(List<int> b, ref List<List<int>> group_island, ref List<int> island_group)
    {
        // bの橋を掛けることで、連結される島の数を数える
        long ret = 0;
        int ba = b[0], bb = b[1];

        // baが属しているグループ = bbが属しているグループの場合、便利さに変化なし
        int ga = island_group[ba], gb = island_group[bb];
        if(ga == gb)
            return 0;

        // 異なる場合、グループを統合する(移動する島が少ない方にする)
        int ca = group_island[ga].Count, cb = group_island[gb].Count;
        ret = ca * cb;

        int ming = ga, maxg = gb;
        if(ca > cb)
        {
            ming = gb;
            maxg = ga;
        }

        for (int i = 0; i < group_island[ming].Count; i++ )
        {
            int island = group_island[ming][i];
            island_group[island] = maxg;
        }
            
        group_island[maxg].AddRange(group_island[ming]);

        return ret;
    }
}

Measured memory_bytes: 47496