akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

    int sitting = 0;
    for (int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        sitting += r - l + 1;
    }

    cout << sitting << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		long ans = 0L;
		long min = 100000000000L;
		int count = 0;

		for (int i = 0; i < N; i++) {
			long X = sc.nextLong();
			if (X < 0) {
				count++;
			}
			min = Math.min(min, Math.abs(X));
			ans += Math.abs(X);
		}
		if (count % 2 == 0) {
			System.out.println(ans);
		} else {
			System.out.println(ans - 2 * min);
		}

		sc.close();
	}
};


Measured memory_bytes: 60388
#include<stdio.h>

int main()
{
  int N,K,d,Aj;int Re=0;
  scanf("%d",&N);
  scanf("%d",&K);
  int A[100];
  for(int i=0;i<N;i++)
    A[i]=0;
  for(int x=0;x<K;x++)
  {
    scanf("%d",&d);
    for(int j=0;j<d;j++)
    {
      scanf("%d",&Aj);
      Aj--;
      A[Aj]++;
    }
  }
  for(int v=0;v<N;v++)
    if(A[v]==0)
      Re++;
  printf("%d\n",Re);
  return 0;
}


Measured memory_bytes: 1704
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let mut c: Vec<i32> = vec![0; n - 1];
    let mut s: Vec<i32> = vec![0; n - 1];
    let mut f: Vec<i32> = vec![0; n - 1];
    for i in 0..n-1 {
        c[i] = sc.read();
        s[i] = sc.read();
        f[i] = sc.read();
    }

    let mut ans: Vec<i32> = vec![INF; n];
    ans[n - 1] = 0;
    for i in 0..n-1 {
        let mut t = 0;
        for j in i..n-1 {
            t = max(t, s[j]);
            if (t - s[j]) % f[j] != 0 {
                t += f[j] - ((t - s[j]) % f[j]);
            }
            t += c[j];
        }
        ans[i] = t;
    }

    for x in ans {
        println!("{}", x);
    }
}

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

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

    int n, k, d, a;
    int ans=0;
    cin >> n >> k;
    int snuke[101]={0};
    for(int i=1 ; i<=k ; i++){
        cin >> d;
        for(int j=0 ; j<d ; j++){
            cin >> a;
            snuke[a]=1;
        }
    }
    for(int i=1 ; i<=n ; i++){
        if(snuke[i]==0) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <math.h>
#include <bits/stdc++.h>
#include <map>
#include <iostream>

#define FOR(i, a, b) for (int i = (a); i < (b);++i)

using namespace std;


int main()
{
    int N,K;
    cin>>N>>K;
    vector<vector<int>> data(K, vector<int>(K,0));
    vector<vector<int>> tate(K+1, vector<int>(K+1,0));
    vector<vector<int>> yoko(K+1, vector<int>(K+1,0));
    int x,y,z,cnt;
    cnt = 0;
    string c;
    
    FOR(i,0,N){
        cin>>x>>y>>c;
        if (c=="B"){
            z = -1;
        }
        else{
            z = 1;
        }
        if ((x/K)%2==1){
            z *= -1;
        }
        if ((y/K)%2==1){
            z *= -1;
        }
        if (z==1){
        cnt++;
        }
        tate.at(x % K).at(K) += z;
        yoko.at(K).at(y % K) += z;
        data.at(x % K).at(y % K) += z;
    }
    vector<vector<int>> dp(K, vector<int>(K));
    int ans=max(cnt,N-cnt);
    dp.at(0).at(0) = cnt;
    FOR(i,0,K){
        if (i>0){
            dp.at(i).at(0) = dp.at(i - 1).at(0) - tate.at(i - 1).at(K);
        }
        FOR(j,0,K-1){
            yoko.at(i + 1).at(j) = yoko.at(i).at(j) + data.at(i).at(j);
            dp.at(i).at(j + 1) = dp.at(i).at(j) - yoko.at(K).at(j) + 2 * yoko.at(i).at(j);
        }
    }
    int n;
    FOR(i,0,K){
        ans = max(ans, *max_element(dp.at(i).begin(), dp.at(i).end()));
        n = *min_element(dp.at(i).begin(), dp.at(i).end());
        ans = max(ans, N - n);
    }
    cout << ans << endl;
}

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


main ()
{
        int a, b ,c,p;
        cin>>a;
        cin>>b;
        cin>>c;

        if (a>b) 
        {
            p=a;
            a=b;
            b=p;
        }

        if (a>c)
       {
            p=a;
            a=c;
            c=p;
       }        
       
       if(b>c){
        p=b;
        b=c;
        c=p;
        
      }

       cout<<a<<' '<<b<<' '<<c<<endl;
}           


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
	in >> p.first >> p.second;
	return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD = 1000000007;
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	rep(i,n){
		cin>>a[i];
		a[i]--;
	}
	vector memo(n,-1ll);
	stack<P> st;
	st.emplace(0,0);
	while(!st.empty()){
		P it=st.top();st.pop();
		if(memo[it.first]!=-1){
			int b=it.second-memo[it.first];
			int c=(k-memo[it.first])%b;
			c+=memo[it.first];
			rep(i,n){
				if(memo[i]==c)cout<<i+1<<endl;
			}
			return 0;
		}
		memo[it.first]=it.second;
		if(it.second==k){
			cout<<it.first+1<<endl;
			return 0;
		}
		st.emplace(a[it.first],it.second+1);
	}
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
struct edge{ll to, cost;};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000
#define ALL(a)  (a).begin(),(a).end()
#define large 1000000000000000000
 
int main(){
    ll a;
    long double b;
    ll hoge;
    cin >> a >> b;
    ll ans;
    hoge = b * 100 + 0.1;
    ans = (ll)(a * hoge)/ 100;
    cout << ans << endl;
}

Measured memory_bytes: 3724
import math
n = int(input())
position = [list(map(int, input().split())) for i in range(n)]

sum = 0
for i in range(n):
  for j in range(i, n):
    x = abs(position[i][0] - position[j][0])
    y = abs(position[i][1] - position[j][1])
    sum += math.sqrt(x*x + y*y)

print(sum*2/n)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long l,r;
  cin>>l>>r;
  r=min(r,l+2019);
  int ans=2018;
  for(long long i=l;i<=r;i++){
    for(long long j=i+1;j<=r;j++){
      int res=(i*j)%2019;
      ans=min(ans,res);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3568
#include <iostream>
using namespace std;
int main(void){
  int a,b,c,d,e,k;
  std::cin >> a>>b>>c>>d>>e>>k;
  if (e-a<=k) {
    std::cout << "Yay!" << '\n';
  }else{
    std::cout << ":(" << '\n';
  }
  return 0;
}


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

if n % 2 == 0:
  print(n*(n-2)//2)
  for i in range(1,n):
    for j in range(i+1,n+1):
      if i + j != n+1:
        print(i,j)
else:
  print(n*(n-2)//2+1)
  for i in range(1,n):
    for j in range(i+1,n+1):
      if i + j != n:
        print(i,j)


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> G(n);

    vector<int> ans(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> q;
    vector<int> d(n,-1);
    q.push(0);
    while(!q.empty()){
        int v=q.front();
        q.pop();

        for(int nv:G[v]){
            if(d[nv]!=-1) continue;
            d[nv]=d[v]+1;
            ans[nv]=v+1;
            q.push(nv);
        }
    }

    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++) cout<<ans[i]<<endl;
}

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

int main() {
  int n,m,p,t1,t2;
  p = 0;
  cin >> n >> m;
  vector<int> h(n),t(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> t1 >> t2;
    if (h.at(t1-1) < h.at(t2-1)) {
      t.at(t1-1) = 1;
    } else if (h.at(t1-1) > h.at(t2-1)) {
      t.at(t2-1) = 1;
    } else {
      t.at(t1-1) = 1;
      t.at(t2-1) = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!t.at(i)) {
      p++;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 4052
#include "bits/stdc++.h"
using namespace std;
int main()
{
    string a;
    cin >> a;
    if(a.length() >= 4 && a[0] == 'Y' && a[1] == 'A' && a[2] == 'K' && a[3] == 'I')
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
     long long int a,n=0,s;
    scanf("%lld",&a);
    for(int i=1;i<=a;i++)
    {
        if(i%3!=0 && i%5!=0 && i%15!=0)
            n=n+i;
    }
    printf("%lld",n);
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define S second
#define F first
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using LL = long long;
using LD = long double;
const int mod = 1e9 + 7;
const LL N = 1e5 + 5;

using namespace std ;

LL ans[1007][1007];
//LL arr[N];
int main (){
    int n, m;
    cin >> n >> m;
    char grid[n][m];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> grid[i][j];

    ans[0][0] = 1;
    for(int i = 0; i < n; ++i){
        for (int j = 0; j < m; ++j){
            if(i and grid[i - 1][j] != '#')
                ans[i][j] = (ans[i][j] + ans[i - 1][j]) % mod;

            if(j)
                ans[i][j] = (ans[i][j] + ans[i][j - 1]) % mod;

            if (grid[i][j] == '#') ans[i][j] = 0;
        }
    }
    cout << ans[n - 1][m - 1] << endl;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2000+5;
int n,x,y,dist[MAXN][MAXN],ans[MAXN];
int main()
{
	cin>>n>>x>>y;
	if(x>y) swap(x,y);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dist[i][j]=abs(j-i);
	for(int i=x;i<=y;i++)
	{
		dist[x][i]=dist[i][x]=min(dist[i][x],dist[i][y]+1);
		dist[y][i]=dist[i][y]=min(dist[i][y],dist[i][x]+1);
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dist[i][j]=dist[j][i]=min(dist[i][j],min(dist[i][x]+dist[x][j],dist[i][y]+dist[y][j]));
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans[dist[i][j]]++;
	for(int i=1;i<=n-1;i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 15872
c = [list(map(int,input().split())) for _ in range(3)]

judge = True
for i in range(2):
    for j in range(2):
        if (c[j][i]-c[j+1][i]) != (c[j][i+1]-c[j+1][i+1]):
            judge = False
for i in range(2):
    for j in range(2):
        if (c[i][j]-c[i][j+1]) != (c[i+1][j]-c[i+1][j+1]):
            judge = False
if judge:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,c=1;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n;i++)
  {
    if(a[i] == c)
      c++;
  }
  if(c==1)
    cout<<"-1";
  else
  {
    i=n-c+1;
 	cout<<i;
  }
  return 0;
}
  


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S,T;
    cin>>S>>T;
    if(S==T.substr(0,S.size())) cout << "Yes" << endl;
    else cout << "No" <<endl;



}


Measured memory_bytes: 3656
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = (ll)1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int m, n;
bool f[8000000];

int main(){
  while (cin >> m >> n, m){
    memset(f, 0, sizeof(f));
    while (true){
      if (f[m]){
        m++;
        continue;
      }
      if (n == 0){
        cout << m << endl;
        break;
      }
      rep(i, m, 8000000, m) f[i] = true;
      m++;
      n--;
    }
  }
}

Measured memory_bytes: 10936
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {

char n[5];

for(int i=1;i<=3;i++){
	
	cin >> n[i];
	
	
}   
   
if(n[1]=='7'||n[2]=='7'||n[3]=='7'){
cout << "Yes" << endl;
}else{
	cout << "No" << endl;
}
	
   
return 0;
}


Measured memory_bytes: 3564
from bisect import bisect_left
from itertools import accumulate


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

b = [0] + a
b.sort(reverse=True)
b = [0] +b
b = list(accumulate(b))

def isok(sum_):
    n_pattern = 0
    for i in range(n):
        n_pattern += n - bisect_left(a, sum_ - a[i])
        if n_pattern >= m:
            return True

    return False

ok = min(a)*2
ng = max(a)*2 +1

while ng - ok > 1:
    mid = (ok+ng)//2
    if isok(mid):
        ok = mid
    else:
        ng = mid

sum_ng = ng
sum_ok = ok

m_counter_ng = 0

ans = 0
for i in range(n):
    id_ng = bisect_left(a, sum_ng - a[i])
    ans += b[n-id_ng]
    ans += a[i]*(n - id_ng)
    m_counter_ng += n - id_ng

ans += sum_ok * (m - m_counter_ng)

print(ans)


Measured memory_bytes: 15412
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 100005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, m, cnt, ans, head[MAXN], f[MAXN], deg[MAXN];

struct Edge {int next, to;} edge[MAXN];

queue<int> q;

void addedge(int from, int to)
{
	edge[++cnt].next=head[from];
	edge[cnt].to=to;
	deg[to]++;
	head[from]=cnt;
}

int main()
{
	scanf("%d%d", &n, &m);
	for(rint i=1, x, y; i<=m; ++i)
	{
		scanf("%d%d", &x, &y);
		addedge(x, y);
	}
	for(rint i=1; i<=n; ++i)
		if(!deg[i]) q.push(i);
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		ans=max(ans, f[x]);
		for(rint i=head[x]; i; i=edge[i].next)
		{
			int to=edge[i].to;
			deg[to]--;
			f[to]=max(f[x]+1, f[to]);
			if(!deg[to]) q.push(to);
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 2432
// #include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

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

    int length = s.length();

    if(length % 2 == 0 && s.substr(0, length / 2) == s.substr(length / 2, length / 2)) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e18
typedef long long ll;

int main(void){
  int N; cin >> N;
  //累積和
  ll A[N+1];
  A[0] = 0;
  int i;REP(i,N){
    ll x;cin >> x;
    A[i+1] = A[i]+x;
  }
  int left = 1,center,right=3;
  ll minimum = INF;
  for(center=2; center<N-1; center++){
    int l,r;
    ll m = INF;
    for(l = left; l<center; l++){
      if(m < abs(A[l] - (A[center] - A[l]))) break;
      else{
        m = abs(A[l] - (A[center] - A[l]) );
      }
    }
    left = l-1;

    m = INF;
    for(r = right; r < N; r++){
      if(m < abs( (A[r] - A[center]) - (A[N] - A[r]) ) ) break;
      else{
        m = abs( (A[r] - A[center]) - (A[N] - A[r]) );
      }
    }
    right = r-1;
    ll Max = max(max(A[left], A[center]-A[left]),max(A[right]-A[center],A[N]-A[right]));
    ll Min = min(min(A[left], A[center]-A[left]),min(A[right]-A[center],A[N]-A[right]));
    if(abs(Max-Min) < minimum){
      minimum = abs(Max-Min);
    }
  }
  cout << minimum << endl;
  return 0;
}


Measured memory_bytes: 1792
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
    std.range, std.container, std.bigint, std.ascii, std.typecons;

// }}}
// nep.scanner {{{
class Scanner
{
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.array : split;
    import std.string : chomp;

    private File file;
    private char[][] str;
    private size_t idx;

    this(File file = stdin)
    {
        this.file = file;
        this.idx = 0;
    }

    private char[] next()
    {
        if (idx < str.length)
        {
            return str[idx++];
        }

        char[] s;
        while (s.length == 0)
        {
            s = file.readln.chomp.to!(char[]);
        }

        str = s.split;
        idx = 0;

        return str[idx++];
    }

    T next(T)()
    {
        return next.to!(T);
    }

    T[] nextArray(T)(size_t len)
    {
        T[] ret = new T[len];

        foreach (ref c; ret)
        {
            c = next!(T);
        }

        return ret;
    }

    void scan()()
    {
    }

    void scan(T, S...)(ref T x, ref S args)
    {
        x = next!(T);
        scan(args);
    }
}
// }}}

void main()
{
    auto cin = new Scanner;
    int n;
    cin.scan(n);
    int[] ar = new int[n + 2];
    foreach (i; 0 .. n)
    {
        cin.scan(ar[i + 1]);
    }
    int sum;
    foreach (i; 0 .. n + 1)
    {
        sum += abs(ar[i + 1] - ar[i]);
    }
    foreach (i; 1 .. n + 1)
    {
        writeln(sum - abs(ar[i] - ar[i - 1]) - abs(ar[i + 1] - ar[i]) + abs(ar[i + 1] - ar[i - 1]));
    }
}

Measured memory_bytes: 5240
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class M>
struct SegmentTree{
    using T = typename M::T;
    int sz;
    vector<T> seg;
    explicit SegmentTree(int n) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2*sz, M::e());
    }

    void set(int k, const T &x){ seg[k + sz] = x; }

    void build(){
        for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[2*i], seg[2*i+1]);
    }

    void update(int k, const T &x){
        k += sz;
        seg[k] = x;
        while (k >>= 1) seg[k] = M::f(seg[2*k], seg[2*k+1]);
    }

    T query(int a, int b){
        T l = M::e(), r = M::e();
        for(a += sz, b += sz; a < b; a >>=1, b>>=1){
            if(a & 1) l = M::f(l, seg[a++]);
            if(b & 1) r = M::f(seg[--b], r);
        }
        return M::f(l, r);
    }

    template<typename C>
    int find(int t, C &c, T &val, int k, int l, int r){
        if(r-l == 1){
            val = f(val, seg[k]);
            return c(val) ? k-sz : -1;
        }
        int m = (l+r) >> 1;
        if(m <= t) return find(t, c, val, (k << 1) | 1, m, r);
        if(t <= l && !c(val = f(val, seg[k]))) return -1;
        int lv = find(t, c, val, (k << 1) | 0 , l, m);
        if(~lv) return lv;
        return find(t, c, val, (k << 1) | 1, m, r);
    }

    template<typename C>
    int find(int t, C &c){
        T val = M::e();
        return find(t, c, val, 1, 0, sz);
    }
    T operator[](const int &k) const { return seg[k + sz]; }
};


struct Monoid{
    using T = int;
    static T f(T a, T b) { return max(a, b); }
    static T e() { return -INF<int>; }
};

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> a(m), b(m);
    vector<int> cnt(h), cntt(w);
    vector<vector<int>> A(h);
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        cnt[a[i]]++; cntt[b[i]]++;
        A[a[i]].emplace_back(b[i]);
    }

    SegmentTree<Monoid> seg(w);
    for (int i = 0; i < w; ++i) {
        seg.set(i, cntt[i]);
    }
    seg.build();
    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (auto &&j : A[i]) {
            cntt[j]--;
            seg.update(j, cntt[j]);
        }
        ans = max(ans, cnt[i]+seg.query(0, w));
        for (auto &&j : A[i]) {
            cntt[j]++;
            seg.update(j, cntt[j]);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 28612
#include<stdio.h>
int q[100010],d[100010];
int topo(int v,int e,int *a,int *b){
  int ta[100010],nt[100010],i,t,r,c[100010]={0};
  for(i=0;i<e;i++)c[b[i]]++;
  for(i=r=0;i<=v;i++){
    ta[i]=-1;
    if(c[i]==0)q[r++]=i;
  }
  for(i=0;i<e;i++){
    nt[i]=ta[a[i]];
    ta[a[i]]=i;
  }
  for(t=0;t<r;t++){
    for(i=ta[q[t]];i+1;i=nt[i]){
      if(--c[b[i]]==0){
	d[b[i]]=q[t];
	q[r++]=b[i];
      }
    }
  }
  return r;
}
int main(){
  int n,m,a[100010],b[100010],i;
  scanf("%d %d",&n,&m);
  for(i=0;i<m+n-1;i++)scanf("%d %d",&a[i],&b[i]);
  topo(n,n+m-1,a,b);
  for(i=0;i<n;i++)printf("%d\n",d[i+1]);
  return 0;
}
  


Measured memory_bytes: 3456
let arr1=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
let n = arr1[0]
let k = arr1[1]

let h=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

let hf = h.filter { $0 >= k }

print( hf.count )

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N, K;
ll A[100005];

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

string solve()
{
    ll g = A[0];
    REP(i, N)
    {
        g = gcd(g, A[i]);
    }

    REP(i, N)
    {
        ll k = A[i] - K;
        if (k < 0)
            continue;
        if (k % g == 0)
            return "POSSIBLE";
    }
    return "IMPOSSIBLE";
}

int main()
{
    cin >> N >> K;
    REP(i, N)
    {
        cin >> A[i];
    }

    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main()
{
    int a, b, c;
    int count = 0;

    std::cin >> a >> b >> c;
    
    for (int x = a; x <= b; x++) {
        if (c % x == 0) {
            count++;
        }
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,a;
    std::deque<int> deq;
    cin>>n>>m;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    for (int j=1;j<=m;j++) {
        for (int k=0;k+1<n;k++) {
            if (deq[k]%j>deq[k+1]%j) {
                swap(deq[k],deq[k+1]);
            }
        }
    }
    for (int l=0;l<deq.size();l++) {
        cout<<deq[l]<<endl;
    }
}


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

ans=1
flag0=0
flag1=0
inf=1000000000000000000

for a in A:
	if(a==0):
		flag0=1
		
if flag0==1:
	print(0)
	
else:
	for a in A:
		ans=ans*a
		if(ans>inf):
			flag1=1
			break

	if flag1==1:
		print(-1)
	else:
		print(ans)

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ss s;
    cin >> s;

    vll n(SIZE(s));
    rep(i,SIZE(s))n[i] = (ll)s[i];

    sort(all(n));

    if(n[0] != 97){
        cout << 'a' << endl;
        return 0;
    }

    rep(i,SIZE(s)){
        if(i == 0)continue;
        if(n[i]-n[i-1] > 1){
            cout << (char)(n[i-1]+1) << endl;
            return 0;
        }
    }

    ll nal=97;
    rep(i,SIZE(s)){
        if(n[i] != nal)nal++;
        if(nal >= 122){
            cout << "None" << endl;
            return 0;
        }
    }
    cout << char(n[SIZE(s)-1]+1) << endl;

    return 0;
}



Measured memory_bytes: 1280
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a + b > c + d){
        cout << "Left" << endl;
    }else if(a + b == c + d){
        cout << "Balanced" << endl;
    }else{
        cout << "Right" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> pairs;
	int left = m / 2 - 1;
	int right = -1;
	int i = 0;
	while(true) {
		if(left < 0) {
			break;
		}
		i++;
		pairs.push_back(make_pair(left, left + i * 2));
		right = left + i * 2;
		left--;
	}
	left = right + ((m + 1) / 2);
	i = 0;
	while(true) {
		if(left <= right) {
			break;
		}
		i++;
		pairs.push_back(make_pair(left, left + i * 2 - 1));
		left--;
	}
	REP(i, m) {
		cout << pairs[i].first + 1 << " " << pairs[i].second + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 4316
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	vi v(100, 0);
	int i = 0, pos = 0;
	while (i < n) {
		if (s[i] == t[pos])pos++;
		i++;
		if (pos == m) {
			int k = 0;
			v[0]++;
			while (v[k] == m + 1) {
				v[k] = 0;
				v[k + 1]++;
				k++;
			}
			while (i < n&&s[i] != t[v[k] - 1])i++;
			i++;
			pos = 0;
		}
	}
	int a = 0;
	REP(i, v.size())if (v[i] > 0)a = i + 1;
	cout << a << endl;
}


Measured memory_bytes: 3332
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>


using namespace std;

int main(){

	int X, Y, N;

	cin >> X >> Y;

	cout << X + Y / 2 << endl;

	return 0;
}


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

int main() {
  int a, p; cin >> a >> p;
  cout << (a*3+p) / 2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

//B問題
public class Main {
	public static void main(String[] args) {

		/*
		[開発方針]
		最大値-最小値で距離を求める
		 */

		//スキャナーを宣言する
	    Scanner sc = new Scanner(System.in);

	    //入力を受け取る
	    int N = Integer.parseInt(sc.next());
	    int a;
	    int max = 0;
	    int min = 1000;

	    for(int cnt = 0; cnt < N; cnt++) {
	    	a = Integer.parseInt(sc.next());
	    	if(a >= max) {
	    		max = a;
	    	}
	    	if(a <= min) {
	    		min = a;
	    	}
	    }

	    //スキャナーを閉じる
	    sc.close();

	    //距離を出力
	    System.out.println(max - min);
	}
}

Measured memory_bytes: 21972
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai

With practice comes perfection,
with knowledge comes wisdom.
Incorporate wisdom in you, practice will harvest better results.
Always learn from others, your method is good but someone's even better.
Results take time, run for wisdom, for innovation, for getting better.
Points are mere objects, either you solve first or you solve better.
Seek for betterment, for quality, pace is important but cannot outstand
the quality you persist.
Times are bad just as now but it'll improve, this is my passion and I promise 
I won't let it go. I'll build myself again like a fighter gets back up after 
being thrown to the ground.
I'll learn. I bet that. I promise that.
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;

bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b){
    return a.fi>b.fi;
}

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

template<class T>
void printv(T &v, ll n){
    if(n==-1)
        n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}

void solve(){
    ll h1,m1,h2,m2,k,x;
    cin>>h1>>m1>>h2>>m2>>k;
    x = (h2-h1)*60 + m2-m1;
    cout << max(0LL, x-k)<<"\n";
}

int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        solve();
    }
}

Measured memory_bytes: 3660
//ARC094-D F - Normalization

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

const int MOD = 998244353;
long long dp[210000][4][4][3]; // (mod 3, last, already)

void add (long long &a, long long b);
long long solve(const string &S);

signed main () {
    string S; 
    cin >> S;

    cout << solve(S) << '\n';

    return (0);
}

void add (long long &a, long long b) {
    a += b;
    if (a >= MOD) {
        a -= MOD;
    }

    return ;
}

long long solve(const string &S) {
    set<char> se;
    bool exist_ren = false;
    long long smod = 0;

    for (int i=0 ;i<S.size() ;i++) {
        se.insert(S[i]);
        smod = (smod + (S[i] - 'a')) % 3;

        if (i+1 < S.size() && S[i] == S[i+1]) {
            exist_ren = true;
        }
    }

    if (se.size() == 1) return 1;
    else if (S.size() == 2) return 2;
    else if (S.size() == 3) {
        if (se.size() == 3) return 3;
        else if (S[0] == S[2]) return 7;
        else return 6;
    }

    memset(dp, 0, sizeof(dp));
    
    for (int last=0 ;last<3 ;last++ ) {
        dp[1][last][last][0] = 1;
    }
    for (int i=1 ;i<S.size() ;i++ ) {
        for (int sum=0 ;sum<3 ;sum++ ) {
            for (int last=0; last<3 ;last++ ) {
                for (int last2=0 ;last2<3 ;last2++ ) {
                    add(dp[i+1][(sum+last2)%3][last2][1], dp[i][sum][last][1]);
                    add(dp[i+1][(sum+last2)%3][last2][last==last2], dp[i][sum][last][0]);
                }
            }
        }
    }
    
    long long res = (exist_ren ? 0 : 1);
    for (int last=0 ;last<3 ;last++ ) {
        add(res, dp[S.size()][smod][last][1]);
    }

    return (res);
}


Measured memory_bytes: 82504
r, c = map(int, input().split())
li = []
for i in range(r):
    li.append(list(map(int, input().split())))
    li[i].append(sum(li[i]))
li.append([sum([li[j][i] for j in range(r)]) for i in range(c+1)])    
for i in range(len(li)):
    print(' '.join(map(str, li[i])))


Measured memory_bytes: 5712
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if ((a * b) % 2 == 1) {
      System.out.println("Odd");
    } else {
      System.out.println("Even");
    }
  } 
}


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

int main() {
    string s[101];
    int h, w;

    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }

    for (int i = 0; i < w+2; ++i) cout << "#";
    cout << endl;

    for (int i = 0; i < h; ++i) {
        cout << "#" << s[i] << "#" << endl;
    }

    for (int i = 0; i < w+2; ++i) cout << "#";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, a;
    cin >> n >> a;
    map<int, i64> dp;
    dp[0] = 1;
    while (n--)
    {
        int x;
        cin >> x;
        map<int, i64> nx(dp);
        for (auto &p : dp)
        {
            int i = p.first;
            i64 val = p.second;
            nx[i + x - a] += val;
        }
        swap(dp, nx);
    }
    cout << dp[0] - 1 << endl;
}

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


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#define MAX_N 10000
#define MAX_K 9

int N, K;
int D[MAX_K];

int check(int a){
    int i, j, n, m;
n=a;
while(n!=0){
        m = n%10;
        for (j=0; j<K; j++)
            if (m==D[j]) return 1;
            n/=10;
}
    return 0;
}

int main(){
    int i;
    scanf("%d%d", &N, &K);
    for (i=0; i<K; i++)
        scanf("%d", &D[i]);

    i=N;
    while (1)
    {
        if(check(i)==0)break;
        else
        {
            i++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 1728
import numpy;I=lambda:map(int,input().split());W,H,N=I();m=numpy.zeros((H,W),int)
while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1
print(W*H-m.sum())

Measured memory_bytes: 14280
import sys
from collections import deque

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q = deque()
for s in S:
    q.append(s)

for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        F = int(F) - 1
        if state ^ F:
            q.append(C)
        else:
            q.appendleft(C)

ans = []
if state == 0:
    while q:
        ans.append(q.popleft())
else:
    while q:
        ans.append(q.pop())

print(''.join(ans))


Measured memory_bytes: 112348
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

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

    map<pair<int, int>, long> mp;
    for (int i = 1; i <= n; i++)
    {
        int tmp = i;
        int p1, p2;
        p1 = tmp % 10;
        while (tmp > 0)
        {
            p2 = tmp % 10;
            tmp /= 10;
        }
        pair<int, int> pr;
        pr.first = p1;
        pr.second = p2;
        mp[pr]++;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int tmp = i;
        int p1, p2;
        p1 = tmp % 10;
        while (tmp > 0)
        {
            p2 = tmp % 10;
            tmp /= 10;
        }
        pair<int, int> pr;
        pr.first = p2;
        pr.second = p1;
        ans += mp[pr];
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
# coding: utf-8
N, A, B = map(int, input().split())
l = [i for i in range(1, N+1, 1)]
ans = 0
for i in range(len(l)):
    s = list(str(l[i]))
    tmp = 0
    for j in range(len(s)):
        tmp += int(s[j])
    if A <= tmp <= B:
        ans += l[i]
print(ans)

Measured memory_bytes: 3316
N = int(input())
a = sorted(map(int, input().split()))

i = 0
remove_cnt = 0
while i < N:
    s = a[i]

    cnt = 1
    while True:

        i += 1
        if i == N or a[i] != s:
            break
        else:
            cnt += 1 

    if cnt > s:
        remove_cnt += cnt - s
    elif cnt < s:
        remove_cnt += cnt
        
print(remove_cnt)


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

int main() {

    int k;
    cin >> k;
    queue<string> q;
    rep(i,9){
        q.push(to_string(i+1));
    }

    rep(i,k-1){
        string curstr = q.front();
        q.pop();
        char rs = curstr.at(curstr.size()-1);
        if(rs != '0'){
            q.push(curstr + (char)(rs-1));
        }
        q.push(curstr + (char)(rs));
        if(rs != '9'){
            q.push(curstr + (char)(rs+1));
        }
    }
    cout << q.front() << endl;

    return 0;
}



Measured memory_bytes: 13696
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long X;

long long A, B;

int main () {
  bool f = false;
  cin >> X;

  for(A = -118; A < 119; A++) {
    for(B = -119; B < 118; B++) {
      if(pow(A, 5) - pow(B, 5) == X) {
        cout << A << " " << B << endl;
        f = true;
        break;
      }
    }
    if(f) break;
  }

  return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, K;
    cin >> N >> K;
    vector<int> A;
    int in;
    for (int i = 0; i < N; i++)
    {
        cin >> in;
        A.emplace_back(in);
    }
    
    vector<int>::iterator p1 = find(A.begin(), A.end(), 1);

    int d1, d2;
    int sum = 0;
    d1 = ((p1 - A.begin()) + (K - 1) - 1) / (K - 1);
    d2 = ((A.end() - p1 - 1) + (K - 1) - 1) / (K - 1);
    sum = d1 + d2;
    if (sum > (((N - 1) + (K - 1) - 1) / (K - 1))) sum = (((N - 1) + (K - 1) - 1) / (K - 1));

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
using namespace std;
typedef pair<int,int> ii;
ii p[200];
int n;

void solve()
{
  int M[n+1][n+1];
  rep(i,n+1)rep(j,n+1)M[i][j] = inf;
  rep(i,n+1)M[i][i] = 0;

  rep(j,n)
    {
      rep(i,n-j)
	{
	  REP(k,i+1,i+j+1)
	    {
	      int cost = M[i][k-1] + M[k][i+j] + p[i].first*p[k-1].second*p[k].first*p[i+j].second;
	      if(cost < M[i][i+j])
		{
		  M[i][i+j] = cost;
		  if(i == 0 && i+j == n-1)
		    {
		      //cout << cost << " = M["<<i<<"]["<<k-1<<"] + M["<<k<<"]["<<i+j<<"] + p["<<i<<"].first*p["<<k-1<<"].second*p["<<k<<"].first*p["<<i+j<<"].second" << endl; 
		      //cout <<  M[i][k-1] <<"+"<< M[k][i+j] <<"+"<< p[i].first<<"*"<<p[k-1].second<<"*"<<p[k].first<<"*"<<p[i+j].second;
		      //cout << endl;
		    }
		}
	    }
	}
    }
  cout << M[0][n-1] << endl;
}

int main()
{

  while(cin >> n)
    {
      rep(i,n)cin >> p[i].first >> p[i].second;
      solve();
    }
  return 0;
}

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

int main() {
    int W,a,b;
    cin>>W>>a>>b;
    if(a+W<=b){
        cout<<b-a-W;
    }else if(b+W<=a){
        cout<<a-b-W;
    }else if(b<=a+W){
        cout<<0;
    }else if(a<=b+W){
        cout<<0;
    }else{} 
return 0;}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,x[100010];
inline int gcd(int n,int m)
{
    return m?gcd(m,n%m):n;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&x[i]);
	while(1)
	  {
       for(i=1,j=0;i<=n;i++)
         if(!(x[i]&1))
           j++;
       if(j&1)
         break;
       if(n-j>1)
         {
          k^=1;
          break;
         }
       for(i=1;i<=n;i++)
         if(x[i]&1)
           {
            x[i]--;
            if(!x[i])
              break;
           }
       if(i<=n)
         {
          k^=1;
          break;
         }
       for(i=1,j=0;i<=n;i++)
         j=gcd(j,x[i]);
       for(i=1;i<=n;i++)
         x[i]/=j;
       k^=1;
      }
    if(k)
      printf("Second\n");
    else
      printf("First\n");
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    int count=0;
    for(int i=1;i<=n;i++){
        if(s.substr(n-i,i)==t.substr(0,i)) count=i;
    }
    cout << n+n-count << endl;
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int a, b, h;
    cin >> a >> b >> h;

    cout << ((a+b)*h)/2 << endl;

    return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
	
	int findLCS(char[] X, char[] Y, int lenX, int lenY) {
		int[][] chart = new int[lenX+1][lenY+1];
		for(int i = 0; i <= lenX; i++) {
			for(int j = 0; j <= lenY; j++) {
				if(i == 0 || j == 0) {
					chart[i][j] = 0;
				}
				else if (X[i-1] == Y[j-1]) {
					chart[i][j] = chart[i-1][j-1] + 1;
				}else {
					chart[i][j] = higherOfTwo(chart[i-1][j], chart[i][j-1]);
				}
			}
		}
		return chart[lenX][lenY];
	}
	int higherOfTwo(int top, int left) {
		return (top > left)? top : left; 
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int q = input.nextInt();
		Main test = new Main();
		input.nextLine();
		for(int i = 0 ; i < q; i++) {
			String str1 = input.nextLine();
			String str2 = input.nextLine();
			char[] X = str1.toCharArray();
			char[] Y = str2.toCharArray();
			int lenX = X.length;
			//System.out.println(lenX);
			int lenY = Y.length;
			//System.out.println(lenY);
			int ans = test.findLCS(X, Y, lenX, lenY);
			System.out.println(ans);
		}
		input.close();	
	}
}


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

int main() {
  int N;
  cin >> N;
  int ans = INT_MAX;
  rep(i, N){
    int A, tmp = 0;
    cin >> A;
    while(A%2==0){
      A /= 2;
      tmp++;
    }
    if(ans > tmp) ans = tmp;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
<?php

function input() {
    return trim(fgets(STDIN));
}

function input_array() {
    return explode(' ', input());
}

function ex_intval($mixed_array) {
    return array_map(function($mixed) {
        return (int)$mixed;
    }, $mixed_array);
}

list($n, $m) = input_array();
$ans = 1;
for ($i = 1; $i ** 2 <= $m; $i++) {
    if ($m % $i === 0) {
        if (intdiv($m, $i) >= $n) {
            $ans = max($ans, $i);
        }
        if ($i >= $n) {
            $ans = max($ans, intdiv($m, $i));
        }
    }
}

echo "{$ans}\n";

Measured memory_bytes: 4728