akhauriyash/Code-Regression huggingface dataset:
import itertools
import math
n = int(input())
d = {}
for i in range(n):
  d[i] = list(map(int, input().split()))

p = [i for i in range(n)]
q = list(itertools.permutations(p, n))
arr = []
for i in range(len(q)):
  dis = 0
  for j in range(1, n):
    start = d[q[i][j - 1]]
    stop = d[q[i][j]]
    dis += math.sqrt((start[0] - stop[0]) ** 2 + (start[1] - stop[1]) ** 2)
  arr.append(dis)
ans = sum(arr) / len(q)
print(ans)

Measured memory_bytes: 9252
#include <iostream>
#include <string>
using namespace std;
int main(){
int a,b;
string s;
cin >>a>>b>>s;
if(s.length()!=(a+b+1)){
  cout<<"No"<<endl;
  return 0;
}
  else if (s[a]!='-'){
  cout<<"No"<<endl;
  return 0;
}
  for(int i=0;i<a;i++){
if (!((48<=static_cast<int>(s[i]))&&(static_cast<int>(s[i])<=57))){
  cout<<"No"<<endl;
  return 0;
  }
}
for(int i=a+1;a<i&&i<a+b+1;i++){
if (!((48<=static_cast<int>(s[i]))&&(static_cast<int>(s[i])<=57))){
cout<<"No"<<endl;
return 0;
}
}
  cout<<"Yes"<<endl;
  return 0;

}


Measured memory_bytes: 256
#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 ll MOD = 1e9 + 7;

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


int main() {

    ll n,a; cin >> n;
    string ans = "second";
    rep(i,n){
        cin >> a;
        if(a%2 == 1) ans = "first";
    }
    cout << ans;
}


Measured memory_bytes: 3612
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        //string input= Console.ReadLine();
        int input =int.Parse(Console.ReadLine());
        string st = input.ToString();
        Console.WriteLine((st[0]==st[1]&&st[1]==st[2])||(st[2] == st[3] && st[1] == st[2])?"Yes":"No");


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=1e18;
using namespace std;
int main()
{
	LL a[Max],b[Max];
	int A,B,Q;
	LL t;
	scanf("%d%d%d",&A,&B,&Q);
	a[0]=-inf;
	b[0]=-inf;
	a[A+1]=inf;
	b[B+1]=inf;
	for(int i=1;i<=A;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int j=1;j<=B;j++)
	{
		scanf("%lld",&b[j]);
	}
	while(Q--)
	{
		scanf("%lld",&t);
		int i=lower_bound(a,a+A+1,t)-a;
		int j=lower_bound(b,b+B+1,t)-b;
		LL ans=inf,la,lb,ra,rb;
		la=t-a[i-1];
		lb=t-b[j-1];
		ra=a[i]-t;
		rb=b[j]-t;
		ans = min(ans, max(ra, rb));
        ans = min(ans, max(la, lb));
		ans = min(ans, ra + lb + min(ra, lb));
        ans = min(ans, la + rb + min(la, rb));
        printf("%lld\n",ans);
	}
}


Measured memory_bytes: 2944
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll q,h,s,d;
    ll n;
    std::cin >> q>>h>>s>>d;
    std::cin >> n;
    ll a = min({q*4,h*2,s});
    if(n%2==0){
        std::cout << min(a*n,d*n/2) << std::endl;
    }else{
        std::cout << min(a*(n-1),d*(n-1)/2)+a << std::endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define flu(i, a, b) for(ll i = a; i < b; i++)
#define blu(i, a, b) for(ll i = a; i >= b; i--)
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define Unique(X) (X).erase(unique(all(X)), (X).end())
#define all(v) v.begin(), v.end()
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\n';

ll MOD = 1e9 + 7;

ll i, j, le;

int sv(int x)
{
    int n = 200000;
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++)
    {
       
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
    if (prime[x])
        return 1;
    else
        return 0;
}

int main()
{
    IOS;
    int t;
    //cin >> t;
     t=1;
    while (t--)
    {
        ll n,c=0,sum1,sum2,sum3,sum,k;
        cin>>n;
        vl v(n,0);
        flu(i,0,n)cin>>v[i];
        sort(all(v));
       for(i=0;i<n;i++)
        {
           for(j=0;j<n && i!=j;j++)
            {
                for(k=0;k<n && k!=i && k!=j;k++)
                {   if(v[i]!=v[j] && v[i]!=v[k] && v[j]!=v[k])
                {
                    sum1= v[i]+v[j];
                    sum2=v[j]+v[k];
                    sum3= v[k]+v[i];
                    if(sum1>v[k] && sum2>v[i] && sum3>v[j])c++;
                }
                }
            }
        }
        cout<<c<<e;
    }
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;

vector<vector<int>> dp(1001,vector<int>(10001,INT_MAX));
int func(vector<int>& a, vector<int>& b, int n, int h){
    if(h<=0) return 0;
    if(n<0) return INT_MAX;
    if(dp[n][h]!=INT_MAX) return dp[n][h];
    dp[n][h] = min(func(a,b,n,h-a[n])+b[n],func(a,b,n-1,h));
    return dp[n][h];
}
int32_t main(){
    N4RUTO;
    int h,n;
    cin>>h>>n;
    vector<int> a(n),b(n);
    loop(i,0,n-1) cin>>a[i]>>b[i];
    cout<<func(a,b,n-1,h);      
    return 0;
}

Measured memory_bytes: 79360
// "k 列消せる" を "n-k 列選ぶ" に言い換えると考えやすくなる

#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

const lint INF=1LL<<61;

int main(){
	int n,k,h[301]={};
	scanf("%d%d",&n,&k);
	rep(i,n) scanf("%d",&h[i+1]);

	// dp[i][j] := ( i 列選び, 最後に選んだ列が j であるときの最適解 )
	lint dp[301][301];
	rep(i,n-k+1) rep(j,n+1) dp[i][j]=INF;
	dp[0][0]=0;
	for(int t=1;t<=n;t++){
		for(int i=n-k-1;i>=0;i--) rep(j,t) {
			dp[i+1][t]=min(dp[i+1][t],dp[i][j]+max(h[t]-h[j],0));
		}
	}

	printf("%lld\n",*min_element(dp[n-k],dp[n-k]+n+1));

	return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d;
		int e=0;
		int f=0;
		cin>>a;
		if (a==0)
		{
			break;
		}
		for (b=0;b<a;b++)
		{

			cin>>c>>d;
			if (c>d)
			{
				e=e+c+d;
			}
			else if (c<d)
			{
				f=f+d+c;
			}
			else if (c==d)
			{
				e=e+c;
				f=f+d;
			}
		}
		cout<<e<<" "<<f<<endl;
	}
	return 0;
}
			

Measured memory_bytes: 2928
import itertools

n, m, q = map(int, input().split())  # x = 1, y = 2
abcd = list(list(map(int, input().split())) for _ in range(q))

# print(n, m, q, abcd)

combis = list(itertools.combinations_with_replacement(range(1, m + 1), n))
# print(combis)
max_sum = 0
for patt in combis:
    sumv = 0
    for abc in abcd:
        [a, b, c, d] = abc
        if c == (patt[b - 1] - patt[a - 1]):
            sumv += d
    if max_sum < sumv:
        max_sum = sumv

print(max_sum)


Measured memory_bytes: 21604
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int d;
	while(~scanf("%d",&d)){
		int S=0;
		for(int i=d;i<=600-d;i+=d){
			S += (i*i)*d;
		}
		printf("%d\n",S);
	}
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,x) = get!(usize, usize);
    if x == 2*n-1 || x == 1 {
        println!("No");
        return;
    }
    println!("Yes");
    if x == 2 {
        let mut vec = (1..2*n).filter(|&e| e < x-1 || x+2 <e).collect::<Vec<_>>();
        let xvec = [x+1,x,x-1,x+2];
        let mut j = 0;
        for i in 1..2*n {
            if i>=n-2 && i<=n+1 {
                println!("{}", xvec[j]);
                j += 1;
            } else {
                println!("{}", vec.pop().unwrap());
            }
        }
        return;
    }
    let mut vec = (1..2*n).filter(|&e| e < x-2 || x+1 <e).collect::<Vec<_>>();
    let xvec = [x-2,x,x+1,x-1];
    let mut j = 0;
    for i in 1..2*n {
        if i>=n-2 && i<=n+1 {
            println!("{}",xvec[j]);
            j += 1;
        } else {
            println!("{}", vec.pop().unwrap());
        }
    }
}


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

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

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int ans=0;
	string s;
	cin>> s;

	rep(i, s.size()){
		if(s[i]=='+') ans++;
		else ans--;
	}
 
	cout<< ans <<endl;

	return 0;
}

Measured memory_bytes: 3552
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M, X = lr()
A = lr()
left = sum(1 for y in A if y < X)
right = M - left
answer = min(left, right)
print(answer)


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

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

use std::cmp::{max, min};

fn main() {
  let n = read::<i32>();
  // let p = vec![];
  let mut count = 0;

  for i in 0..n {
    let p_i = read::<i32>();
    if p_i != i + 1 {
      count += 1;
    }
  }

  if count == 2 || count == 0 {
    println!("YES");
  } else {
    println!("NO");
  }

}



Measured memory_bytes: 4352
N=int(input())
Y=[]
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        Y.append([i,N//i])

def FAB(S):
    return(max(len(str(S[0])),len(str(S[1]))))

ans=10**10
for i in range(len(Y)):
    ans=min(ans,FAB(Y[i]))
print(ans)

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

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

  int total = 0;
  for (int i = 0; i < C; ++i) {
    int p;
    cin >> p;
    total += p;
  }

  int s = total / (N + 1);
  int r = total % (N + 1);

  s += r > 0;

  cout << s << endl;

  return 0;
}



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

using namespace std;

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

  int H,W; cin>>H>>W;
  vector<string> map(H);
  for (auto& s : map) cin>>s;

  auto bfs = [&](int s) {
    if (map[s/W][s%W] == '#')
      return -1;
    vector<int> d(H*W, numeric_limits<int>::max());
    queue<pair<int, int>> qs;
    qs.emplace(s, 0);
    while (not qs.empty()) {
      auto q = qs.front(); qs.pop();
      auto s = q.first;
      auto dist = q.second;
      if (d[s] <= dist)
        continue;
      d[s] = dist;
      auto go = [&](int t) {
        if (map[t/W][t%W] == '.' and d[t] > dist+1) {
          qs.emplace(t, dist+1);
        }
      };
      // -1
      if (s % W > 0) {
        go(s-1);
      }
      // 1
      if (s%W != W-1) {
        go(s+1);
      }
      // -W
      if (s/W > 0) {
        go(s-W);
      }
      // W
      if (s/W != H-1) {
        go(s+W);
      }
    }
    auto res = 0;
    for (auto v : d) {
      if (v == numeric_limits<int>::max())
        continue;
      res = max(res, v);
    }
    return res;
  };
  auto ans = 0;
  for (int i = 0; i < H*W; i++) {
    ans = max(ans, bfs(i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ma 100001
bool coun[ma]={0};
int pen[ma]={0};
int main()
{
  int n,m;cin>>n>>m;
  string *s=new string[m];
  int *p=new int[m];
  for(int i=0;i<m;i++)
    cin>>p[i]>>s[i];
  
  for(int i=0;i<m;i++)
  {
  	
  	int t=p[i];
    if(!coun[t])
    {
    if(s[i]=="AC")
      coun[t]=1;
    else
      pen[t]++;
    }
  }
  int  c=0,pe=0;
  for(int i=1;i<ma;i++)
  {
    if(coun[i])
    {c++;
     pe+=pen[i];
    }
  }
  cout<<c<<" "<<pe;
  return 0;
}
  
  

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

long long euclidean_gcd(long long a, long long b) {
  if(a < b) euclidean_gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int N;
    cin >> N;
    long long A, B;
    cin >> A;
    for(int i = 1; i < N; i++){
        cin >> B;
        A = euclidean_gcd(A, B);
    }
    cout << A << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#define R second.second
using namespace std;
typedef vector<pair<int,pair<int,int> > >vpp;
void rm(vpp&v,int d){
	for(int i=0;i<v.size();i++)if(v[i].first==d){v.erase(v.begin()+i);break;}
}
void add(vpp&v,int d,int w){
	for(int i=0;~v[i].first;i++){
		if(v[i+1].second.first-v[i].R>=w){
			v.insert(v.begin()+i+1,make_pair(d,make_pair(v[i].R,v[i].R+w)));
			printf("%d\n",v[i].R);return;
		}
	}
	puts("impossible");
}
int main(){
	int W,Q,d,w;
	char s[2];
	for(;scanf("%d%d",&W,&Q),W;){
		vpp v;
		v.push_back(make_pair(-2,make_pair(0,0)));
		v.push_back(make_pair(-1,make_pair(W,0)));
		for(;Q;Q--){
			scanf("%s",s);
			if(*s=='w')scanf("%d",&d),rm(v,d);
			else scanf("%d%d",&d,&w),add(v,d,w);
		}
		puts("END");
	}
}

Measured memory_bytes: 0
n = int(input())
ans = 0

for i in range(1, n+1):
  if not i % 2 == 0:
    count = 0
    for j in range(1, i+1):
      if i % j == 0:
        count += 1
    
    if count == 8:
      ans += 1

print(ans)

Measured memory_bytes: 2940
s=input()
n=len(s)

s0=''
s1=''
for i in range(n):
    if (i%2==0):
        s0+='0'
        s1+='1'
    else:
        s0+='1'
        s1+='0'

a=0
b=0
for i in range(n):
    if s[i]!=s0[i]:
        a+=1
    if s[i]!=s1[i]:
        b+=1
print(min(a,b))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
void input()
{
    //6:19

    cin>>N>>K;
}
void solve()
{
    // (A+B)%K == (B+C)%K == (C+A)%K == 0
    int a1=0,a2=0;
    bool even=not (K%2);
    for(int i=K; i<=N; i+=K) a1++;
    if (even) for(int i=K/2; i<=N; i+=K)a2++;
    cout<<a1*a1*a1 + a2*a2*a2<<endl;
}
signed main()
{
    input();
    solve();
    return 0;
}

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

const int MAXN = 200000 + 10;
const int MAXL = 100000 + 10;

struct DSU
{
    int fa[MAXN];

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

    void merge(int x, int y)
    {
        fa[find(x)] = find(y);
    }
}d1, d2;

int tmp[MAXN], ans[MAXN], cnt[MAXN];

void init(DSU & d)
{
    for(int i = 0; i < MAXN; i++)
        d.fa[i] = i;
}

int N, K, L;
int main()
{
    init(d1);
    init(d2);
    int u, v;
    cin >> N >> K >> L ;

    for(int i = 1; i <= K; i++)
        cin >> u >> v, d1.merge(u, v);
    for(int i = 1; i <= L; i++)
        cin >> u >> v, d2.merge(u, v);

    for(int i = 1; i <= N; i++)
        d1.fa[i] = d1.find(i),
        d2.fa[i] = d2.find(i);
    for(int i = 1; i <= N; i++)
        tmp[i] = i;
    sort(tmp+1, tmp+N+1, [](int x, int y)-> bool {return d1.fa[x] < d1.fa[y];});


    for(int i = 1; i <= N; i++)
    {
        int j = i;
        while(j < N && d1.fa[tmp[j]] == d1.fa[tmp[j+1]])
            j++;

        for(int t = i; t <= j; t++)
            cnt[d2.fa[tmp[t]]]++;
        for(int t = i; t <= j; t++)
            ans[tmp[t]] = cnt[d2.fa[tmp[t]]];
        for(int t = i; t <= j; t++)
            cnt[d2.fa[tmp[t]]]--;
        i = j ;
    }

    for(int i = 1; i <= N; i++)
        cout << ans[i] << " \n"[i == N] ;

    return 0;
}


Measured memory_bytes: 4608
#include<iostream>
#include<string>
using namespace std;
auto change(string n) {
	n = n.back() + n.substr(0, n.size() - 1);
	return n;
}
int main() {
	string S, T;
	cin >> S >> T;
	bool ans = false;
	for (int i = 0; i < S.size(); ++i) {
		if (S == T) {
			ans = true;
			break;
		}
		S = change(S);
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int *a = new int[m];
    int sum = 0;
    for (int i = 0; i < m;i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    if(sum>n)
    {
        cout << -1 << endl;
    }else
    {
        cout << n - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
A = [0]+list(map(int,input().split()))+[0]
suma = 0
for i in range(1,N+2):
    suma += abs(A[i]-A[i-1])
for i in range(1,N+1):
    print(suma - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1]))

Measured memory_bytes: 14044
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S; cin >> S;
  int size, count;
  char a, b;
  size = S.size();
  a = S[0];
  b = S[size-1];
  count = size - 2;
  cout << a << count << b << endl;
}

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

int main(){
	int a,b;
	cin>>a>>b;
	while(true){
		if(a>b){
			a=a%b;
		}else{
			b=b%a;
		}
		if(a==0||b==0)break;
	}
	cout<<max(a,b)<<endl;
	return 0;
} 

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> iii;
typedef vector<iii> viii;

#define umap unordered_map
#define uset unordered_set
#define pb push_back
#define LSOne(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

const int iinf = 1e9+7;
const ll inf = 1e18+7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    vi dp(3);
    for (int i = 0; i < n; ++i) {
        vi new_dp(3,0),v(3);
        for (auto& i : v) cin >> i;
        for (int i = 0; i < 3; ++i)
            for (int j = 0; j < 3; ++j) {
                if (i != j) {
                    new_dp[j] = max(new_dp[j],dp[i]+v[j]);
                }
            }
        dp = new_dp;
    }
    cout << max({dp[0],dp[1],dp[2]}) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
  ll n;
  cin >> n;
  ll a[n+1],work[n+1];
  rep(i,n) a[i+1] = 0;
  rep(i,n){
	cin >> work[i+1];
	a[work[i+1]]++;
  }

  ll sum = 0;
  rep(i,n) sum += a[i+1]*(a[i+1]-1)/2;
  //  cout << "sum =" << sum << endl;
  rep(i,n) cout << sum-a[work[i+1]]*(a[work[i+1]]-1)/2+(a[work[i+1]]-1)*(a[work[i+1]]-2)/2 << endl;
  return 0;
  
}


Measured memory_bytes: 5760
Class Main
    Public Shared Sub Main()
        Dim tmp As String() = Split(Console.ReadLine(), " ")
        Dim A As Integer = CInt(tmp(0))
        Dim B As Integer = CInt(tmp(1))
        Dim C As Integer = CInt(tmp(2))
    Dim D As Integer = CInt(tmp(3))
    if (A + d - 1) \ D >= (C + b - 1) \ B THEN
        Console.WriteLine("Yes")
      else
      Console.WriteLine("No")
        end if
        End Sub
End Class


Measured memory_bytes: 28388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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

    int ans = 0;
    for(int i = 1; i < n; i++){
        string l = s.substr(0, i);
        string r = s.substr(i);
        set<char> t;
        for(auto c:l)
            t.insert(c);
        int cnt = 0;
        for(auto x:t)
            if(r.find(x) != string::npos)
                cnt++;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 100010;
ll a[MAXN];
ll n, t;

void solve() {
  int cur = 0;
  int cnt = 0;
  ll maxDiff = 0;
  for (int i=0;i<n;i++) {
    if (a[i] - a[cur] == maxDiff) {
      cnt++;
    } else if (a[i] - a[cur] > maxDiff) {
      cnt = 1;
      maxDiff = a[i] - a[cur];
    } else if (a[i] < a[cur]){
      cur = i;
    }
  }
  cout << cnt << endl;
}

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


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

int main() {
   int n;
   cin >> n;
   
   vector<int> vec(n);
   
   for (int i=0; i<n; i++) {
       cin >> vec.at(i); 
   }
   
   sort(vec.begin(), vec.end());
   
   int ans = 1;
   
   for (int i=n-1; i>0; i--) {
       if (vec.at(i) > vec.at(i-1)) ans++;
   }
   cout << ans << endl;
}

Measured memory_bytes: 3644
S = input()
K = int(input())

# import bisect

five_subs = []
for num in range(1,6):
    for idx in range(len(S)-(num-1)):
        tmp_s = S[idx:idx+num]
        
        if len(five_subs) == 0:
            five_subs.append(tmp_s)

        else:
            if tmp_s in five_subs:
                continue
            elif len(five_subs) <= 5:
                five_subs.append(tmp_s)
                five_subs.sort()
                five_subs = five_subs[:5]
            else:
                for sub in five_subs:
                    if sub > tmp_s:
                        five_subs.append(tmp_s)
                        five_subs.sort()
                        five_subs = five_subs[:5]
                        break

print(five_subs[K-1])

Measured memory_bytes: 40560
import java.util.Scanner;

public class Main {
	
	private static void solve(int n ,int[] h) {
		
		int[] dp = new int[n];
		dp[1] = Math.abs(h[1]-h[0]);
		
		for (int i=2; i<n; i++) {
			
			dp[i] = Math.min(
						dp[i-1] + Math.abs(h[i] - h[i-1]), 
						dp[i-2] + Math.abs(h[i] - h[i-2])
						);
		}

		System.out.println(dp[n-1]);
	}

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int[] h = new int[n];
		
		for (int i=0; i<n; i++) {
			h[i] = scanner.nextInt();
		}
		
		solve(n, h);
		
		scanner.close();
	}

}


Measured memory_bytes: 50956
#include<stdio.h>



int main( void )
{
	int	a ,a10 ;
	int	b ,b20 ;

	char	name[ 2 ][ 1 << 7 ] = { "hiroshi\n" ,"kenjiro\n" } ;

	int h ,hh ;
	int	k ,kk ;
	int Hp ,Kp ;
	scanf( "%d %d" ,&h ,&hh ) ;
	scanf( "%d %d" ,&k ,&kk ) ;

	scanf( "%d %d %d %d" ,&a ,&b ,&a10 ,&b20 ) ;
	Hp = ( h * a + ( h / 10 ) * a10 ) + ( hh * b + ( hh / 20 ) * b20 ) ;
	Kp = ( k * a + ( k / 10 ) * a10 ) + ( kk * b + ( kk / 20 ) * b20 ) ;

	if( Hp == Kp )
	{
		puts( "even" ) ;
	}
	else
	{
		printf( name[ ( Kp > Hp ) ] ) ;
	}

	return 0 ;
}


Measured memory_bytes: 2040
#include<stdio.h>
 
int main()
{
  int t[4][14] = {};
  int n, i,j,c;
  char m, d;
 
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
 }
 
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}
 



Measured memory_bytes: 2056
N = int(input())

class Mint:
    
    MOD = 10**9+7
    
    def __init__(self, x=0):
        self.x = (x%self.MOD + self.MOD) % self.MOD
    
    def __iadd__(self, other):
        self.x += other.x
        if self.x >= self.MOD:
            self.x -= self.MOD
        return self
    
    def __isub__(self, other):
        self.x += self.MOD - other.x
        if (self.x >= self.MOD):
            self.x -= self.MOD
        return self
    
    def __imul__(self, other):
        self.x *= other.x
        self.x %= self.MOD;
        return self;
    
    def __add__(self, other):
        ans = Mint(self.x)
        ans += other
        return ans
        
    def __sub__(self, other):
        ans = Mint(self.x)
        ans -= other
        return ans
    
    def __mul__(self, other):
        ans = Mint(self.x)
        ans *= other
        return ans
    
    def __pow__(self, n):
        if n == 0:
            return Mint(1)
        a = self.__pow__(n >> 1)
        a *= a
        if n&1:
            a *= self
        return a
    
    def inv(self):
        return self**(self.MOD-2)
    
    def __ifloordiv__(self, other):
        self *= other.inv()
        return self
    
    def __floordiv__(self, other):
        ans = Mint(self.x)
        ans //= other
        return ans
        
        
def Main(N):
    ans = Mint(1)
    for i in range(1, N+1):
        ans *= Mint(i)
    return ans.x
    
print(Main(N))

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll>arr(k);
    vector<ll> val(10,0);
    for(ll i=0;i<k;i++)
    {
        cin >> arr[i];
        val[arr[i]]++;

    }
    for(ll i=n;i<10*n;i++)
    {
        ll temp=i;
        map<ll,ll> mp;
        while(temp)
        {
            ll mod=temp%10;
            mp[mod]++;
            temp/=10;

        }
        ll flag=1;
        for(auto x:mp)
        {
            if(x.second>0)
            {
                if(val[x.first]!=0)
                {
                    flag=-1;
                    
                }
            }
        }
        if(flag==1)
        {
            cout <<i;
            break;
        }


    }
}


Measured memory_bytes: 3596
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAX_N 12
#define MAX_M 12

const int INF = 1000000000;

int main() {
  int N, M, X;
  int A[MAX_N][MAX_M];
  int C[MAX_N];
  int answer = INF;
        
        cin >> N >> M >> X;
        for (int i = 0; i < N; i++) {
          cin >> C[i];
          for (int j = 0; j < M; j++) {
            cin >> A[i][j];
          }
        }
        
        for (int s = 0; s < 1 << N; s++) {
          int cost = 0;
          int understand[MAX_M];
          for (int j = 0; j < M; j++) {
            understand[j] = 0;
          }
          
          for (int i = 0; i < N; i++) {
          if (s >> i &1) {
            cost += C[i];
            for (int j = 0; j < M; j++) {
              understand[j] += A[i][j];
            }
            
            bool ok = true;
            
            for (int j = 0; j < M; j++) {
              if (understand[j] < X) ok = false;
            }
            if (ok) {
              answer = min(answer, cost);
            }
          }
          }
        }
        
        if (answer == INF) answer = -1;
        
        cout << answer << endl;
        
        return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n, a, b;

void read()
{
	cin >> n >> a >> b;
}

void solve()
{
	int ans1, ans2;
	ans1 = min(a, b);
	ans2 = max(0, -(n - a - b));

	cout << ans1 << " " << ans2 << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC55 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def check(t):
    for i in range(n):
        if t[i] == 'S':
            if s[i] == 'o':
                if i == n-1:
                    if t[i-1] != t[0]:
                        return False
                        break
                else:
                    if t[i-1] != t[i+1]:
                        return False
                        break
            else:
                if i == n-1:
                    if t[i-1] == t[0]:
                        return False
                        break
                else:
                    if t[i-1] == t[i+1]:
                        return False
                        break
        if t[i] == 'W':
            if s[i] == 'o':
                if i == n-1:
                    if t[i-1] == t[0]:
                        return False
                        break
                else:
                    if t[i-1] == t[i+1]:
                        return False
                        break
            else:
                if i == n-1:
                    if t[i-1] != t[0]:
                        return False
                        break
                else:
                    if t[i-1] != t[i+1]:
                        return False
    return True

n = I()
s = input()
tmp = ['SS','SW','WS','WW']
for x in tmp:
    for i in range(1,n-1):
        if s[i] == 'o':
            if x[-1] == 'S':
                if x[-2] == 'W':
                    x += 'W'
                else:
                    x += 'S'
            else:
                if x[-2] == 'W':
                    x += 'S'
                else:
                    x += 'W'
        else:
            if x[-1] == 'S':
                if x[-2] == 'W':
                    x += 'S'
                else:
                    x += 'W'
            else:
                if x[-2] == 'W':
                    x += 'W'
                else:
                    x += 'S'
    if check(x):
        print(x)
        quit()
print(-1)


Measured memory_bytes: 3828
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
All = 0
L = [0] * N

for i in range(N):
  t = abs(A[i + 2] - A[i + 1])
  k = abs(A[i + 1] - A[i])
  p = abs(A[i + 2] - A[i])
  All += k
  L[i] = p - (t + k)
All += abs(A[-2])

for i in range(N):
  print(All + L[i])
  

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

int main() {
    int h, w;
    cin >> h >> w;

    vector<int> alphabet(26, 0);
    rep(y, h) rep(x, w) {
            char c;
            cin >> c;
            alphabet[c - 'a']++;
        }

    if (h > w) swap(h, w);

    vector<int> needs;
    for (int i = 0; i < h / 2; i++) {
        for (int j = 0; j < (w / 2); j++) {
            needs.push_back(4);
        }
        if (w % 2 == 1) needs.push_back(2);
    }
    if (h % 2 == 1) {
        for (int j = 0; j < (w / 2); j++) {
            needs.push_back(2);
        }
        if (w % 2 == 1) needs.push_back(1);
    }

    sort(needs.rbegin(), needs.rend());

    priority_queue<ll> q;
    for (ll l : alphabet) if (l != 0) q.push(l);

    for (ll need : needs) {
        if (q.empty()) {
            cout << "No" << endl;
            ret();
        }
        ll t = q.top();
        q.pop();
        if (t < need) {
            cout << "No" << endl;
            ret();
        }
        t -= need;
        assert(t >= 0);
        if (t != 0) q.push(t);
    }
    assert(q.empty());

    cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

  string s,t;
  cin >> s >> t;
  sort(ALL(s));
  sort(ALL(t),greater<char>());
  if (s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n){
        cin >>a[i];
    }
    int count = 0;
    while (true){
        rep(i, n)
        {
            if (a[i] % 2 != 0)
            {
                cout << count << endl;
                return 0;
            }
            else
            {
                a[i] /= 2;
            }
        }
        count++;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define A first
#define B second
#define lowbit(p) (p&(-p))
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
/*
	题意:
	给定一张图和规则 ,求所有点出发至少要操作多少次才能到达 点1
	规则是 每次走到已经走到的点四周最小的点
	
	复杂度应该限制在n log n或者log^2左右.
	
	
	
	如果单独考虑的话.
	节点r到节点1的路径是确定的.
	
	维护某个节点周围和其权值在一定范围内的点的个数 ->克鲁斯卡尔重构树
	 
	
	 
	 
	
*/
#define K 18
#define M 400005
int fa[M][K],n,dp[M],Mx[M][K],mx[M];

struct ed{
	int x,nx;
}e[M];
int nx[M],ecnt=1,de[M],tot,q[M];
void add(int x,int y){
	e[ecnt]=(ed){y,nx[x]};
	nx[x]=ecnt++;
}
void dfs(int f,int x,int v){
	Max(v,x);
	de[x]=de[f]+1;
	mx[x]=v;
	Mx[x][0]=max(f,x);
	fa[x][0]=f;
	q[++tot]=x;
	for (int i=nx[x];i;i=e[i].nx)if (e[i].x!=f){
		dfs(x,e[i].x,v);
	}
}
void init(){
	int k,i,x,v,p;
	dfs(0,1,1);
	for (k=1;k<K;k++){
		for (i=1;i<=n;i++){
			fa[i][k]=fa[fa[i][k-1]][k-1];
			Mx[i][k]=max(Mx[i][k-1],Mx[fa[i][k-1]][k-1]);
		}
	}
	for (i=1;i<=n;i++){
		if (mx[i]==i){
			dp[i]++;
		}
		else{
			p=mx[i];
			x=i;
			v=i;
			for (k=K-1;k>=0;k--){
				if (de[fa[x][k]]>=de[p]+1){
					Max(v,Mx[x][k]);
					x=fa[x][k];
				}
			}
			if (v<mx[fa[p][0]])x=p;
//			printf("x=%d\n",x);
			dp[x]++;
		}
	}
	dp[1]--;
	for (i=1;i<=n;i++)dp[q[i]]+=dp[fa[q[i]][0]];
}
int main(){
//	freopen("1.in","r",stdin);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	int i,x,y;
	for (i=1;i<n;i++){
		read(x);read(y);
		add(x,y); add(y,x);
	}
	init();
	for (i=2;i<n;i++){
		printf("%d ",dp[i]);
	}
	printf("%d\n",dp[i]);
	return 0;
}

Measured memory_bytes: 51200
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  }

  mint a, b;
  a =  b = 1;
  rep (i, n) a *= (i + 1);
  rep (i, m) b *= (i + 1);
  mint ans = a.x * b.x;

  if (n == m) ans *= 2;
  cout << ans.x << endl;

  
  return 0;
}


Measured memory_bytes: 3636
d, g = map(int, input().split())

p, c = [], []

for i in range(d):
    p_tmp, c_tmp = map(int, input().split())
    p.append(p_tmp)
    c.append(c_tmp)

ans = 10 ** 18

for bit in range(1 << d):
    solve = 0
    score = 0
    for i in range(d):
        if bit & (1 << i):
            score += 100 * (i + 1) * p[i]
            score += c[i]
            solve += p[i]
        if score >= g:
            ans = min(ans, solve)
    else:
        if score < g:
            tmp = (1 << d) - 1
            not_bit = bit ^ tmp
            digit = 0
            while not_bit != 0:
                digit += 1
                not_bit = not_bit >> 1
            for j in range(p[digit - 1]):
                score += digit * 100
                solve += 1
                if score >= g:
                    ans = min(ans, solve)
                    break

print(ans)


Measured memory_bytes: 3064
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt(), ans = 0;
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            ans += Math.min(k - a, a) * 2;
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int a,b;
  cin >> a >> b;
  int p = 1;
  int cnt = 0;
  while(p<b){
    p += a-1;
    cnt++;
  }
  cout << cnt << endl;
  
}


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

using namespace std;

long long dp[10005][105];
int v[10005];
string s;
long long MOD = 1000000007;
int N, K;

int main(){
    cin >> s >> K;
    N = s.size();
    for(int i = 1; i<=N; i++){
        v[i] = s[N-i] - '0';
    }
    dp[0][0] = 1;
    for(int i = 1; i<=N; i++){
        for(int j = 0; j<K; j++){
            for(int d = 0; d<=9; d++){
                dp[i][(j+d)%K] += dp[i-1][j];
                dp[i][(j+d)%K] %= MOD;
            }
        }
    }
    int sum = 0;
    long long res = 0;
    for(int i = N; i>=1; i--){
        for(int j = 0; j < v[i]; j++){
            res += dp[i-1][((-(sum+j))%K + K)%K];
            res %= MOD;
        }
        sum += v[i];
    }
    if(sum%K){
        res = (res+MOD-1)%MOD;
    }
    cout << res << endl;
}


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

int main() {
  int N,K,A=0;
  cin>>N>>K;
  vector<int> p(K+1);
  for(int i=0;i<K;i++){
    cin>>p.at(i);
  }
  vector<int> q(N+1);
  q.at(0)=1;
  q.at(1)=1;
  if(p.at(A)==1){
    A++;
    q.at(1)=0;
  }
  for(int i=2;i<=N;i++){
    if(p.at(A)==i){
      A++;
    }
    else{
      q.at(i)=(q.at(i-1)+q.at(i-2))%1000000007;
    }
  }
  cout<<q.at(N)<<endl;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
        int h, w;
        scanf("%d %d", &h, &w);
        vector<vector<int>> fie(h+1, vector<int>(w+1, 1e9));
        for(int i=1; i<=h; i++){
                char s[w+1];
                scanf("%s", s);
                for(int j=0; j<w; j++) fie[i][j+1] = (s[j]=='#');
        }

        vector<vector<P>> dp(h+1, vector<P>(w+1, P(1e9, 1)));
        dp[1][1] = P(0, fie[1][1]);
        for(int i=1; i<=h; i++){
                for(int j=1; j<=w; j++){
                        P a, b;
                        if(fie[i][j]){
                                a = P(dp[i-1][j].first, 1);
                                b = P(dp[i][j-1].first, 1);
                        }else{
                                a = P(dp[i-1][j].first+dp[i-1][j].second, 0);
                                b = P(dp[i][j-1].first+dp[i][j-1].second, 0);
                        }
                        dp[i][j] = min({dp[i][j], a, b});
                }
        }
        printf("%d\n", dp[h][w].first+dp[h][w].second);
        return 0;
}


Measured memory_bytes: 384
n=int(input())
A=list(map(int,input().split()))
ki=0  ;gu=0
for i in A:
    if i%2==1:
        ki+=1
    else:
        gu+=1
gu+=ki//2
ki%=2
if gu>=1 and ki==1:
    print("NO");exit()
print("YES")

Measured memory_bytes: 85552
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[])
{
  char s[10]="";
  char a='a';
  scanf("%s",s);
  int l;
  l=strlen(s);
  if(l%2==1){
    printf("No");
    return 0;
  }
  for(int i=0;i<l;i++){
    a=s[i];
    if(i%2==0){
      //if(strcmp(a,'h')){
      if(a!='h'){
        printf("No");
        return 0;
      }
    }else{
      //if(strcmp(a,'i')){
      if(a!='i'){
        printf("No");
        return 0;
      }
    }
  }
  printf("Yes");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
/*   -- AUTHOR -- 
  ---- cervotrex ---- 
*/
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(arr) arr.begin(),arr.end()
#define mod 1000000007
const ll INF = 1LL << 60;
const int MAX_N = 1000005;

ll power(ll x, ll y){
    ll res = 1;
    while(y){
        if(y&1)
          res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return (res%mod);
}

ll ncr(ll n, ll r){
    ll p = 1, k = 1;
    r = (n-r)<r?(n-r):r;
    if(r==0)
        return p;
    while(r){
        p = p*n;
        k *= r;
        ll m = __gcd(p,k);
        p /= m; k /= m;
        n--; r--;
    }
    return p;
}

ll modInverse(ll n){
  return power(n, mod-2);
}

ll ncrfermet(ll n, ll r){
  if(r==0)
    return 1;
  vector<ll> fact(n+1);
  fact[0] = 1;
  for(ll i=1; i<=n; i++)
    fact[i] = fact[i-1]*i%mod;
  ll res = (fact[n]*modInverse(fact[r])%mod*modInverse(fact[n-r])%mod)%mod;
  return (res%mod);
}

void solve(){
  ll n; cin>>n;
  ll ans = power(10ll, n) - 2*power(9ll, n) + power(8ll, n);
  while(ans<0)
    ans += mod;
  cout<<ans<<"\n";
  return ;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 3656
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(c.keys(), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in c.keys():
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 56624