akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		sc.close();
		if(A <= C) {
			if(D <= B) {
				System.out.println(D - C);
			}else if(C <= B) {
				System.out.println(B - C);
			}else {
				System.out.println(0);
			}
		}else {
			if(D <= A) {
				System.out.println(0);
			}else if(D >= B) {
				System.out.println(B - A);
			}else if(D >= A) {
				System.out.println(D - A);
			}
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll a;
    cin >> a;
    string s;
    cin >> s;
    ll b, c, d;
    b = s[0] - '0';
    c = s[2] - '0';
    d = s[3] - '0';
    //cout << b << c << d << endl;
    ll ans = 0;
    ans += a*(100*b + 10*c + d);
    ans /= 100;
    //cout << ans << endl;
    cout << ans << endl;
    return 0;
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

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

    int souwa = 0;
    REP(i, n-1) {
        souwa += abs(a[i+1] - a[i]);
    }

    souwa += abs(a[0]);
    souwa += abs(a[n-1]);
    int tmp;

    REP(i, n) {
        if(i == 0) {
            tmp = souwa;
            tmp -= abs(a[0]) + abs(a[0] - a[1]);
            tmp += abs(a[1]);
            cout << tmp << endl;
        } else if (i == n-1) {
            tmp = souwa;
            tmp -= abs(a[n-1]) + abs(a[n-1] - a[n-2]); 
            tmp += abs(a[n-2]);
            cout << tmp << endl;
        } else {
            tmp = souwa;
            tmp -= abs(a[i] - a[i-1]) + abs(a[i+1] - a[i]);
            tmp += abs(a[i+1] - a[i-1]);
            cout << tmp << endl;
        }
    }

    return 0;
}
 

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

#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vi vector<int>
using namespace std;
int mod = 1'000'000'000 + 7;

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

string S;
ll l;

ll f(ll x, ll y) {
    ll res = 0;
    for (int i = x; i < y; i++) {
        res += S[i] - '0';
        res *= 10;
    }
    return res / 10;
}

ll solve(ll x = 0) {
    // S[x]以降で出来る文字列の和
    ll res = f(x, l);
    for (int i = x + 1; i < l; i++) {
        res += solve(i);
        res += f(x, i) * pow(2, l - i - 1);
    }
    return res;
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    cin >> S;
    l = S.length();
    cout << solve() << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();    	
      	int[] a = new int[n];
      	int mid = 0;
      	int count = 0;
        for(int i = 0; i < a.length; ++i){
          a[i] = sc.nextInt();
        } 
        for(int i = 0; i <(n-2); i++){
            mid = a[(i+1)];
            if(mid > a[i] && mid < a[(i+2)]){
            count += 1; 
            }if(mid < a[i] && mid > a[(i+2)]){
            count += 1; 
            }
        }
         System.out.println(count);
    }
}


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

int main(){
  int n;
  std::cin>>n;
  std::vector<int64_t> a(n);
  for(auto& ai:a)std::cin>>ai;
  
  std::vector<int64_t> sum(n+1);
  for(int i=0;i<n;++i)sum[i+1] = sum[i]+a[i];
  
  constexpr int64_t mod = 1e9+7;
  int64_t ans = 0;
  for(int i=0;i+1<n;++i){
    int64_t sum_aj = sum[n]-sum[i+1];
    sum_aj %= mod;
    ans += a[i]*sum_aj%mod;
    ans %= mod;
  }
  
  std::cout << ans << std::endl;
}

Measured memory_bytes: 6404
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

string c_j(string str);
string c_c(string str);
string c_e(string str);
string c_a(string str);
string c_p(string str);
string c_m(string str);

int main()
{
	int n;
	string order, message;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> order >> message;
		string ans = message;
		for(int j = order.length()-1; j >= 0; j--){
			if(order[j] == 'J') ans = c_j(ans);
			else if(order[j] == 'C') ans = c_c(ans);
			else if(order[j] == 'E') ans = c_e(ans);
			else if(order[j] == 'A') ans = c_a(ans);
			else if(order[j] == 'P') ans = c_p(ans);
			else if(order[j] == 'M') ans = c_m(ans); 
		}
		cout << ans << endl;
	}
	return 0;
}

string c_j(string str)
{
	char c;
	c = str[str.length()-1];
	str.erase(str.end()-1);
	str = c + str;
	return str;
}

string c_c(string str)
{
	char c;
	c = str[0];
	str.erase(str.begin());
	str += c;
	return str;
}

string c_e(string str)
{
	string a;
	int l = str.length();
	a = str.substr(0, l / 2);
	if( l % 2 == 1){
		char c = str[l / 2];
		str.erase(str.begin(), str.begin() + (l / 2) + 1);
		str += c;
		str += a;
	} else {
		str.erase(str.begin(), str.begin() + (l / 2));
		str += a;
	}
	return str;
}

string c_a(string str)
{
	reverse(str.begin(), str.end());
	return str;
}

string c_p(string str)
{
	for(int i = 0; i < str.length(); i++){
		if(isdigit(str[i])){
			int n = str[i] - '0';
			n--;
			if(n == -1) n = 9;
			str[i] = n + '0';
		}
	}
	return str;
}

string c_m(string str)
{
	for(int i = 0; i < str.length(); i++){
		if(isdigit(str[i])){
			int n = str[i] - '0';
			n = (n + 1) % 10;
			str[i] = n + '0';
		}
	}
	return str;
}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    cout << (x - z) / (y + z) << endl;
    return 0;
}


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

#define segtree_mem_max (17*10000*5)
#define segtree_max (1<<17) /* 131072 */

struct segtree_t {
	int max_num,push_num;
	int left,right;
};

struct segtree_t segtree[segtree_mem_max];
int segtree_buffer_num=1;

int segtree_makenode(void) {
	if(segtree_buffer_num>=segtree_mem_max)exit(1);
	segtree[segtree_buffer_num].max_num=0;
	segtree[segtree_buffer_num].push_num=0;
	segtree[segtree_buffer_num].left=-1;
	segtree[segtree_buffer_num].right=-1;
	return segtree_buffer_num++;
}

void segtree_push(int youso,int kstart,int kend) {
	if(kend-kstart>1) {
		if(segtree[youso].left<0)segtree[youso].left=segtree_makenode();
		if(segtree[youso].right<0)segtree[youso].right=segtree_makenode();
		segtree[segtree[youso].left].push_num+=segtree[youso].push_num;
		segtree[segtree[youso].right].push_num+=segtree[youso].push_num;
	}
	segtree[youso].max_num+=segtree[youso].push_num;
	segtree[youso].push_num=0;
}

void segtree_add_internal(
		int youso,int add,int start,int end,int kstart,int kend) {
	segtree_push(youso,kstart,kend);
	if(end<=kstart || kend<=start)return;
	if(start<=kstart && kend<=end) {
		segtree[youso].push_num+=add;
		segtree_push(youso,kstart,kend);
	} else {
		if(segtree[youso].left<0)segtree[youso].left=segtree_makenode();
		segtree_add_internal(segtree[youso].left,add,start,end,
			kstart,kstart+(kend-kstart)/2);
		if(segtree[youso].right<0)segtree[youso].right=segtree_makenode();
		segtree_add_internal(segtree[youso].right,add,start,end,
			kstart+(kend-kstart)/2,kend);
		segtree[youso].max_num=segtree[segtree[youso].left].max_num;
		if(segtree[youso].max_num<segtree[segtree[youso].right].max_num) {
			segtree[youso].max_num=segtree[segtree[youso].right].max_num;
		}
	}
}

int segtree_getmax_internal(
		int youso,int start,int end,int kstart,int kend) {
	int r1,r2;
	segtree_push(youso,kstart,kend);
	if(end<=kstart || kend<=start)return 0;
	if(start<=kstart && kend<=end) {
		return segtree[youso].max_num;
	} else {
		if(segtree[youso].left<0)segtree[youso].left=segtree_makenode();
		r1=segtree_getmax_internal(segtree[youso].left,start,end,
			kstart,kstart+(kend-kstart)/2);
		if(segtree[youso].right<0)segtree[youso].right=segtree_makenode();
		r2=segtree_getmax_internal(segtree[youso].right,start,end,
			kstart+(kend-kstart)/2,kend);
		if(r1>r2)return r1; else return r2;
	}
}

void segtree_init(void) {
	segtree_buffer_num=0;
	segtree_makenode();
}
 
void segtree_add(int start,int end,int add) {
	segtree_add_internal(0,add,start,end,0,segtree_max);
}
 
int segtree_getmax(int start,int end) {
	return segtree_getmax_internal(0,start,end,0,segtree_max);
}

int main(void) {
	int n;
	int h1,m1,s1,h2,m2,s2;
	int i;
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		segtree_init();
		for(i=0;i<n;i++) {
			scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
			segtree_add(h1*3600+m1*60+s1,h2*3600+m2*60+s2,1);
		}
		printf("%d\n",segtree_getmax(0,24*3600));
	}
	return 0;
}

Measured memory_bytes: 2296
// Kevin Mathew T
// Birla Institute of Technology, Mesra
// LinkedIn - https://www.linkedin.com/in/KevinMathewT/
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define F first
#define S second
#define fi(a, b) for(ll i=(a);i<=b;i++)
#define fj(a, b) for(ll j=(a);j<=b;j++)
#define fid(a, b) for(ll i=(a);i>=b;i--)
#define fjd(a, b) for(ll j=(a);j>=b;j--)

// #include <ext/pb_ds/assoc_container.hpp> // Common file 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> // for less 
// #include <iostream> 
// using namespace __gnu_pbds; 
// using namespace std; 
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) : Value at kth index in sorted array. 
// order_of_key(k) : Index of the value k.

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    os << "]";
	return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, unordered_map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}


const ll N = 4010, M = 1e9 + 7;
ll n;
string s;
vector<ll> p;

void solve(){
	cin >> n;
	cin >> s;

	ll tot = 0;

	fi(0, n - 1) if(s[i] == 'B') p.push_back(i);
	sort(p.begin(), p.end());

	// cout << p << "\n";

	fi(0, n - 1) 
		if(s[i] == 'R')
			fj(0, n - 1) 
				if(s[j] == 'G') {
					tot += p.size();
					auto ptr = lower_bound(p.begin(), p.end(), min(i, j) - abs(j - i));
					if(ptr != p.end() && *ptr == (min(i, j) - abs(j - i))) tot--;

					ptr = lower_bound(p.begin(), p.end(), max(i, j) + abs(j - i));
					if(ptr != p.end() && *ptr == (max(i, j) + abs(j - i))) tot--;

					if((j - i) % 2 == 0) {
						ptr = lower_bound(p.begin(), p.end(), (i + j) / 2);
						if(ptr != p.end() && *ptr == ((i + j) / 2)) tot--;
					}

				}

	cout << tot << "\n";
}

int main(){
	// freopen("input.txt", "r", stdin);		//Comment
	// freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	// ll T;
	// cin >> T;
	// while(T--)
		solve();

	return 0;
}

Measured memory_bytes: 3660
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 100000
struct node {
	int value, add;
}A[MAXN + 5];
int Ans = 0;
bool cmp(node a, node b) {
	return a.value < b.value;
}
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		A[i].add = i;
		A[i].value = x;
	}
	sort(A + 1, A + n + 1, cmp);
	for (int i = 1; i <= n; i++)
		Ans += abs(A[i].add - i) % 2;
	printf("%d", Ans / 2);
	//getchar(); getchar(); getchar();
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
using namespace std;

int main(){
    int h;
    cin >> h;
    int a[h];
    REP(i,h){
        cin >> a[i];
    }
    FOR(i,1,h+1){
        cout << "node " << i << ": ";
        cout << "key = " << a[i-1] << ", ";
        if(i/2){
            cout << "parent key = " << a[i/2-1] << ", ";
        }
        if(2*i <= h){
            cout << "left key = " << a[2*i-1] << ", ";
        }
        if(2*i+1 <= h){
            cout << "right key = " << a[2*i] << ", ";
        }
        cout << endl;
    }
  return 0;
}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// AtCoder Beginner Contest 144
typedef long long ll;
const double pi = 3.14159265358979;

int main(){

    double a, b, x;
    cin >> a >> b >> x;

    if(x >= a * a * b / 2){
        x = a * a * b - x;
        x = (x * 2) / (a * a);
        cout << atan2(x, a) / pi * 180 << '\n';
    } else {
        x = (x * 2) / (a * b);
        cout << 90 - atan2(x, b) / pi * 180 << '\n';
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;



int main() {
int N;
cin>>N;
ll A[N],sum[N],count=0;
rep(i,N){
    cin>>A[i];
}

sum[0]=A[0];
map<ll,int> seen;
seen[0]++;
seen[A[0]]++;
if(A[0]==0){
    count++;
}
rep3(i,N-1){
    sum[i]=sum[i-1]+A[i];
    if(seen[sum[i]]!=0){
        count+=seen[sum[i]];
    }
    seen[sum[i]]++;
}
cout<<count<<endl;

return 0;
}




Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    int n,k;
    cin>>n>>k;
    vector<int> arr(n,0),dp(k+1,0);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    for(int i=1;i<=k;i++)
    {
        bool win=0;
        for(int j=0;j<n;j++)
        {
            if(i-arr[j]>=0)
            {
                if(dp[i-arr[j]]==0)
                { win=1;break;}
            }
        }
        if(win)dp[i]=1;
        else dp[i]=0;
    }

    // for(int i:dp)
    //  cout<<i<<"||";

    if(dp[k]==1)
     cout<<"First";
    else
     cout<<"Second"; 
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
char c;
int main() {
    cin >> c;
    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    }else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e5 + 10, Mod = 1e9 + 7;
inline int Power(int a, int b)
{
    int ret = 1;
    for (; b; b >>= 1, a = (ll)a * a % Mod)
        if (b & 1) ret = (ll)ret * a % Mod;
    return (ret);
}
int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);

    ll cn = 1;
    for (int i = 1; i <= k; i++)
        cn = cn * i % Mod;
    cn = Power(cn, Mod - 2);
    cn = cn * k % Mod * (k - 1) % Mod;
    for (int i = n * m - k + 1; i <= n * m - 2; i++)
        cn = cn * i % Mod;
    ll tot = 0;
    for (int i = 1; i < n; i++)
        tot = (tot + (ll)(n - i) * m % Mod * m % Mod * i) % Mod;
    for (int i = 1; i < m; i++)
        tot = (tot + (ll)(m - i) * n % Mod * n % Mod * i) % Mod;
    tot = tot * cn % Mod;
    printf("%lld\n", tot);
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: i64 = read();
    let k: i64 = read();
    println!("{}", min((n % k).abs(), (k - (n % k)).abs()));
}


Measured memory_bytes: 4476
import sys
import fractions
N, M = map(int, input().split())
S = input()
T = input()

g = fractions.gcd(N, M)
L = N * M // g

ss = L // N
ts = L // M
for i in range(N):
  if (i * ss) % ts == 0:
    j = (i * ss) // ts
    if S[i] != T[j]:
      print(-1)
      sys.exit()

for i in range(M):
  if (i * ts) % ss == 0:
    j = (i * ts) // ss
    if T[i] != S[j]:
      print(-1)
      sys.exit()

print(L)

Measured memory_bytes: 5432
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int n, m, ans = 999999, w[55], b[55], r[55];
string k;
int main() {
	int i, j;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		w[i] = w[i - 1];
		b[i] = b[i - 1];
		r[i] = r[i - 1];
		cin >> k;
		for (j = 0; j < m; j++) {
			if (k[j] != 'W') w[i]++;
			if (k[j] != 'B') b[i]++;
			if (k[j] != 'R') r[i]++;
		}
	}
	for (i = 1; i <= n - 2; i++) for (j = i + 1; j <= n - 1; j++) {
		ans = min(ans, w[i] + b[j] - b[i] + r[n] - r[j]);
	}
	cout << ans << endl;
}



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

int main(){
	int n;
	cin >> n;
	vector<int> alp(26);
	string S;
	cin >> S;
	for (char c : S) alp[c-'a']++;
	rep(i,n-1) {
		cin >> S;
		vector<int> tmp(26);
		for (char c : S) tmp[c-'a']++;
		rep(j,26) alp[j] = min(alp[j],tmp[j]);
	}

	rep(i, 26) {
		rep(j,alp[i]) {
			cout << (char)(i+'a');
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;
  cin>>N>>M;
  vector<ll> A(N);
  cin>>A;
  ll ans=0;
  set<ll> S;
  vector<ll> cnt2(M,0),cnt1(M,0);
  for(auto &I:A){
    if(S.count(I)){cnt2[I%M]++; ans++; S.erase(I);}
    else{S.insert(I);}
  }
  for(auto &I:S){cnt1[I%M]++;}
  for(int i=1;2*i<M;i++){
    ll dif=0;
    for(int j=0;j<=min(cnt1[i],cnt1[M-i]);j++){
      ll k=j;
      k+=min((cnt1[i]-j)/2,cnt2[M-i]);
      k+=min((cnt1[M-i]-j)/2,cnt2[i]);
      dif=max(dif,k);
    }
    ans+=dif;
  }
  ans+=cnt1[0]/2;
  if(M%2==0){ans+=cnt1[M/2]/2;}
  cout<<ans<<endl;
  
  


  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
long long int check(long long int a)
{
    if(a%4==1) return 1;
    else if(a%4==2) return a+1;
    else if(a%4==3 || a==0) return 0;
    else return a;
}
int main()
{
    long long int a,b;
    scanf("%lld%lld",&a,&b);
    if(a==0 ) cout<<check(b)<<endl;
    else cout<<((check(a-1))^(check(b)))<<endl;
}


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

#define N 100005

using namespace std;

int n,m,a,b;

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	cin>>n;
}
 
int main(){
	init();
	int a,dig=0;
	a=n;
	while(n>0){
		dig+=n%10;
		n/=10;
	}
	if(a%dig==0)
	puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;

/*string toLower( string s ) {
    for( int i = 0; i < s.length(); ++i ) {
        if( s[i] >= 'A' && s[i] <= 'Z' ) s[i] += 32;
    }
    return s;
}*/

int main( void ) {
    int n;
    string a, b;
    cin >> n;
    int hanako = 0, tarou= 0;
    for( int i = 0; i < n; ++i ) {
        cin >> a >> b;
        if( a == b ) tarou++, hanako++;
        else if( a > b ) tarou += 3;
        else hanako += 3;
    }
    cout << tarou << ' ' << hanako << '\n';
    return 0;
}



Measured memory_bytes: 3152
void main()
{
    long x = rdElem;

    long limit = 200000;
    auto sieve = new Prime(limit);
    foreach (i; x .. limit)
    {
        if (sieve.isPrime(i))
        {
            i.writeln;
            return;
        }
    }
}

struct Prime
{
    bool[] flags;

    this(long limit)
    {
        flags = makeSieve(limit);
    }

    bool[] makeSieve(long limit)
    {
        long len = (limit - 1) / 2;
        bool[] result = new bool[len];
        result[] = true;
        foreach (i; 0 .. len)
        {
            if (!result[i]) continue;

            long prime = 3 + 2 * i;
            foreach (j; iota(prime+i, len, prime))
            {
                result[j] = false;
            }
        }
        return result;
    }

    bool isPrime(long number)
    in
    {
        assert((number - 1) / 2 <= flags.length);
    }
    body
    {
        if (number < 2)
            return false;
        else if (number == 2)
            return true;
        else if (number % 2 == 0)
            return false;
        else
            return flags[(number-3)/2];
    }
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 2300
#include"bits/stdc++.h"
using namespace std;
#define     uniq(x)         sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end())
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)

using ll = long long int;


int main()
{
    fast;
    int a,b,c;cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    ll n;
    cin>>n;
    auto d=divisor(n);
    int ans=0;
    //map<ll,int> dd;//判定済み
    
    for (ll x:d){
        if (x==1){
            continue;
        }
        else{
            ll num=x;
            while (num<=n){
                //dd[num]=1;
                if (n%num!=0){
                    break;
                }
                else{
                    if ((n/num)%x==1){
                        ans+=1;
                        break;
                    }
                    num*=x;
                    }
                }
            }

        }
    

    auto d2=divisor(n-1);
    ans+=d2.size()-1;
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, f, r;
    while (cin >> m >> f >> r && (m != -1 || f != -1 || r != -1)) {
        if (m == -1 || f == -1)
            cout << 'F' << "\n";
        else if (m + f >= 80)
            cout << 'A' << "\n";
        else if (m + f >= 65)
            cout << 'B' << "\n";
        else if (m + f >= 50)
            cout << 'C' << "\n";
        else if (m + f >= 30 && r >= 50)
            cout << 'C' << "\n";
        else if (m + f >= 30)
            cout << 'D' << "\n";
        else
            cout << 'F' << "\n";
    }
}

Measured memory_bytes: 3100
#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 chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

vector<vector<int>> dp; // dp[v][i] := vを親として、vのi番目の頂点を部分木の親とするときの答え
vector<int> P; // P[v] := vの親が何番目か。
vector<ll> ans; 
int M;

ll dfs(int v, int p, vector<vector<int>> &G) {
    ll ret = 1;
    dp[v].resize(G[v].size());
    for(int i = 0; i < G[v].size(); i++) {
        if (G[v][i] == p) {
            P[v] = i;
            continue;
        }
        dp[v][i] = dfs(G[v][i], v, G);
        ret *= dp[v][i] + 1;
        ret %= M;
    }
    return ret;
}

void dfs2(int v, int p, ll r, vector<vector<int>> &G) {
    if (p != -1) {
        dp[v][P[v]] = r;
    }
    int N = G[v].size();
    vector<ll> dpl(N + 1), dpr(N + 1);
    dpl[0] = 1, dpr[N] = 1;
    for(int i = 0; i < N; i++) {
        dpl[i + 1] = dpl[i] * (dp[v][i] + 1) % M;
    }
    for(int i = N; i > 0; i--) {
        dpr[i - 1] = dpr[i] * (dp[v][i - 1] + 1) % M;
    }
    ans[v] = dpr[0];
    for(int i = 0; i < N; i++) {
        if (G[v][i] == p) continue;
        dfs2(G[v][i], v, dpl[i] * dpr[i + 1] % M, G);
    }
}

void solve() {
    int N;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dp.resize(N);
    P.resize(N);
    ans.resize(N);
    dfs(0, -1, G);
    dfs2(0, -1, 0, G);
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();

    #ifdef LOCAL_ENV
    assert(cin.rdstate() & ios_base::eofbit);
    #endif
}

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

long long gcd(long long a, long long b){
    long long c;
    while(a!=0){
        c = a;
        a = b%a;
        b = c;
    }
    return b;
}

long long lcm(long long a, long long b){
    return max(a,b)/gcd(a,b)*min(a,b);
}

int main(){
    int N;
    long long x;
    cin >> N;
    vector<long long> T(N);
    for(int i=0;i<N;++i){
        cin >> T[i];
    }
    x = T[0];
    for(int i=1;i<N;++i){
        if(max(x,T[i])%min(x,T[i]) == 0) x = max(x,T[i]);
        else x = lcm(x, T[i]);
    }
    cout << x << endl;
}


Measured memory_bytes: 256
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair

const ll N = 1e5 + 10;
ll n;
ll h[N];
ll dp[N];

ll go(ll i)
{
	if(i == 1)
		return 0;
	if(i == 2)
		return abs(h[i] - h[i-1]);

	ll &ans = dp[i];
	if(ans != -1)
		return ans;

	ans = min(go(i-1) + abs(h[i] - h[i-1]) , go(i-2) + abs(h[i] - h[i-2]));

	return ans;
}
signed main()
{
	fast;
	memset(dp , -1 , sizeof dp);
////////////////////////////////////////////////////////////////////////////////////////////

	cin >> n;
	rep(i,1,n+1)
	{
		cin >> h[i];
	}
	cout<<go(n)<<endl;






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

	
	return 0;
}


Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod

f = Factorial(N, mod)
revs = [0] * (N + 1)
for i in range(N): revs[i + 1] = (revs[i] + pow(i + 1, mod - 2, mod)) % mod
dp = [0] * N
for i in range(N):
  l = i + 1
  r = N - i
  dp[i] = f.factorial(N) * (revs[l] + revs[r] - revs[1]) % mod * a[i] % mod
res = 0
for i in range(N):
  res += dp[i]
  res %= mod
print(res)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
 
const ll MOD = 1000000007;

int main() {
   int n, m; scanf("%d%d", &n, &m);
   vector<vector<int>> g(n + 1);
   set<pi> used;
   for (int i = 0; i < m; i++) {
      int a, b; scanf("%d%d", &a, &b);
      if (used.find({a, b}) == used.end()) {
         g[a].pb(b);
         g[b].pb(a);
         used.insert({a, b});
         used.insert({b, a});
      }
   }
   vector<int> visited(n + 1);
   vector<int> cmp;
   queue<int> q;
   int curCmp = 0;
   int cur = 1;
   while (true) {
      while (cur < n + 1 && visited[cur])
         cur++;
      if (cur == n + 1) break;
      q.push(cur);
      visited[cur] = true;
      cmp.pb(0);
      cmp[curCmp]++;
      while (!q.empty()) {
         int temp = q.front();
         q.pop();
         for (int i : g[temp]) {
            if (!visited[i]) {
               q.push(i);
               visited[i] = true;
               cmp[curCmp]++;
            }
         }
      }
      curCmp++;
   }
   printf("%d", *max_element(all(cmp)));
   return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int N, M;
vector<vector<int>> adj;
vector<bool> vis;

int dfs(int v) {
    if (vis[v]) return 0;
    vis[v] = true;
    int ret = 1;
    for (int u : adj[v]) ret += dfs(u);
    return ret;
}

int main() {
    cin >> N >> M;
    adj.assign(N, vector<int>());
    for_(i,0,M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int ans = 0;
    vis.assign(N, false);
    for_(v,0,N) if (!vis[v]) ans = max(ans, dfs(v));
    cout << ans << endl;
}

Measured memory_bytes: 20208
import collections
import math
from operator import mul
from functools import reduce
N,M = list(map(int,input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

c = collections.Counter(prime_factorize(M))
primeFactorizeList = list(c.values())
answer = 1
for i in primeFactorizeList:
    answer *= combinations_count(i+N-1, i)
    answer = answer % (10 ** 9 + 7)
print(int(answer))


Measured memory_bytes: 9640
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<ll> num;
    num.push_back(2);
    num.push_back(1);
    ll ans = 3;
    for (int i = 2; i <= n; ++i) {
        ans = num[i-1] + num[i-2];
        num.push_back(ans);
        //cout << i << " " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

string S;

int main(){
    cin>>S;

    int ans=0;
    rep(i,4){
        if(S[i]=='+') ans++;
        else ans--;
    }

    cout<<ans<<endl;
}

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

int main(){
	string snt;
	getline(cin, snt);
	for( int i=0;i<snt.length();i++ ){
		if( snt[i] >= 'a' && snt[i] <= 'z' )
			snt[i] -= 32;
	}
	

	cout << snt << endl;

	return 0;
}

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

char s[99]="abcdefghijklmnopqrstuvwxyz.?! ############################";
int main(){
	string t;
	while(cin>>t){
		int f = 1;
		string ans;
		for(int i=0;i<t.size();i+=2){
			if(t[i] < '1' || '6' < t[i] || t[i+1] < '1' || '5' < t[i+1]){
				f = 0; break;
			}
			ans.push_back(s[(t[i]-'1')*5+t[i+1]-'1']);
		}
		if(!f) cout << "NA" << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;

typedef long long int ll;
typedef pair<ll,ll> pp;
typedef long double ld;
typedef vector<pp> vpl;
//typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 100005;
const ll mod = 1000000007;
const long long int inf = 1e9;

#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);





int main(){
	ld r;
	cin>>r;
	decimal(10);
	cout<<2*r*pi<<endl;




		



		
	

		
}
	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	while(1){
		int n,m,c,s,g;
		cin >> n >> m >> c >> s >> g;
		if(n==0) break;
		
		vector<vector<vector<int> > > adj(c, vector<vector<int> >(n, vector<int>(n, inf)));
		for(int i=0; i<m; i++){
			int x,y,d,c;
			cin >> x >> y >> d >> c;
			x--; y--; c--;
			if(adj[c][x][y] > d){
				adj[c][x][y] = adj[c][y][x] = d;
			}
		}
		vector<int> p(c);
		for(int i=0; i<c; i++){
			cin >> p[i];
		}
		vector<vector<int> > q(c), r(c), fq(c);
		for(int i=0; i<c; i++){
			q[i].resize(p[i]+1);
			r[i].resize(p[i]);
			fq[i].resize(p[i]);
			q[i][0] = 0;
			q[i][p[i]] = inf;
			for(int j=1; j<p[i]; j++){
				cin >> q[i][j];
			}
			for(int j=0; j<p[i]; j++){
				cin >> r[i][j];
			}
			fq[i][0] = 0;
			for(int j=1; j<p[i]; j++){
				fq[i][j] = fq[i][j-1] +(q[i][j]-q[i][j-1])*r[i][j-1];
			}
		}
		
		for(int d=0; d<c; d++){
			for(int k=0; k<n; k++){
				for(int i=0; i<n; i++){
					for(int j=0; j<n; j++){
						adj[d][i][j] = min(adj[d][i][j], adj[d][i][k]+adj[d][k][j]);
					}
				}
			}
			for(int i=0; i<n; i++){
				for(int j=i; j<n; j++){
					if(adj[d][i][j] == inf) continue;
					int idx=0;
					while(q[d][idx+1] < adj[d][i][j]) idx++;
					adj[d][i][j] = adj[d][j][i] = fq[d][idx] +(adj[d][i][j]-q[d][idx])*r[d][idx];
				}
			}
		}
		
		for(int i=0; i<n; i++){
			for(int j=i; j<n; j++){
				for(int d=1; d<c; d++){
					adj[0][i][j] = adj[0][j][i] = min(adj[0][i][j], adj[d][i][j]);
				}
			}
		}
		for(int k=0; k<n; k++){
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					adj[0][i][j] = min(adj[0][i][j], adj[0][i][k]+adj[0][k][j]);
				}
			}
		}
		
		if(adj[0][s-1][g-1] == inf){
			cout << -1 << endl;
		}else{
			cout << adj[0][s-1][g-1] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	vector<int> dp(1000000, INT_MAX / 2);
	dp[0] = 0;
	vector<int> _dp = dp;
	for (int i = 1; i <= 200; i++) {
		int x = i * (i + 1) * (i + 2) / 6;
		for (int j = x; j < 1000000; j++)
			dp[j] = min(dp[j], dp[j - x] + 1);
		if (x % 2 == 1)
			for (int j = x; j < 1000000; j++)
				_dp[j] = min(_dp[j], _dp[j - x] + 1);
	}
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		cout << dp[n] << ' ' << _dp[n] << endl;
	}
}

Measured memory_bytes: 8856
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int a,b;
  cin >> a >> b;
  
  cout << b*2 - a << endl;

 return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  double dp[1<<n][m], prob[n][m];
  for(int i = 0; i < (1<<n); ++i){
    fill(dp[i],dp[i]+m,0);
  }
  //fill(dp[0],dp[0]+m,0);//テァツ個ォテ」ツ?古・ツ?ィテ」ツ?ヲテ・ツ?津」ツつ古」ツ?ヲテ」ツつ凝」ツ?ョテ」ツ?ァ0

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      cin >> prob[i][j];
    }
  }
  
  for(int bit = 0; bit < (1<<n); ++bit){
    for(int i = 0; i < m; ++i){
      for(int j = 0; j < n; ++j){
	if(bit>>j & 1){
	  double t = 0, p = 1.0;
	  for(int k = i; k < m; ++k){
	    t += p*(1.0 - prob[j][k])*dp[bit-(1<<j)][k];
	    p *= prob[j][k];
	  }
	  t += p;
	  dp[bit][i] = max(dp[bit][i],t);
	}
      }
    }
  }

  double ans = dp[(1<<n)-1][0];
  printf("%.12f\n",ans);
  return 0;
}

Measured memory_bytes: 11440
#include<cmath>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
using i64=long long;
char str[10000000];
int read(){int x=0,c=getchar(),f=1;while(isspace(c))c=getchar();if(c=='-')f=-1,c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return f*x;}
int main()
{
    int k;scanf("%d%s",&k,str+1);
    int n=strlen(str+1);
    if(n>k)
    {
	str[k+1]=str[k+2]=str[k+3]='.',str[k+4]=0;
    }
    puts(str+1);
}


Measured memory_bytes: 3764
#include <cstdio>

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

using namespace std;

int main(){
	int a,b;
	char c; scanf("%d %c%d",&a,&c,&b);
	printf("%d\n",c=='+'?a+b:a-b);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;

	if (A + B > A - B) {
		if (A + B > A * B) {
			cout << A + B << endl;
		}
		else cout << A * B << endl;
	}
	else if (A - B > A * B) {
		cout << A - B << endl;
	}
  else cout << A * B << endl;
}

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

int main() {
	int N, K;
	string S;

	cin >> N >> S >> K;

	char m = S[K - 1];
	for( int i = 0; i < N; i++ ) {
		if( S[i] != m ) {
			S[i] = '*';
		}
	}

	cout << S << endl;

	return 0;
}


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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	string s, t; cin >> s >> t;
	rep(i,0,s.size()){
		if (s[i] != t[i]){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,a6,b6,a7,b7,n1,n2,n3,n4,n5,n6,n7;
	cin>>a1>>b1>>a2>>b2>>a3>>b3>>a4>>b4>>a5>>b5>>a6>>b6>>a7>>b7;
	n1=a1-b1;
	n2=a2-b2;
	n3=a3-b3;
	n4=a4-b4;
	n5=a5-b5;
	n6=a6-b6;
	n7=a7-b7;
	cout<<n1<<endl;
	cout<<n2<<endl;
	cout<<n3<<endl;
	cout<<n4<<endl;
	cout<<n5<<endl;
	cout<<n6<<endl;
	cout<<n7<<endl;
	
	return 0;
}



Measured memory_bytes: 3088
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    S = list(map(int, S))
    N = len(S)

    ans = 0
    for bit in range(1 << (N - 1)):
        n = 0
        for i, s in enumerate(S):
            n += s
            if bit & (1 << i):
                ans += n
                n = 0
            else:
                n *= 10
        ans += n // 10

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9488