akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define invrep(i,n) for(int i = (int)(n); i > 0; i++)
using ll = long long;

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

    if (n.size() > k) {
        string ans = "";
        rep (i, n.size()) {
            if (i < k) ans += n[i];
            else {
                ans += "...";
                break;
            }
        }

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

    cout << n << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    int ans = 0;
    for (int i = 0; i < 30; ++i) {
        ll t = 1 << i;
        for (int j = 0; j < n; ++j) {
            c[j] = a[j] % (t << 1);
            d[j] = b[j] % (t << 1);
        }
        sort(d.begin(), d.end());
        int s = 0;
        for (int j = 0; j < n; ++j) {
            int left = lower_bound(d.begin(), d.end(), t - c[j]) - d.begin();
            int right = lower_bound(d.begin(), d.end(), 2 * t - c[j]) - d.begin();
            s += (right - left) % 2;
            left = lower_bound(d.begin(), d.end(), 3 * t - c[j]) - d.begin();
            right = lower_bound(d.begin(), d.end(), 4 * t - c[j]) - d.begin();
            s += (right - left) % 2;
        }
        if (s % 2) {
            ans += t;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
#define vec2 vector<vector<int>>
#define set setprecision
#define mod 1000000007
#define pi 3.14159265
#include<numeric>
using namespace std;
int gcd(int a, int b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {	ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);}
int main() {
	int n;
	cin >> n;
	vec a(n);
	rip(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	int count = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++)if (a[i] + a[j] > a[k])count++;
		}
	}
	cout << count << endl;
}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tp=0, hp=0;
	string t, h;
	int n;
	cin>>n;
	for(int i=0; i<n; ++i) {
		cin>>t>>h;
		if(t==h) {
			++tp;
			++hp;
		} else if(t>h) {
			tp+=3;
		} else if(t<h){
			hp+=3;
		}
	}
	cout<<tp<<' '<<hp<<'\n';
	return 0;
}



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

int main(){
  long long N;
  cin >> N;
  
  if(N % 2) {
   	cout << 0 << endl;
    return 0;
  }
  
  long long d = 10;
  long long ans = N / d;
  N /= d;
 
  while(N){
    ans += N / 5;
    N /= 5;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int h,n;
	cin>>h>>n;
	
	vi a(n),b(n);
	REP(i,n) cin>>a[i]>>b[i];
	
	vi dp(h+1,INF);
	dp[h]=0;
	for(int i=h;i>0;--i){
		if(dp[i]==INF){}
		else{
			REP(j,n){
				if(i-a[j]<0) dp[0]=min(dp[0],dp[i]+b[j]);
				else dp[i-a[j]]=min(dp[i-a[j]],dp[i]+b[j]);
			}
		}
	}
	
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define INF (int)1e9+1
#define INFLL (int)1e18+1
#define sz(bb) (int)bb.size()
#define all(qq) qq.begin(), qq.end() 
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
const double PI=acos(-1);
// #define int unsigned long long int//used when x<=2^64-1 && x>0
#define int long long//used when x<=2^63-1
//bool cmp if returns true it keeps 1st as first else swaps
typedef long long  ll;

vector<int> gr[100001];
int dp[100001];
void fun(int x)
{
    if(dp[x]!=-1)
        return;
    int cur=0;
    for(auto it: gr[x])
    {
        fun(it);
        cur=max(cur, dp[it]);
    }
    dp[x]=1+cur;
}
void solve()
{
    int n, m;
    cin>>n>>m;
    while(m--)
    {
        int a, b;
        cin>>a>>b;
        a--; b--;
        gr[a].pb(b);
    }
    for(int i=0;i<n;i++)
        dp[i]=-1;
    for(int i=0;i<n;i++)
    {
        if(dp[i]==-1)
            fun(i);
    }
    int mx=dp[0];
    for(int i=0;i<n;i++)
    {
        mx=max(mx, dp[i]);
    }
    cout<<mx-1<<"\n";
}
int32_t main()
{
    IOS;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 12592
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    int n;
    cin >> n;
    if (n == 1 || (n & (n - 1)) == 0) {
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    for (int i = 2; i < n; i += 2) {
        cout << i << ' ' << i + 1 << '\n';
        cout << i + 1 << ' ' << 1 << '\n';
        cout << 1 << ' ' << n + i << '\n';
        cout << n + i << ' ' << n + i + 1 << '\n';
    }
    cout << n + 3 << ' ' << n + 1 << '\n';
    if (n % 2 == 0) {
        for (int i = 0; i < 17; i++) {
            if (n >> i & 1) {
                cout << n << ' ' << (1 << i) + 1 << '\n';
                cout << n + (n ^ (1 << i)) << ' ' << 2 * n << '\n';
                break;
            }
        }
    }

}


Measured memory_bytes: 2304
import sys
input = sys.stdin.buffer.readline


r, c, k = map(int, input().split())
info = [list(map(int, input().split())) for i in range(k)]
INF = 10 ** 18

item = [[0] * c for i in range(r)]
for i, j, v in info:
    i -= 1
    j -= 1
    item[i][j] = v

OFFSET = (r + 1)
dp = [[-INF] * ((c + 1) * (r + 1)) for i in range(4)]
for i in range(r + 1):
    dp[0][i] = 0
for j in range(c + 1):
    dp[0][OFFSET * j] = 0
    
for i in range(r):
    for j in range(c):
        val = item[i][j]
        tmp11 = i + 1 + OFFSET * (j + 1)
        tmp = i + 1 + OFFSET * j
        tmp01 = i + OFFSET * (j + 1)

        dp[0][tmp11] = max(dp[0][tmp], dp[0][tmp01], dp[1][tmp01], dp[2][tmp01], dp[3][tmp01])
        dp[1][tmp11] = max(dp[1][tmp], dp[0][tmp] + val,  dp[0][tmp01] + val, dp[1][tmp01] + val, dp[2][tmp01] + val, dp[3][tmp01] + val)
        dp[2][tmp11] = max(dp[2][tmp], dp[1][tmp] + val)
        dp[3][tmp11] = max(dp[3][tmp], dp[2][tmp] + val)


print(max(dp[0][(c + 1) * (r + 1) - 1], dp[1][(c + 1) * (r + 1) - 1], dp[2][(c + 1) * (r + 1) - 1], dp[3][(c + 1) * (r + 1) - 1]))
                                   


Measured memory_bytes: 445012
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int a[4][4],b[10101];
bool f[4][4];
int main()
{
	int n;
	int i,j;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	cin>>n;
	int k;
	for(i=0;i<n;i++){
		cin>>b[i];
	}
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			for(k=0;k<n;k++){
				if(b[k]==a[i][j]){
					f[i][j]=1;
				}
			}
		}
	}
	if(f[0][0]&&f[0][1]&&f[0][2]||f[1][0]&&f[1][1]&&f[1][2]||f[2][0]&&f[2][1]&&f[2][2]||f[0][0]&&f[1][0]&&f[2][0]||f[0][1]&&f[1][1]&&f[2][1]||f[0][2]&&f[1][2]&&f[2][2]||f[0][0]&&f[1][1]&&f[2][2]||f[0][2]&&f[1][1]&&f[2][0]){
		cout<<"Yes"<<endl;
	} 
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  
  int i,j,n[3];
  for(i = 0 ; i < 3 ; i++){
    scanf("%d",&n[i]);
  }
  
  for(i = 0 ; i < 3 ; i++){
    for(j = i + 1 ; j < 3 ; j++){
      if(n[i] < n[j]){
        int tmp;
        tmp = n[i];
        n[i] = n[j];
        n[j] = tmp;
      }
    }
  }
  
  int ans = 10 * n[0] + n[1] + n[2];
  printf("%d",ans);
  
  return 0;
  
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int ll

const int M = 998244353;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e9 + 100;
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


#define N 10000

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;
	vi a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(ALL(a));


	deque <int> d;
	d.push_back(a[0]);

	int i = 1, j = n - 1;
	bool flag = true;
	while (i <= j)
	{
		if (flag)
		{
			d.push_back(a[j]);
			j--;
			if (j >= i)
				d.push_front(a[j]);
			j--;
		}
		else
		{
			d.push_back(a[i]);
			i++;
			if (j >= i)
				d.push_front(a[i]);
			i++;
		}
		flag = !flag;
	}
	
	int cur = d.front(), sum = 0;
	while (!d.empty())
	{
		sum += abs(d.front() - cur);
		cur = d.front();
		d.pop_front();
	}
	

	d.push_back(a[n - 1]);

	i = 0, j = n - 2;
	flag = false;
	while (i <= j)
	{
		if (flag)
		{
			d.push_back(a[j]);
			j--;
			if (j >= i)
				d.push_front(a[j]);
			j--;
		}
		else
		{
			d.push_back(a[i]);
			i++;
			if (j >= i)
				d.push_front(a[i]);
			i++;
		}
		flag = !flag;
	}

	cur = d.front();
	int sum2 = 0;
	while (!d.empty())
	{
		sum2 += abs(d.front() - cur);
		cur = d.front();
		d.pop_front();
	}

	cout << max(sum, sum2);

}

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

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

long long int lcm(long long int a, long long int b){
	long long int d = gcd(a,b);
	return a/d*b;
}
	

int main(){
	int n;
	cin >> n;
	vector<long long int> t(n);
	for(int i=0; i<n; i++){
		cin >> t[i];
	}
	
	long long int ans=t[0];
	for(int i=1; i<n; i++){
		ans = lcm(ans, t[i]);
	}
	cout << ans << endl;
	return 0;
}
	

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

int main() {
  ll X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  
  ll straight = min(K, X / D); // 最初に移動する回数
  K -= straight; //移動できる回数残り
  X -= straight * D; // K回移動した後の位置
  
  if( K % 2 == 0){
    cout << X << endl; // 偶数回なら位置変わらず、ちなみに原点に近づけなかったらK=0なのでこの場合に含まれている。
  }
  else{
    cout << D - X << endl; // 奇数回ならさらに動く
  }
}

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

int gcd(int p, int q){
  while(q != 0){
    int r = p % q;
    p = q;
    q = r;
  }
  return p;
}


int main() {
  int a,b,sum;
  a=1;
  b=1;
  sum=0;
  int c = gcd(a,b);
  cin >> a;
  for(int i=1;i<a+1;i++){
    for(int j=1;j<a+1;j++){
      for(int k=1;k<a+1;k++){
        sum += gcd(gcd(i,j),k);
      }
    }
  }
  printf("%d",sum);
}

Measured memory_bytes: 3764
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut tasks = vec![];
    for i in 0..n {
        let v = read_vec::<i64>();
        let (a, b) = (v[0] as usize, v[1]);
        tasks.push((a, b));
    }
    tasks.sort();
    tasks.reverse();
    let mut heap = BinaryHeap::new();
    let mut ans = 0i64;
    for i in 0..m {
        while let Some(&(a, b)) = tasks.iter().rev().next() {
            if a <= i + 1 {
                heap.push(b);
                tasks.pop();
            } else {
                break;
            }
        }
        if let Some(b) = heap.pop() {
            ans += b;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4752
import sys

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a%b)

for line in sys.stdin:
    a, b= map(int, line.split())
    if a < b:
        a, b = b, a
    g = gcd(a,b)
    print g, a*b/g

Measured memory_bytes: 6360
#include <stdio.h>


int main(void)
{
    int a, b, c, k;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &k);

        if(k <= a){
            printf("%d\n", k);
        }
        else if(k <= (a + b)){
            printf("%d\n", a);
        }
        else{
            printf("%d\n", a-(k-a-b));
        }
    return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>

#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 INF = 2e9;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> dp(n+1, -INF); // dp[i] : ちょうどi本のマッチ棒を使うときの最大桁数
    
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    
    vector<int> table2num ={-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    
    dp[0] = 0;
    for (int i = 1; i < n+1; ++i)
    {
        rep(j, m)
        {
            int idx = i - table2num[a[j]];
            if (idx < 0) continue;
            else
            {
                dp[i] = max(dp[i], dp[idx] + 1);
            }
            
        }
    }
    
    
    
    
    
    sort(a.begin(), a.end(), std::greater<int>());
    int match_idx = n;
    for (int i = dp[n]; i>0; --i)
    {
        for (int j : a)
        {
            if (match_idx - table2num[j] < 0) continue;
            if (dp[match_idx - table2num[j]] == dp[match_idx] - 1)
            {
                match_idx -= table2num[j];
                cout << j;
                break;
            }
        }
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = []
for n in range(1, N+1):
    ans = 0
    for x in range(1, int(n**(1/2))+1):
        for y in range(x, int(n**(1/2))+1):
            c = x**2 + y**2 + x*y - n
            b = x+y
            if b**2 - 4*c >= 0:
                d = (-b+(b**2-4*c)**(1/2))/2
                if int(d) == d and d >= 1:
                    if x != y:
                        ans += 2
                    else:
                        ans += 1
    print(ans)


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

using namespace std;

int main()
{
  int H, W;
  string S[8];
  cin >> H >> W;

  int ret = 0;
  for(int i = 0; i < H; i++) {
    cin >> S[i];
    for(int j = 0; j < W; j++) {
      ret += S[i][j] == '#';
    }
  }

  if(ret == H + W - 1) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }

}

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

pair<int,int> Pos[90001];

int main(){
  int H,W,D;cin>>H>>W>>D;
  vector<vector<int>>Dists(D);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int a;cin>>a;
      Pos[a] = make_pair(i,j);
    }
  }
  
  for(int i=1;i<=D;i++){
    int x = i;
    int dist = 0;
    Dists[i-1].push_back(0);
    x+=D;
	while(x <= H*W){
      dist += abs(Pos[x].first - Pos[x-D].first) + abs(Pos[x].second - Pos[x-D].second);
      Dists[i-1].push_back(dist);
      x+=D;
    }
  }
  
  int Q;cin>>Q;
  for(int i=0;i<Q;i++){
    int l,r;cin>>l>>r;
    l--;r--;
    cout<<Dists[l%D][r/D] - Dists[l%D][l/D]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 6016
#python
import sys

N = input()
a = []
for i in range(N):
	a.append(input())
#print a

if 2 not in a:
	print "-1"
	sys.exit()

i=1

while a[i-1]!=2:

	if a[i-1]==0:
		print "-1"
		sys.exit()

	#print i,a[i-1]
	before=i
	i=a[i-1]
	a[before-1]=0
	#print a
	

print a.count(0)+1


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  long maney = 1000;
  for(long i = 0; i < N-1; i++){
    if(A.at(i+1) > A.at(i)){
      long tmp = maney;
      maney = maney % A.at(i);
      maney = maney + A.at(i+1) * (tmp / A.at(i));
    }
  }
  cout << maney << endl;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()

int main() {
	set<int> A, B;
	int n;
	cin >> n;
	Rep(i, n) {
		int a;
		cin >> a;
		A.insert(a);
	}
	int m;
	cin >> m;
	Rep(i, m) {
		int b;
		cin >> b;
		B.insert(b);
	}
	set<int> res;
	set_intersection(All(A), All(B), inserter(res, res.end()));
	for (auto v : res) {
		cout << v << endl;
	}
	return 0;
}


Measured memory_bytes: 23720
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
    int a,b;
    cin >> a >> b;
    if (a <= 9 && b <= 9) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int N, M;
	cin >> N >> M;
	vector<pair<int, bool>> V(N, mpair(1, false));
	V[0].second = true;
	int x, y;
	for(int i = 0; i < M; i++){
		cin >> x >> y;
		x--;
		y--;
		if(V[x].second){
			V[y].second = true;
		}
		V[x].first--;
		V[y].first++;
		if(V[x].first == 0){
			V[x].second = false;
		}
	}
	int ans = 0;
	for(int i = 0; i < N; i++){
		if(V[i].second)ans++;
	}
	cout << ans << endl;

	return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define All(v) (v).begin(), (v).end()
#define Pb(i) push_back(i)

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

    ll a,b,c; Cin3(a,b,c);
    if(a+b==c || a+c==b || b+c==a) Cout("Yes");
    else Cout("No");
    return 0;
}

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

string S;
int K;

int main()
{
    cin >> S >> K;
    int L = S.size();
    vector<vector<vector<int> > > dp(L, vector<vector<int> >(L, vector<int>(K+1, 1)));

    // 1文字 dp[i][i][k]は全部1
    
    // 2文字 dp[i][i+1][k]埋め
    for (int i=0; i<L-1; i++)
    {
        dp[i][i+1] = vector<int>(K+1, 2);
        if (S[i] != S[i+1]) dp[i][i+1][0] = 1;
    }
    for (int l=3; l<=L; l++)
    {
        for (int i=0; i<=L-l; i++)
        {
            if (S[i] == S[i+l-1])
            {
                for (int k=0; k<=K; k++) dp[i][i+l-1][k] = dp[i+1][i+l-2][k] + 2;
            }
            else
            {
                for (int k=0; k<=K; k++)
                {
                    int tmpmax = max(dp[i][i+l-2][k], dp[i+1][i+l-1][k]);
                    if (k>0) tmpmax = max(tmpmax, dp[i+1][i+l-2][k-1]+2);
                    dp[i][i+l-1][k] = tmpmax;
                }                
            }
        }
    }
    cout << dp[0].back().back() << endl;
    return 0;
}

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

using namespace std;

int main() {

	string s;
	cin >> s;

	vector<int> a(s.size()+1,-1);

	if (s[0] == '<') { a[0] = 0; }
	if (s[s.size() - 1] == '>') { a[s.size()] = 0; }
	for (int i = 0; i < s.size()-1; i++) {

		if (s[i] == '>' && s[i + 1] == '<') {
			a[i + 1] = 0;
		}
	}

	for (int i = 0; i <= s.size(); i++) {
		if (a[i] == 0) {
			//右に行く
			int j = 0;
			while (s[i + j] == '<' && i+j+1<s.size()+1) {
				a[i + j + 1] = max(a[i+j+1],a[i + j] + 1);
				j++;
			}
			//左に行く
			j = 0;
			if (i != 0) {
				while (s[i + j - 1] == '>' && i + j  >= 0) {
					a[i + j - 1] = max(a[i + j - 1], a[i + j] + 1);
					j--;
					if (i + j == 0) { break; }
				}
			}
		}
	}

	//for (int i = 0; i <= s.size(); i++) {
	//	cout << a[i] << " ";
	//}

	cout << accumulate(a.begin(),a.end(),0LL) << endl;

	return 0;

}

Measured memory_bytes: 5864
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e,max;
	cin>>a>>b;
	c=a+b;
	d=a-b;
	e=a*b;
	max=(c>d?c:d);
	max=(max>e?max:e);
	cout<<max<<endl;
}  

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int M,K; cin >> M >> K;
    if(M == 0 || M == 1){
        if(K == 0){
            VI ans(2*(1<<M));
            REP(i,ans.size()/2){
                ans[2*i] = i;
                ans[2*i+1] = i;
            }
            REP(i,ans.size()) cout << ans[i] << " ";
            cout << endl;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    else{
        if(K >= (1<<M)){
            cout << -1 << endl;
            return 0;
        }
        VI ans;
        REP(i,1<<M){
            if(i == K) continue;
            ans.push_back(i);
        }
        ans.push_back(K);
        RREP(i,1<<M){
            if(i == K) continue;
            ans.push_back(i);
        }
        ans.push_back(K);
        REP(i,ans.size()) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main(){
  int x;cin >> x;
  if(x == 0) cout << 1 << endl;
  else cout << 0 << endl;
}


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


int main() {
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  int ans = 0;
  rep(i,k) {
    t += '0';
  }
  rep(i,k) {
    int j = i+k;
    char cur = t[i];
    int cnt = 1;
    while(j<n+k+1) {
      // cout << "i " << i << " , j " << j << " , cnt " << cnt << endl;
      if(cur == t[j]) {
        cnt ++;
      }
      else {
        int num_win = (cnt + 1) / 2 ;
        if(cur =='r') ans += num_win * p;
        if(cur =='p') ans += num_win * s;
        if(cur =='s') ans += num_win * r;
        cur = t[j];
        cnt = 1;
      }
      j += k;
    }
      // cout << "END !!! i " << i << " , j " << j << " , cnt " << cnt << endl;
      int num_win = (cnt + 1) / 2 ;
      if(cur =='r') ans += num_win * p;
      if(cur =='p') ans += num_win * s;
      if(cur =='s') ans += num_win * r;

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


Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        String s = sc.next();
        int x = 0;
        int max = 0;
        for(int i=0; i<n; i++){
            Character character = s.charAt(i);
            if(character == 'I') x++;
            else x--;
            max = Math.max(max, x);
        }
        System.out.println(max);

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i=0;i<N;i++)cin >> p[i];
  int cnt=0;
  for(int i=0;i<N;i++){
    if(p[i]!=i+1)cnt++;
  }
  if(cnt<=2)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
<?php
$S=trim(fgets(STDIN));
$P=trim(fgets(STDIN));

$Sl=strlen($S);
$Pl=strlen($P);
$S.=$S;
$F='No';
for($i=0;$i<$Sl;$i++){
  if($S[$i]!=$P[0]) continue;
  $f=1;
  for($j=1;$j<$Pl;$j++) if($S[$i+$j]!=$P[$j]){$f=0;break;}
  if($f){$F='Yes';break;}
}
echo $F;
?>

Measured memory_bytes: 15444
#include <iostream>
#define rep(i,a) for(i = 0; i < a; i++)
using namespace std;

class Card {
public:
  string suit;
  int value;
  void InputCard(string T);
};

void Card::InputCard(string T) {
  suit = T[0];
  value = T[1] - '0';
}

void print(Card card[],int n) {
  int i;
  rep(i,n){
    if(i > 0){
      cout << " ";
    }
    cout << card[i].suit << card[i].value;
  }
  cout << endl;
}

void bubblesort(Card card[],int n) {
  int i;
  rep(i,n) {
    for(int j = n-1; j > i; j--) {
      if(card[j].value < card[j-1].value) {
	swap(card[j],card[j-1]);
      }
    }
  }
}

void selectionsort(Card card[],int n) {
  int i;
  rep(i,n) {
    int minj = i;
    for(int j = i; j < n; j++) {
      if(card[j].value < card[minj].value) {
	minj = j;
      }
    }
    swap(card[i],card[minj]);
  }
}

bool isStable(Card card1[], Card card2[], int n) {
  int i;
  rep(i,n) {
    if(card1[i].suit != card2[i].suit) {
      return false;
    }
  }
  return true;
}

int main(void) {
  int i,n;
  string T;
  cin >> n;
  Card *Card1 = new Card[n];
  Card *Card2 = new Card[n];
  rep(i,n) {
    cin >> T;
    Card1[i].InputCard(T);
    Card2[i].InputCard(T);
  }

  bubblesort(Card1,n);
  selectionsort(Card2,n);

  print(Card1,n);
  cout << "Stable" << endl;
  print(Card2,n);

  if(isStable(Card1,Card2,n)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;

}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const LL MOD = 1e9+7;
const int INF = 1<<30;
int MAXN = 1e5+2;
const double eps = 1e-13;

int r,c,d,h;
char ans[1009][1009];
char col[]="RYGB";

void cen(int x,int y,int v){
	for(int i=x-h;i<=x+h;i++){
		for(int j=y-h;j<=y+h;j++){
			if(i<0||j<0||i>=r||j>=c)continue;
			int dist1=abs(i-x)+abs(j-y);
			int dist3=abs(i-x)+abs(j-y-1);
			if(min(dist1,dist3)>h)continue;
			//printf("yay");
			ans[i][j]=col[v];
		}
	}
}

int main(){
	RIII(r,c,d);
	if(d%2){
		REP(i,r){
			REP(j,c){
				ans[i][j]=col[(i+j)%4];
			}
		}
	}
	else if(d==2){
		REP(i,r){
			REP(j,c){
				ans[i][j]=col[(2*i+(i+j)/2)%4];
			}
		}
	}
	else{
		h=d/2;
		int mm=1000/max(h,1);
		for(int ix=-mm;ix<=mm;ix++){
			for(int iy=-mm;iy<=mm;iy++){
				int cx=ix*(1)+iy*(h);
				int cy=ix*(2*h-1)+iy*(-h);
				cen(cx,cy,(((ix+mm)%2))^(2*iy+mm)%4);
			}
		}
	}
	REP(i,r){
		REP(j,c){
			printf("%c",ans[i][j]);
		}puts("");
	}
}


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

T = 1
xyz = [0]*3
for Ai in A:
  if xyz.count(Ai)>0:
    T = (T * xyz.count(Ai))%1000000007
    xyz[xyz.index(Ai)] += 1
  else:
    T = 0
    break
print(T)

Measured memory_bytes: 10428
n, m = map(int, input().split())
lights = [list(map(int, input().split()))[1:] for i in range(m)]
P = list(map(int, input().split()))

res = 0
# bit列の組み合わせについて
for bit in range(1 << n):
    ok = True
    # 各電球について
    for i in range(m):
        # 電球iのonの状態のスイッチの個数
        cnt = 0
        # 電球の各スイッチについて
        for v in lights[i]:
            v -= 1
            # 電球のスイッチがvのon/off判定
            if bit & (1 << v):
                cnt += 1
        # 電球iは点灯しているか判定
        if cnt % 2 != P[i]:
            ok = False
    if ok:
        res += 1
print(res)

Measured memory_bytes: 73960
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n - 2){
        vec num;
        rep(j, 3){
            num.push_back(p[i+j]);
        }
        sort(num.begin(), num.end());
        if(num[1] == p[i+1])ans++;
    }
    cout << ans << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k;
  cin >> k;
  std::cout << 50 << std::endl;
  vector<ll> v(50);
  rep(i,50){
    v[i] = i;
    v[i] += (k / 50) ;
  }
  rep(i,k % 50){
    v[i] += 50;
    rep(j,50){
      if(i != j) v[j] -= 1;
    }
  }
  rep(i,50){
    if(i) cout << ' ';
    cout << v[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
//freopen("output.txt","w",stdout);
//freopen("input.txt","r",stdin);
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long // remove when constraints are tight.
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/
ll poww(long long a, long long n, long long m)
{
        long long ans = 1;
        long long mul = a;
        while (n != 0)
        {
                if (n % 2)
                {
                        ans = (ans * mul) % m;
                }
                mul = (mul * mul) % m;
                n /= 2;
        }
        return ans;
}
/* 
Fermat's little theorem: 
1) (a/b)%mod= (a*(poww(b,phi(mod)-1,mod)))%mod iff a%b==0
2) (a^b)%mod= (a^(b%(mod-1)))%mod iff mod is prime
3) Fermat's little theorem: 
        a^(phi(n))=1 mod(n)  when a and n are relatively prime.
*/
int32_t main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int fact[n+5];
	fact[0]=1;
	for(int i=1;i<n+5;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}	
	int f[n+5];
	for(int i=1;i<n+5;i++)
	{
		f[i]=fact[n-1]*poww(i,MOD-2,MOD);
		f[i]%=MOD;
	}
	int cum[n+5];
	cum[0]=0;
	for(int i=1;i<n+5;i++)
	{
		cum[i]=cum[i-1]+f[i];
		cum[i]%=MOD;
	}
	int ar[n+5];
	for(int i=1;i<=n;i++)
	{
		cin>>ar[i];
	}
	int ans=0;

	for(int i=2;i<=n;i++)
	{
		ans+=((ar[i]-ar[i-1])*cum[i-1])%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
}


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

int main(){
  string s; cin >> s;
  char tmp = s[0];
  int count = 0;
  for(char k : s) {
    if(tmp != k) {
      count++;
      tmp = k;
    }
  }

  cout << count << endl;
}



Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

std::vector<bool>sieve(unsigned long long n)
{
    std::vector<bool>is_prime(n+1,true);
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i*i<=n;++i){
        if(is_prime[i]){
            for(ll j=i*2;j<n+1;j+=i){
                is_prime[j]=false;
            }
        }
    }
    return is_prime;
}
int main()
{
    auto p=sieve(100003);
    ll x=in();
    for(ll i=x;;++i){
        if(p[i]){
            cout<<i<<endl;
            return 0;
        }
    }
}


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

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

#define INF (INT32_MAX/4)

int main()
{
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a( A );
	vector<int> b( B );
	vector<tuple<int, int, int>> xy;
	vector<int> cost;
	for( int i = 0; i < A; i++ ) {
		cin >> a[i];
	}
	for( int i = 0; i < B; i++ ) {
		cin >> b[i];
	}
	for( int i = 0; i < M; i++ ) {
		int x, y, c;
		cin >> x >> y >> c;
		x--;
		y--;
		xy.push_back( make_tuple( c, x, y ) );
	}
	sort( xy.begin(), xy.end(), greater<tuple<int, int, int>>() );
	for( int i = 0; i < xy.size(); i++ ) {
		int x, y, c;
		tie( c, x, y ) = xy[i];
		if( a[x] == INF || b[y] == INF ) continue;
		int cc = a[x] + b[y] - c;
		cost.push_back( cc );
		a[x] = INF;
		b[y] = INF;
	}

	sort( a.begin(), a.end() );
	sort( b.begin(), b.end() );
	sort( cost.begin(), cost.end() );
	int ans = min( a[0] + b[0], cost[0] );

	cout << ans << endl;
}


Measured memory_bytes: 2680
<?php
$n=trim(fgets(STDIN));
if($n==1){
  echo trim(fgets(STDIN));
}else{
  $a=explode(" ",trim(fgets(STDIN)));
  $p=$a[0];
  $q=1;
  $i=1;
  while($i<$n){
    (int)$c=lcm($p,$a[$i]);
    (int)$q=$c/$p*$q+$c/$a[$i];
    (int)$p=$c;
    ++$i;
  }
  printf("%f",$p/$q);
}

function gcd($a,$b) {
    return ($a % $b) ? gcd($b,$a % $b) : $b;
}
function lcm($a,$b) {
  return $a / gcd($a,$b) * $b;
}

Measured memory_bytes: 4732
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);

int n;
ll k;
vector<ll> a;
ll ret = 0;

ll mod(ll val, ll m) {
	ll res = val % m;
	if (res < 0) 
		res += m;
	return res;
}

int main(void) {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		ll ai;
		cin >> ai;
		a.push_back(ai);
	}

	for (int i = 0; i < n; i++) {
		ll ai = a[i];
		int l = 0, r = 0;
		for (int j = 0; j < i; j++) {
			if (a[j] < ai)
				l++;
		}
		for (int j = i + 1; j < n; j++) {
			if (a[j] < ai)
				r++;
		}

		ret += mod((l + r) * ((k * (k + 1) / 2) % MOD) % MOD - (l * k) % MOD, MOD);
		ret = ret % MOD;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int a,b,c,d;
int main(){
	while(~scanf("%d%d",&a,&b)){
		int ans = max(a+b,a-b);
		ans = max(ans,a*b);
		printf("%d\n",ans);
	}
	return 0;
}

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

typedef long long ll;
typedef struct pair<int,int> P;
int p[1001]={};
int x[1001]={};
int y[1001]={};

vector<int> v;
int a[100001]={};

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i];
	sort(a,a+n);
	int a1=a[0];
	int b=1;
	int t=0;
	for(int i=1;i<n;++i){
		if(a[i]!=a1){
			t+=b%2;
			a1=a[i];
			b=1;
		}else{
			b++;
		}
	}
	t+=b%2;

	cout<<t<<endl;

	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    ll N,W; cin >> N >> W;
    vector<vector<ll>> V(4);
    ll w1; 
    REP(i,N){
        ll w,v; cin >> w >> v;
        if(i==0){
            w1 = w;
            V[0].push_back(v);
        }else{
            V[w-w1].push_back(v);
        }
    }
    REP(i,4){
        if(V[i].size()!=0){
            sort(ALL(V[i]), greater<ll>());
            REP(j,V[i].size()-1){
                V[i][j+1] += V[i][j];
            }
        }
        V[i].push_back(0);
        sort(ALL(V[i]));
    }
    ll ans = 0;
    REP(a,V[0].size()){
        REP(b,V[1].size()){
            REP(c,V[2].size()){
                REP(d,V[3].size()){
                    if(a*w1 + b*(w1+1) + c*(w1+2) + d*(w1+3) > W) continue;
                    ans = max(ans, V[0][a]+V[1][b]+V[2][c]+V[3][d]);
                }
            }
        }
    }

    cout << ans << endl;
    
    

    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict

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

road = defaultdict(list)
for i in range(m):
    a, b = map(int, input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)

ans = 0
for i in range(n):
    for j in road[i]:
        if h[i] <= h[j]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 103104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, T, result=1001;
  cin >> N >> T;
  vector<int> cost(N);
  vector<int> time(N);
  for(int i=0;i<N;i++){
    cin >> cost.at(i) >> time.at(i);
  }
  for(int i=0;i<N;i++){
    if(time.at(i) <= T){
      if(cost.at(i) <= result){
        result = cost.at(i);
      }
    }
  }
  if(result == 1001){
    cout << "TLE" << endl;
  }else{
    cout << result << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <iterator>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 1000020;
const LL INF = 100000000000000LL;
const LL mod = 998244353;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define For(i,a,b) for(int i=a;i<=b;++i)

int n;
int a, b;

void solve() {
    if(a + b == 15) cout << "+" << endl;
    else if(a * b == 15) cout << "*" << endl;
    else cout << "x" << endl;
}

int main() {
    while(cin >> a >> b) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256