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

using namespace std;

#define ll long long
#define ar array



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

	int k;
	cin >> k;
	if(k&1^1 || k%5==0){
		cout << -1;
	}else{
		ll seven = 7%k;
		int cnt = 1;
		while(seven){
			seven  = (seven*10 + 7)%k;
			cnt++;
		}
		cout << cnt;
	}


	return 0;
}


Measured memory_bytes: 3680
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)
def lcm(a,b):
	p = a*b
	g = gcd(a,b);
	return p//g
MOD = int(10**9+7)
n = int(input())
a = list(map(int,input().split()))
lc = a[0];
for i in range(1,n):
	lc = lcm(a[i],lc)
ans = 0
for i in range(n):
	ans += (lc//a[i])
print(ans%MOD)

Measured memory_bytes: 4084
# -*- coding: utf-8 -*-

n = int(raw_input())
for i in range(n):
    line = str(raw_input())
    p = []
    for j in range(len(line)):
        p.append(int(line[j]))
    p.sort()
    x = 1
    max = 0
    min = 0
    for j in range(len(p)):
        max += p[j]*x
        min += p[len(p)-j-1]*x
        x *= 10
    print max-min

Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int Maxn = 60;

bool used[Maxn], g[Maxn][Maxn];
int n, m;
int a[Maxn], b[Maxn];

void dfs(int x){
    used[x] = true;
    for (int i = 0; i < n; i++){
        if (g[x][i] && !used[i]) dfs(i); 
    }
}



int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        a[i] = --x;
        b[i] = --y;
        g[x][y] = g[y][x] = true;
    }

    int cnt = 0;
    for (int i = 0; i < m; i++){
        g[a[i]][b[i]] = false;
        fill(used, used + Maxn, false);
        dfs(a[i]);
        if (!used[b[i]]) cnt++;
        g[a[i]][b[i]] = true;
    }

    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define INF 1e9
typedef long long LL;
const LL mod = 1e9+7;

int main() {
  int A, B, X;
  cin >> A >> B >> X;
  
  string answer = "NO";
  if (A <= X && A + B >= X) answer = "YES";
  
  cout << answer << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

int main() {
  int W,H,N;
  cin >> W >> H >> N;
  int xn[N],yn[N],an[N];
  for(int i=0; i < N; ++i)cin >> xn[i] >> yn[i] >> an[i];

  int resW[2]={0,W},resH[2]={0,H};
  for(int i = 0; i < N; ++i){
    if(an[i] == 1){
      if(resW[0] < xn[i]){
        resW[0] = xn[i];
      }
    }
    if(an[i] == 2){
      if(resW[1] > xn[i]){
        resW[1] = xn[i];
      }
    }
    if(an[i] == 3){
      if(resH[0] < yn[i]){
        resH[0] = yn[i];
      }
    }
    if(an[i] == 4){
      if(resH[1] > yn[i]){
        resH[1] = yn[i];
      }
    }
  }
  if(resW[0] > resW[1] || resH[0] > resH[1]){
    cout << '0' << endl;
  }else{
    cout << (resW[1] - resW[0]) * (resH[1] - resH[0]) << endl;
  }
}



Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_up_longint(const void *a, const void *b){
   return *(long int*)a - *(long int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N,count;
  scanf("%d",&N);
  long int num[N];
  long int tmp[N];
  for(int i=0;i<N;i++) scanf("%ld ",&num[i]);
  for(int i=0;i<N;i++)tmp[i] = num[i];
  qsort(tmp,N,sizeof(long int),compare_up_longint);
  long int a = tmp[N/2 -1];long int b = tmp[N/2];
  for(int i=0;i<N;i++){
    if(2*num[i] < a+b) printf("%d\n",b);
    else printf("%d\n",a);
  }
  //for(int i=0;i<N;i++) printf("%d\n",num[i]);
  return 0;
}


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

#define ll long long

const int mxN=3e3, M=998244353;
int n, s, a[mxN];
ll dp[mxN+1][mxN+1], ans;

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

	cin >> n >> s;
	for(int i=0; i<n; ++i) {
		cin >> a[i];
		memcpy(dp[i+1], dp[i], sizeof(dp[0]));
		//start a new sequence
		dp[i+1][a[i]]=(dp[i+1][a[i]]+i+1)%M;
		for(int j=0; j+a[i]<=s; ++j)
			dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%M;
		ans=(dp[i+1][s]+ans)%M;
	}
	cout << ans;
}


Measured memory_bytes: 70656
// https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c
#![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 s = read::<String>().chars().collect::<Vec<_>>();
    let mut s2 = Vec::new();
    for &ch in s.iter() {
        if ch != 'x' {
            s2.push(ch);
        }
    }
    debug!(s2);
    for i in 0..s2.len() / 2 {
        if s2[i] != s2[s2.len() - i - 1] {
            println!("-1");
            return;
        }
    }
    let mut x_count = Vec::new();
    let mut current_count = 0i64;
    for &ch in s.iter() {
        if ch != 'x' {
            x_count.push(current_count);
            current_count = 0;
        } else {
            current_count += 1;
        }
    }
    x_count.push(current_count);
    let mut ans = 0;
    for i in 0..x_count.len() / 2 {
        ans += (x_count[i] - x_count[x_count.len() - 1 - i]).abs();
    }
    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: 6396
#include<iostream>

using namespace std;

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

Measured memory_bytes: 764
import sys
sys.setrecursionlimit(1000000)

N, M = map(int, input().split())

G = [[] for i in range(N)]
for _ in range(M):
    Ai, Bi = map(int, input().split())
    G[Ai - 1].append(Bi - 1)
    G[Bi - 1].append(Ai - 1)

color = [0] * N
def dfs(v, c):
    '''
    頂点vをcで塗る　そこから深さ優先探索で交互に塗っていく
    '''
    color[v] = c
    for i in G[v]:
        if color[i] == c:
            return False
        if color[i] == 0 and not(dfs(i, -c)):
            return False
    return True

if dfs(0, 1):
    print(color.count(1) * color.count(-1) - M)
else:
    print(N * (N - 1) // 2 - M)


Measured memory_bytes: 31164
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	l := make(map[int]int, n)
	var a, b int
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		l[a-1]++
		l[b-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Println(l[i])
	}
}


Measured memory_bytes: 512
/*
ID: alec3
LANG: C++14
PROG: ttwo
*/

#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }

using namespace std;

ifstream fin("ttwo.in");
ofstream fout("ttwo.out");

ll dp[100001];
int main()
{
    io;
    int n, w;
    cin >> n >> w;

    vector<int> a(n), b(n);

    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }

    for (int i = 0; i < n; i++){
        for (int j = w - a[i]; j >= 0; j--)
            dp[j + a[i]] = max(dp[j] + b[i], dp[j + a[i]]);
    }
    cout << dp[w] << endl;

    return 0;
}


Measured memory_bytes: 4388
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int a[32] = {1,
               1,
               1,
               2,
               1,
               2,
               1,
               5,
               2,
               2,
               1,
               5,
               1,
               2,
               1,
               14,
               1,
               5,
               1,
               5,
               2,
               2,
               1,
               15,
               2,
               2,
               5,
               4,
               1,
               4,
               1,
               51};

  int K;
  cin >> K;
  out(a[K - 1]);
}


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

ll binaryExponentiation(ll x, ll n){
    ll result = 1LL;
    while(n > 0){
        if(n&1) result *= x;
        x = x*x;
        n >>= 1;
    }
    return result;
}
// 1000000000000000000


int main() {

    ll x, t = 0;
    cin >> x;

    ll A = 100;
    for(t = 1; t < 3762; t++) {
        A += (A * 0.01);
        if(A >= x)
            break;
    }

    cout << t << "\n";

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define mp make_pair
#define ll long long
#define pii pair<int,int>
using namespace std;

bool cmp(pii p1,pii p2) {
    return p1.first<p2.first;
}
int main() {
  ll n;
  cin>>n;
  vector<pii>v;
  int a,b;
  int curr=0;
  for(int i=0;i<n;i++) {
      cin>>a>>b;
      v.push_back({b,a});
  }
  sort(v.begin(),v.end(),cmp);
  int st=1;
  for(int i=0;i<n;i++) {
      curr+=v[i].second;
      if(curr>v[i].first){
          st=0;
          break;
      }
  }
  if(st) {
      cout<<"Yes";
  }
  else {
      cout<<"No";
  }
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

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

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

vector<int> f(string s) {
	int N = s.length();
	vector<int> a(N + 1);
	rep(i, N) {
		a[i + 1] = a[i];
		if (s[i] == 'A') a[i + 1]++;
		if (s[i] == 'B') a[i + 1]--;
	}
	return a;
}

int main() {
	string s, t;
	cin >> s >> t;
	vector<int> a = f(s), b = f(t);
	int Q; cin >> Q;
	while (Q--) {
		int l1, r1, l2, r2;
		scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
		l1--; l2--;
		int x = a[r1] - a[l1], y = b[r2] - b[l2];
		x = (x % 3 + 3) % 3;
		y = (y % 3 + 3) % 3;
		printf("%s\n", x == y ? "YES" : "NO");
	}
}


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

int main() {
  int n,l; cin >> n >> l;
  vector<string> strl(n);
  vector<char> strs(n);
  
  if(l==1){
    for(int i=0; i < n; i++){
	  char s; cin >> s;
      strs.at(i)=s;
    }
    
    sort(strs.begin(),strs.end());
    
    string sum;
    for(int i=0; i < n; i++){
      sum += strs.at(i);
     }
    
    cout << sum << endl;
  }
  else{
    for(int i=0; i < n; i++){
	  string s; cin >> s;
      strl.at(i)=s;
    }
    
    sort(strl.begin(),strl.end());
    
    string sum;
    for(int i=0; i < n; i++){
      sum += strl.at(i);
    }
    
    cout << sum << endl;
  }
}


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

using namespace std; 

int main() 
{ 
	long long a; cin >> a;
	long long b; cin >> b;
	long long k; cin >> k;

	if(k == 0) cout << a << " " << b << endl;
	else
	{
		if(a-k == 0) a = 0;
		else if(a-k > 0) a -= k;
		else if(a-k < 0)
		{
			k = k - a;
			a = 0;
			b -= k;
			//cout << k << endl;
			if(b < 0) b = 0;
		}

		cout << a << " " << b << endl;
	}

	return 0; 
} 


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

using namespace std;
#define ll long long

int main()
{
    ll n ,m;
    cin >> n >> m;
    if(n>=10)
    {
        cout << m << endl;
    }
    else
    {
        cout << m+(10-n)*100;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int n;
	cin>>n;
	long long int v[n],c[n],sum=0,i,j,k;
	for(i=0;i<n;++i)
	{
		cin>>v[i];
	}
	for (j=0;j<n;++j)
	{
		cin>>c[j];
	}
	for(k=0;k<n;++k)
	{
		if(v[k]-c[k]>0)
		{
			sum+=v[k]-c[k];
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
   int n,m,l,i,j,k;
   long a[100][100],b[100][100],c[100][100];
   for (i=0;i<100;i++){
       for (j=0;j<100;j++){
           a[i][j]=0;
           b[i][j]=0;
           c[i][j]=0;
       }
   }
   cin >> n >> m >> l;
   for (i=0;i<n;i++){
       for (j=0;j<m;j++){
           cin >> a[i][j];
       }
   }
   for (i=0;i<m;i++){
       for (j=0;j<l;j++){
           cin >> b[i][j];
       }
   }
   for (i=0;i<n;i++){
       for (j=0;j<l;j++){
           for (k=0;k<m;k++){
               c[i][j] = c[i][j]  + (a[i][k] * b[k][j]);
           }
       }
   }
   for (i=0;i<n;i++){
       for (j=0;j<l;j++){
           if(j==l-1){
               cout << c[i][j] << endl;
           }
           else{
               cout << c[i][j] << " ";
           }
       }
   }
}


Measured memory_bytes: 3344
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
long long ans,num=1;
int n;
string s[maxn];
int main()
{
        cin>>n;
        for(int i=1;i<=n;i++) cin>>s[i],sort(s[i].begin(),s[i].end());
        sort(s+1,s+n+1);
        for(int i=2;i<=n;i++)
            if(s[i]==s[i-1])
                num++;
            else
            {
                ans+=1LL*num*(num-1)/2;
                num=1;
            }
        ans+=1LL*num*(num-1)/2;
        cout<<ans<<endl;
        return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

int N,Q;
string s;
vector<char>t,d;

bool left(int now){
  for(int i=0;i<Q;i++){
    if(s[now]==t[i]){
      if(d[i]=='L')now--;
      if(d[i]=='R')now++;
    }
    if(now<0)return true;
  }
  return false;
}

bool right(int now){
  for(int i=0;i<Q;i++){
    if(s[now]==t[i]){
      if(d[i]=='L')now--;
      if(d[i]=='R')now++;
    }
    if(now>=N)return true;
  }
  return false;
}

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

  cin>>N>>Q;
  cin>>s;
  t.resize(Q);
  d.resize(Q);
  for(int i=0;i<Q;i++)cin>>t[i]>>d[i];

  //左に落ちる
  int l1=0;
  int r1=N;
  int m1;
  while(r1-l1>1){
    m1=(l1+r1)/2;
    if(left(m1))l1=m1;
    else r1=m1;
  }

  int l2=0;
  int r2=N;
  int m2;
  while(r2-l2>1){
    m2=(l2+r2)/2;
    if(right(m2))r2=m2;
    else l2=m2;
  }
  cout<<N-min(l1+N-l2,N)<<endl;
  return 0;
}


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

struct range{
  float m;
  float M;
};

int main(){
  int a,b,ans = 0;
  cin >> a;
  cin >> b;
  range xa,xb;
  xa.m = (25*a)/2;
  xa.M = (25*(a + 1))/2;
  xb.m = 10*b;
  xb.M = 10*(b + 1);

  if((xa.m >= xb.M)||(xb.m >= xa.M)){
    ans = -1;
  }
  else if((xa.m >= xb.m)&&(xa.M >= xb.M)){
    if((xb.M - xa.m) <= 0.5){
      ans = -1;
    }
    else if(a%2 == 0){
      ans = xa.m;
    }
    else{
      ans = xa.m + 1;
    }
  }
  else if((xa.m <= xb.m)&&(xa.M <= xb.M)){
    ans = xb.m;
  }
  else if((xa.m <= xb.m)&&(xa.M >= xb.M)){
    ans = xb.m;
  }
  printf("%d\n",ans);
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    cin>>N;
    set<ll> s;
    s.insert(N);
    reps(i,2,1000010){
        N = (N%2 == 1 ? 3*N + 1 : N/2);
        auto ite = s.find(N);
        if(ite == s.end()) {
            s.insert(N);
        }else {
            cout << i << endl;
            return 0;
        }
    }
}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int A = in.nextInt();
			String str = in.next();
			int B = in.nextInt();
			out.println(str.equals("+") ? A + B : A - B);
		}
	}

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

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

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

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
}


Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")




int main() {


    ll n; cin >> n;
    string s;
    ll a = 0, b = 0, c = 0, ans = 0;
    rep(i,n){
        cin >> s;
        if(s[0] == 'B' && s[s.length()-1] == 'A') c ++;
        else if(s[s.length()-1] == 'A') a ++;
        else if(s[0] == 'B') b ++;
        rep(j,s.length()-1){
            if(s[j] == 'A' && s[j+1] == 'B') ans ++;
        }

    }
    
    if(c == 0) cout << ans + min(a,b);
    else{
        if(a+b == 0) cout << ans + c-1;
        else cout << ans + c + min(a,b);
    }



    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<vector>

using namespace std;
using ll = long long;
const ll N = 1e6;
const double PI = acos(-1.0);
#define Test ll tesnum;tesnum = read();while(tesnum--)
ll read();
int a[N],b[N];
int main()
{
    int n;
    cin>>n;
    
    for(int i = 1; i <= n; i++){
        cin>>a[i]>>b[i];
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    if(n&1)
    {
        cout<<b[n+1>>1]-a[n+1>>1]+1<<endl;
    }else{
        cout<<b[n>>1]+b[(n>>1)+1]-a[n>>1]-a[(n>>1)+1]+1<<endl;
    }
    return "BT7274", NULL;
}

inline ll read() {
    ll hcy = 0, dia = 1;char boluo = getchar();
    while (!isdigit(boluo)) {if (boluo == '-')dia = -1;boluo = getchar();}
    while (isdigit(boluo)) {hcy = hcy * 10 + boluo - '0';boluo = getchar();}
    return hcy * dia;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<bool> ch(60000);
    fill(ch.begin(), ch.end(), true);
    ch[0] = false;
    ch[1] = false;
    for(int i = 2; i < 60000; i++){
        if(ch[i]){
            for(int k = 2; k * i < 60000; k++) ch[i * k] = false;
        }
    }
    int s = 0, k = 0;
    while(k < n){
        if(ch[s] && 1 == s%5)cout << s <<" ", k++;
        s++;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] even = new int[100001];
		int[] odd = new int[100001];
		
		int evenMaxIndex = 0;
		int evenMaxCount = 0;
		int oddMaxIndex = 0;
		int oddMaxCount = 0;
		for (int i = 1; i <= N; i++) {
			int num = sc.nextInt();
			if (i % 2 == 0) {
				int tmp = even[num];
				tmp++;
				even[num] = tmp;
				
				if (Math.max(evenMaxCount, tmp) == tmp) {
					evenMaxIndex = num;
					evenMaxCount = tmp;
				}
			} else {
				int tmp = odd[num];
				tmp++;
				odd[num] = tmp;
				
				if (Math.max(oddMaxCount, tmp) == tmp) {
					oddMaxIndex = num;
					oddMaxCount = tmp;
				}
			}
		}
		
		if (evenMaxIndex == oddMaxIndex) {
			Arrays.sort(even);
			Arrays.sort(odd);
			oddMaxCount = Math.max(even[even.length-2], odd[odd.length-2]);
		}
		
		int ans = N - (evenMaxCount + oddMaxCount);
		
		System.out.println(ans);
	}
	
}

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

long long mod = 1e9 + 7;
int main(){
    long long n, m;
    cin >> n >> m;

    vector<long long> use(n+1, true);

    for(long long i = 0; i < m; i++){
        long long a;
        cin >> a;
        use[a] = false;
    }

    vector<long long> dp(n+1, 0);
    dp[0] = 1;

    for(long long i = 0; i <= n; i++){
        if(i == 0) continue;
        if(i == 1){
            if(use[i] == true) dp[i] = dp[i-1];
            else dp[i] = 0;
        }
        else{
            if(use[i] == false) dp[i] = 0;
            else{
                dp[i] = dp[i-1]%mod + dp[i-2]%mod;
                dp[i] = dp[i]%mod;
            }
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 4840
#include <stdio.h>
#define N 500000
#define M 2147483647
void marge(int *,int,int,int);
void margeSort(int *,int,int);
int count=0,n,i,S[N];
int main(){
 

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  margeSort(S,0,n);

  for(i=0;i<n-1;i++)
    printf("%d ",S[i]);
  printf("%d\n%d\n",S[n-1],count);
  
  
  return 0;
}

void marge(int *A,int left,int mid,int right){
  int n1,n2,j,k;
  int L[N/2+1],R[N/2+1];
  n1=mid-left;
  n2=right-mid;



  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=M;
  R[n2]=M;

  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
      count++;
    }
    else {
      A[k]=R[j];
      j=j+1;
      count++;
    }
  }
  
}

void margeSort(int *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    margeSort(A,left,mid);
    margeSort(A,mid,right);
    marge(A,left,mid,right);
  }
  
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

vector<int> v;
int banned = 2;

void dfs1(auto &E,int now,int parent){
	int maxi = 0;
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		if(to==parent)continue;
		dfs1(E,to,now);
		maxi = max(maxi,v[to]);
	}
	
	v[now] = maxi+1;
}

void dfs2(auto &E,int now,int parent,int X){
	vector<pair<int,int>> P;
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		if(to==parent)continue;
		P.emplace_back(v[to],to);
	}
	
	P.emplace_back(X,parent);
	
	sort(P.rbegin(),P.rend());
	
	if(P.size()>=3&&P[2].first>=1){
		int A = P[0].first;
		int B = P[2].first;
		//cout<<now<<':'<<A<<endl;
		if(A!=B){
			banned = max(banned,A+B);
		}
		else{
			banned = max(banned,A+B-1);
		}
	}
	
	
	sort(P.rbegin(),P.rend());
	
	for(int i=0;i<E[now].size();i++){
		int to = E[now][i];
		if(to==parent)continue;
		if(P[0].second!=to)dfs2(E,to,now,P[0].first+1);
		else dfs2(E,to,now,P[1].first+1);
	}
}

int main(){
    
	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	v.resize(N,1);
	
	dfs1(E,0,-1);
	
	dfs2(E,0,-1,0);
	
	string ans(N,'1');
	
	for(int i=2;i<banned;i++){
		ans[i] = '0';
	}
	
	cout<<ans<<endl;
	
    return 0;
}



Measured memory_bytes: 24200
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const LL MOD = 1e9 + 7;
const int N = 1e5;
LL fct[2 * N + 5];
LL inv[2 * N + 5];

LL fast(LL A, LL B) {
	LL ans = 1;
	while(B) {
		if(B & 1) ans = ans * A % MOD;
		B /= 2;
		A = A * A % MOD;
	}
	return ans;
}

void pre() {
	fct[0] = 1;
	for(int i = 1;i <= 2 * N;i++) fct[i] = fct[i - 1] * i % MOD;
	inv[2 * N] = fast(fct[2 * N],MOD - 2) % MOD;
	for(int i = 2 * N - 1;i >= 0;i--) inv[i] = inv[i + 1] * (i + 1) % MOD;
}

LL dp[N + 5];
pair<LL,LL> pos[N + 5];

LL combin(int n,int r) {
	return fct[n] * inv[r] % MOD * inv[n - r] % MOD;
}

void hora(int tc) {
	pre();
	LL h,w,n;
	cin>>h>>w>>n;
	for(int i = 0;i < n;i++) {
		cin>>pos[i].FI>>pos[i].SE;
	}
	pos[n] = {h,w};
	n++;
	sort(pos,pos + n);
	for(int i = 0;i < n;i++) {
		LL ways = combin(pos[i].FI + pos[i].SE - 2, pos[i].FI - 1);
		for(int j = 0;j < i;j++) {
			if(pos[j].FI <= pos[i].FI && pos[j].SE <= pos[i].SE) {
				int x = pos[i].SE - pos[j].SE;
				int y = pos[i].FI - pos[j].FI;
				ways = (ways + MOD - (combin(x + y, y) * dp[j] % MOD)) % MOD;
			}
		}
		dp[i] = ways;
	}
	cout<<dp[n - 1]<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



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

int comb(int a, int b);

int comb(int a, int b) {
    if (a == 0 || a == 1) {
        return 0;
    }
    int n = b, x = 1, y = 1;
    for (int i = 0; i < n; i++) {
        x *= a--;
        y *= b--;
    }
    return x / y;
}

int main(void) {
    int n, m;
    cin >> n >> m;
    int ans = comb(n, 2) + comb(m, 2);
    cout << ans << endl;
    return 0;
}

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

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    for(auto& e : b) cin >> e;
    string res = "No";
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(b[i] == a[j][k]){
                    a[j][k] = 0;
                }
            }
        }
    }
    for(int i = 0; i < 3; i++){
        if(a[0][i] + a[1][i] + a[2][i] == 0) res = "Yes";
        if(a[i][0] + a[i][1] + a[i][2] == 0) res = "Yes";
        if(a[0][0] + a[1][1] + a[2][2] == 0) res = "Yes";
        if(a[0][2] + a[1][1] + a[2][0] == 0) res = "Yes";
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
using namespace std;
typedef vector<long long int> vec; 
typedef vector<vec> mat; 
int N; 
long long int P = 1e9+7; 
mat mul(mat A, mat B){
	mat C(A.size(), vec(B[0].size())); 
	for(int i = 0; i < A.size(); i++){
		for(int k = 0; k < B.size(); k++){
			for(int j = 0; j < B[0].size(); j++){
				C[i][j] += A[i][k] * B[k][j]; 
				C[i][j] %= P; 
			}
		}
	}
	return C; 
}
mat pow(mat A, long long K){
	mat D(A.size(), vec(A.size())); 
	for(int i = 0; i < A.size(); i++){
		D[i][i] = 1; 
	}
	while(K > 0){
		if(K & 1) D = mul(D, A); 
		A = mul(A, A); 
		K >>= 1; 
	}
  return D; 
}
int main(){
	int N; long long int K; cin >> N >> K; 
	mat A(N, vec(N)); 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> A[i][j]; 
		}
	}
	mat B(N, vec(1)); mat C(1, vec(N)); mat D(1, vec(1)); 
	for(int i = 0; i < N; i++){
		B[i][0] = 1; C[0][i] = 1; 
	}
	D = mul(mul(C, pow(A, K)), B); 
	cout << D[0][0] << endl; 
}

Measured memory_bytes: 384
from operator import itemgetter
N = int(input())

AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=itemgetter(1))
time = 0
ans = "Yes"
for i in AB:
    time = time + i[0]
    if time>i[1]:
        ans = "No"
        break

print(ans)


Measured memory_bytes: 53732
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;
const int MOD = 1000000007;

int main(){
    int N;cin >> N;
    vector<string> s(2);
    cin >> s[0];
    cin >> s[1];
    int idx = 0;
    vector<int> ope;
    while(idx<N){
        if(s[0][idx]==s[1][idx]){
            ope.push_back(1);
            idx++;
        }else{
            ope.push_back(2);
            idx+=2;
        }
    }
    ll res = ope[0]==1?3:6;
    for(int i=1;i<ope.size();i++){
        if(ope[i-1]==1&&ope[i]==1)res=res*2%MOD;
        if(ope[i-1]==1&&ope[i]==2)res=res*2%MOD;
        if(ope[i-1]==2&&ope[i]==2)res=res*3%MOD;
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N =int(input())
kara =[]
for i in range(N):
    wa = input()
    kara.append(wa)

s = 0  
for k in kara:
    if k =="AC":
        s += 1
print("AC x "+str(s))

t = 0
for k in kara:
    if k =="WA":
        t += 1
print("WA x "+str(t))

z =0
for k in kara:
    if k =="TLE":
        z += 1
print("TLE x "+str(z))

print("RE x " + str(N-s-t-z))



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

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    for (ll i=1;(i*i)<n;++i){
        if(n%i==0 and (n/i)-i>=2){

            ans+=(n/i)-1;
        }
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double x = sc.nextDouble();

		int result = Double.compare(x, a * a * b / 2.0);

		double answer;
		if (result > 0) {
			double h = 2 * (b - x / (a * a));
			answer = Math.atan2(h, a);
		} else {
			double w = 2.0 * x / (a * b);
			answer = Math.atan2(b, w);
		}

		answer = answer / (2.0 * Math.PI) * 360.0;
		System.out.println(answer);
	}
}


Measured memory_bytes: 22996
import collections

def solve(N, blues, M, reds):
    blue_count = collections.Counter(blues)
    red_count  = collections.Counter(reds)

    if len(blue_count - red_count) == 0:
        return 0

    return (blue_count - red_count).most_common()[0][1]

N = int(input())
blues = []
for _ in range(N):
    blues.append(input())

M = int(input())
reds = []
for _ in range(M):
    reds.append(input())

print(solve(N, blues, M, reds))


Measured memory_bytes: 3316
/* One original thought is worth a thousand mindless quotings */

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<bitset>
#include<queue>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

#define int long long
const int N = 5 * 100*1000 + 7;

int test;

int n,m;

int dist[N];

VPI g[N];

BIT czy;

bool bad = 0;

void dfs(int v){
    czy[v] = 1;

    for(auto it:g[v]){
        if (czy[it.st] == 0){
            dist[it.st] = dist[v] + it.nd;
            dfs(it.st);
        }

        if (dist[it.st] != dist[v] + it.nd)
            bad = 1; 
    }
}

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

    FOR(i,1,m){
        int a,b,c;
        cin >> a >> b >> c;

        g[a].eb(b,c);
        g[b].eb(a,-c);
    }

    FOR(i,1,n){
        if (!czy[i])
            dfs(i);
    }

    cout << (bad ? "No" : "Yes");

    return;
}

int32_t main()
{
    boost

    test=1;

    while(test--)
    {
        solve();
    }

  return 0;
}


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

#define fi first
#define se second
typedef pair<int,int> PII;


long long n, m, k, a[1<<20], ans[1<<20], d[1<<20], p[1<<20];

void mul(long long a[], long long b[]) {
    static long long c[1<<20];
    for (int i = 1; i < n; i++) c[i] = a[b[i]];
    for (int i = 1; i < n; i++) a[i] = c[i];
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        d[i+1] -= a[i], d[i] += a[i];
        ans[i+1] = p[i+1] = i+1;
    }
    cin >> m >> k;
    for (int i = 0; i < m; i++) {
        int u;
        cin >> u;
        swap(p[u],p[u-1]);
    }
    for (long long x = k; x; x>>=1) { if (x&1) mul(ans,p); mul(p,p); }
    for (int i = 1; i < n; i++) a[i] = a[i-1] + d[ans[i]];
    for (int i = 0; i < n; i++) cout << a[i] << '\n';
}


Measured memory_bytes: 10240
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func min(arr []int) (v int) {
	for i, n := range arr {
		if i == 0 || v > n {
			v = n
		}
	}
	return
}

func max(arr []int) (v int) {
	for i, n := range arr {
		if i == 0 || v < n {
			v = n
		}
	}
	return
}

func sum(arr []int) (s int) {
	for _, n := range arr {
		s += n
	}
	return
}

func main() {
	rd := bufio.NewReader(os.Stdin)
	var s string
	var err error
	s, err = rd.ReadString('\n')
	if err != nil {
		return
	}
	n, _ := strconv.Atoi(s)
	s, err = rd.ReadString('\n')
	s = strings.TrimSpace(s)
	if err != nil {
		return
	}
	arr := strings.Split(s, " ")
	nums := make([]int, 0, n)
	for _, i := range arr {
		n, _ := strconv.Atoi(i)
		nums = append(nums, n)
	}
	fmt.Println(min(nums), max(nums), sum(nums))
}



Measured memory_bytes: 1924
#include<iostream>
using namespace std;
int main(void)
{
    int a,b,x;
    cin >> a >> b >> x;
    for(int i=0;i<=b;i++)
        if(a+i==x)
        {
            cout << "YES";
            return 0;
        }
    cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;
const int mod = 1e9 + 7;

void add_self (int & a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}

int mul (int a, int b) {
	return (int) (((ll) a * b) % mod);
}

int power (int a, int k) {
	int ans = 1;
	while (k >= 1) {
		if (k & 1) ans = mul (ans, a);
		a = mul (a, a);
		k >>= 1;
	}
	return ans;
}

int inverse (int a) {
	return power (a, mod - 2);
}

pii getFirstAndLast (ll n) {
	pii p;
	p.second = n%10;
	while (n) {
		p.first = n%10;
		n = n/10;
	}
	return p;
}

int main() {
	ll N;
	cin >> N;
	ll answer = 0LL;
	for (ll A = 1; A <= N; A++) {
		ll added = 0;
		pair < int, int > p = getFirstAndLast (A);
		int x = p.first, y = p.second;
		//cout << "A = " << A << x << " " << y << endl;
		if (y == 0) continue;
		if (10 * y + x <= N) {
			added++;
		}
		for (int d = 1; d < 5; d++) {
			ll S = (N - x) / 10 - (ll) (y * pow (10, d));
			added += max (0LL, min (S + 1, (ll) pow (10, d)));
			//cout << added << endl;
		}
		// If B is of the form x (when x == y)
		if (x == y) {
			added += 1;
			//cout << "." << added << endl;
		}
		answer += added;
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    string n;
    
    cin >> n;
    
    if (n.length() != 3) {
        return -1;
    }
    
    for (int i = 0; i < 3; i++) {
        if (n[i] == '1') {
            n[i] = '9';
        } else if (n[i] == '9') {
            n[i] = '1';
        }
    }
    cout << n << endl;
    
    return 0;
}

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

SUM=abs(A[0])
for i in range(N):
  if i < N-1:
    SUM += abs(A[i+1]-A[i])
  else:
    SUM += abs(0-A[i])

now=0
for i in range(N):
  if i != N-1:
    diff = abs(A[i+1]-now)-abs(A[i]-now)-abs(A[i+1]-A[i])
    now = A[i]
  else:
    diff = abs(0-now)-abs(A[i]-now)-abs(0-A[i])
  print(SUM + diff)

Measured memory_bytes: 20512
import sys
import collections


def alg_duplicate_combination_mod(n, r, mod):
    n = n + r - 1
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    t = m
    d = collections.defaultdict(int)
    for i in range(2, int(t ** 0.5) + 1):
        while True:
            if t % i == 0:
                d[i] += 1
                t //= i
            else:
                break
    if t != 1:
        d[t] += 1
    cnt = 1
    for k, v in d.items():
        cnt *= alg_duplicate_combination_mod(n, v, mod)
        cnt %= mod
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

//素数判定表
vector<ll> eratosthenes_sieve(ll n) {
    vector<ll> ps(n + 1);
    iota(ps.begin() + 2, ps.end(), 2);
    for (ll i = 2; i * i <= n; ++i)
        if (ps[i])
            for (ll j = i * i; j <= n; j += i) ps[j] = 0;
    return ps;
}

//素数表
vector<ll> make_primes(ll n) {
    vector<ll> ps = eratosthenes_sieve(n);
    ps.erase(std::remove(ps.begin(), ps.end(), 0), ps.end());
    return ps;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    vector<ll> pm = make_primes(100000 + 1);
    vec ans(100001);
    for(auto p : pm){
        if(p <= 100000) ++ans[p];
        if(2 * p - 1 <= 100000) ++ans[2 * p - 1];
    }
    rep1(i, 100000) ans[i] /= 2;
    rep1(i, 100000) ans[i] += ans[i - 1];

    ll Q;
    cin >> Q;
    rep(_, Q){
        ll l, r;
        cin >> l >> r;
        print(ans[r] - ans[l - 1]);
    }

    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;

struct stk{
	int b,n,s;
	stk(int b, int n, int s) : b(b), n(n), s(s) {}
};

int chkl(int nn, int ss){
int i, cnt=0;
stack< stk > que;
	que.push(stk(-1,0,0));
	while(!que.empty()){
		stk cr = que.top();
		que.pop();
		rep2(i,cr.b+1,10){
			stk nt = cr;
			nt.b=i; nt.n++; nt.s +=i;
//			printf("r= %d %d %d\n",nt.b,nt.n,nt.s);
			if(nt.n==nn && nt.s == ss){
				cnt++;  continue;
			}
			if(nt.s > ss) break;
			if(nt.n > nn) break;
			if(nt.n < nn && nt.s < ss) que.push(nt);

		}
	}
	return cnt;
}

int main(void){

int nn, ss;
	
	while(cin >> nn >> ss){
		if(nn ==0 && ss ==0) break;
		cout << chkl(nn,ss) << endl;
		
	}
	return 0;
}

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

int main(){
  ll n, kk;
  cin >> n >> kk;
  vector<pair<ll,ll>> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  ll ans = 4e18;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < n; l++) {
          ll xmax = max(p[i].first,max(p[j].first,max(p[k].first,p[l].first)));
          ll ymax = max(p[i].second,max(p[j].second,max(p[k].second,p[l].second)));
          ll xmin = min(p[i].first,min(p[j].first,min(p[k].first,p[l].first)));
          ll ymin = min(p[i].second,min(p[j].second,min(p[k].second,p[l].second)));
          int cnt = 0;
          for (int m = 0; m < n; m++) {
            if (p[m].first <= xmax && p[m].first >= xmin && p[m].second <= ymax && p[m].second >= ymin) {
              cnt++;
            }
          }
          if (cnt >= kk) {
            if (xmax == xmin || ymax == ymin) continue;
            ans = min(ans, (xmax - xmin) * (ymax - ymin));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int l[500005], r[500005];
int h[500005], hl;
int comp_h(int a, int b)
{
	if (r[h[a]] > r[h[b]])
		return 1;
	else
		return -1;
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void f1(int ne)
{
	h[hl] = ne;
	int p = hl;
	hl++;
	while (p > 0)
	{
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
		p = (p - 1) / 2;
	}
	return;
}
int f2()
{
	hl--;
	swap_h(0, hl);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < hl)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < hl)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[hl];
}
int seg[2000006], s;
void set(int x, int v)
{
	x += s - 1;
	seg[x] = v;
	while (x > 0)
	{
		x = (x - 1) / 2;
		seg[x] = seg[2 * x + 1] + seg[2 * x + 2];
	}
	return;
}
int get(int left, int right)
{
	left += s - 1;
	right += s - 1;
	int res = 0;
	while (left < right)
	{
		if (left % 2 == 0)
			res += seg[left];
		left = left / 2;
		if (right % 2 > 0)
			res += seg[right];
		right = (right - 2) / 2;
	}
	if (left == right)
		res += seg[left];
	return res;
}
int main()
{
	int n, q;
	scanf("%d %d", &n, &q);
	int i;
	int c[500005];
	for (i = 0; i < n; i++)
	{
		scanf("%d", &c[i]);
		c[i]--;
	}
	for (i = 0; i < q; i++)
		scanf("%d %d", &l[i], &r[i]);
	int sq[500005];
	hl = 0;
	for (i = 0; i < q; i++)
		f1(i);
	for (i = 0; i < q; i++)
		sq[i] = f2();
	int last[500005];
	for (i = 0; i < n; i++)
		last[i] = -1;
	s = 1;
	while (s < n)
		s *= 2;
	int ans[500005];
	int nl = 0;
	for (i = 0; i < q; i++)
	{
		while (nl < r[sq[i]])
		{
			if (last[c[nl]] >= 0)
				set(last[c[nl]], 0);
			last[c[nl]] = nl;
			set(nl, 1);
			nl++;
		}
		ans[sq[i]] = get(l[sq[i]] - 1, r[sq[i]] - 1);
	}
	for (i = 0; i < q; i++)
		printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 21180