akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
/*
ll Comb(ll n, ll k){
  ll f[105][105];
  rep(i,105) f[0][i] = f[i][0] = 1;
  REP(i,1,105){
    REP(j,1,105){
      f[i][j] = f[i-1][j] + f[i][j-1];
      if(i+j==n && j==k) return f[i][j];
    }
  }
  return 1;
}
*/

ll Comb(int n, int k){
  ll C[n+1][n+1];
  for(int i=0; i<n+1; i++){
    for(int j=0; j<=i; j++){
      if(j==0 || j==i){
        C[i][j] = 1;
      }else{
        C[i][j] = C[i-1][j-1] + C[i-1][j];
      }
    }
  }
  return C[n][k];
}


int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  rep(i,N){
    cin >> v[i];
  }
  sort(ALLOF(v));
  reverse(ALLOF(v));

  ll mx = -1;
  ll mxn = 1;
  
  ll sum = 0;
  rep(i,N){
    sum += v[i];
    if(A<=i+1 && i+1<=B){
      if(mx*(i+1) < sum*mxn){
        mx = sum;
        mxn = i+1;
      }
    }
  }

  printf("%.15lf\n", mx/(double)mxn);

  ll cnt1 = 0, cnt2 = 0;
  rep(i,N){
    if(v[i] == v[mxn-1]){
      cnt1++;
      if(i < mxn){
        cnt2++;
      }
    }
  }

  sum = 0;
  rep(i,A-1){
    sum += v[i];
  }
  
  ll ret = 0;
  REP(i,A,B+1){
    sum += v[i-1];
    if(sum*mxn != mx*i) break;
    ll cnt = 0;
    rep(j,i){
      if(v[i-1] == v[j]) cnt++;
    }
    ret += Comb(cnt1,cnt);
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for (int i=1; i<=(n); ++i)
#define drep(i,n) for (int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)
#define pu push_back
#define po pop_back
#define pi (acos(-1))
#define fast ios::sync_with_stdio(false); cin.tie(0)
//#define pii pair<int,int>
//#define pll pair<ll,ll>
#define vec vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> P;
const int INF = 1001001001;

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

int main(void) {
  int n;
  cin >> n;
  if (n >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main(void) {

	int n;
	int A[100] ={0};
	int B[100] ={0};
	long long ans =0;

	scanf("%d", &n);

	int i;
	for(i=0;i<n-1;i++)
		scanf("%d", &B[i]);

	A[0] = B[0];
	A[n-1] = B[n-2];
	ans = A[0] +A[n-1];

	for(i=1; i<n-1;i++){
		if(B[i-1] < B[i]){
			A[i] = B[i-1];
		}else{
			A[i] = B[i];
		}
		ans += A[i];

	}
	printf("%lld",ans);

//	for(i=0;i<n;i++)
//	printf("%d\n",A[i]);
	return EXIT_SUCCESS;
}

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

using namespace std;

#define ll long long
#define int ll
#define pb(x) push_back(x)
#define mp(x) make_pair(x)
#define fi first
#define se second
struct Trie
{
    Trie* next[26];
    bool last;
    Trie()
    {
        for(int i=0;i<26;i++)
        {
            next[i]=NULL;
        }
        last=false;
    }
};
Trie* head=new Trie();
int cnt=0;
void insert(string &s)
{
    Trie* ptr=head;
    for(int i=0;i<s.size();i++)
    {
        if(ptr->next[s[i]-'a']==NULL)
        {
            Trie* temp=new Trie();
            ptr->next[s[i]-'a']=temp;
        }
        ptr=ptr->next[s[i]-'a'];
    }
    if(ptr->last==false)
    {
        ptr->last=true;
        cnt++;
    }
    return;
}
int32_t main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
       int S,W;
       cin>>S>>W;
       if(S<=W)
       {
           cout<<"unsafe";
       }
       else cout<<"safe";
    }

    return 0;
    
}

Measured memory_bytes: 3592
import scala.annotation.tailrec
object Main extends App {
  import scala.io.StdIn._


  val n = readInt
  val liquid = Array.tabulate(n){ _ ⇒
    val Array(color, density) = readLine.trim.split(' ')
    color → density.toInt
  }.groupBy(_._1).mapValues(_.map(_._2).sorted.toList)
  val layers = List.tabulate(readInt){ _ ⇒ readLine.trim }
  println(if(canMake(liquid, layers)) "Yes" else "No")
  def canMake(liquid: Map[String, List[Int]], layer: List[String]): Boolean = {
    @tailrec
    def sub(li: Map[String, List[Int]], la: List[String], weight: Int = 0): Boolean = {
      la match {
        case Nil ⇒ true
        case h::_ if !li.contains(h) ⇒ false
        case h::t ⇒
          li(h).span(_ <= weight) match {
            case (_, w::ws) ⇒ sub(li.updated(h, ws), t, w)
            case _ ⇒ false
          }
      }
    }
    sub(liquid, layer)
  }

  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

struct dice{
	int d[6];
	void rotation(int& w,int& x,int& y,int& z){
		int tmp=w; w=x; x=y; y=z; z=tmp;
	}
	void n(){rotation(d[4],d[0],d[1],d[5]);}
	void e(){rotation(d[2],d[0],d[3],d[5]);}
	void w(){rotation(d[3],d[0],d[2],d[5]);}
	void s(){rotation(d[1],d[0],d[4],d[5]);}
	void spin(){rotation(d[1],d[2],d[4],d[3]);}
	int query(int a,int b){
		string ss="WWWWSWW";
		rep(i,ss.length()){
			if(ss[i]=='W')w();
			if(ss[i]=='S')s();
			if(d[0]==a)break;
		}
		while(d[1]!=b)spin();
		return d[2];
	}
};

dice dic;
int q;

int main(){
	cin.sync_with_stdio(false);
	rep(i,6){
		cin>>dic.d[i];
	}
	cin>>q;
	rep(i,q){
		int a,b;
		cin>>a>>b;
		cout<<dic.query(a,b)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3208
using System;
using System.Collections.Generic;
using System.Linq;


public class B{
	
	public static void Main(){
	
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		long N = Int64.Parse(args[0]);
		
		args = Console.ReadLine().Split(' ');
		double T = Double.Parse(args[0]);
		double A = Double.Parse(args[1]);
		
		double[] H = new double[N];
		args = Console.ReadLine().Split(' ');
		for(int i = 0; i < N; i++)
			H[i] = Double.Parse(args[i]);
		
		double d = Int64.MaxValue;
		int result = -1;
		for(int i = 0; i < N; i++)
		{
			double tmp = Math.Abs(T - H[i] * 0.006 - A);
			if(tmp < d)
			{
				d = tmp;
				result = i;
			}			
		}
		
		Console.WriteLine(result + 1);
		
	}
	
}

Measured memory_bytes: 11164
#include <stdio.h>
#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
typedef long long ll;

using namespace std;

const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
const double pi = acos(-1.0), eps = 1e-9;
const ll INF = 1e18;

int n, m, x;
vector <int> a, b, even, odd, nb;

int main(){
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cout << setprecision(10) << fixed;

	cin >> n >> m;

	for(int i = 1; i <= m; ++i){
		cin >> x;
		if(x % 2 == 1)
			odd.pb(x);
		else even.pb(x);
	}

	if(sz(odd) > 2){
		cout << "Impossible";
		return 0;
	}

	if(sz(odd))
		a.pb(odd[0]);

	for(int i = 0; i < sz(even); ++i)
		a.pb(even[i]);

	if(sz(odd) == 2)
		a.pb(odd[1]);
	
	vector <int> b;
	for(int i = 0; i < m; ++i)
		b.pb(a[i]);

	b[0]--;	

	if(sz(a) == 1){
		b.pb(0);
	}

	b[sz(b) - 1] += 1;
	for(int i = 0; i < sz(b); ++i)
		if(b[i])
			nb.pb(b[i]);

	b = nb;

	for(int i = 0; i < m; ++i)
		cout << a[i] << " ";
	cout << endl << sz(b) << endl;

	for(int i = 0; i < sz(b); ++i)
		cout << b[i] << " ";
	
	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.trim();
    input = input.split(" ")
    var a = input[0]
    var b = input[1]
    var h = input[2]
    var m = input[3]

    var c = h * 30 + m * 30/60;
    var d = m * 6;

    if(Math.abs(c-d) < 180){
        var theta = Math.abs(c-d)/180*Math.PI;
        console.log(Math.sqrt(
            a*a+b*b-2*a*b*Math.cos(theta)
        ))
    }else{
        var theta = (360-Math.abs(c-d))/180*Math.PI;
        console.log(Math.sqrt(
            a*a+b*b-2*a*b*Math.cos(theta)
        ))
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 


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

int compare(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}


int main()
{
    int a, b;
    int i = 0;
    int sum = 0;
    int A[1000];
    scanf("%d %d", &a, &b);
    int j = a;
    while(a>0){
        scanf("%d", &A[i]);
        sum += A[i];
        a--;
        i++;
    }

    qsort(A, j, sizeof(int), compare);
    //ならびかえ

    int pop = 0;
    i = 0;
    while (j > 0)
    {
        if((double)A[i]>=(double)sum/(4*b)){
            pop++;
        }
        j--;
        i++;
    }

    if (pop >= b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    string s;
    string c[4] = {
        "dream",
        "dreamer",
        "erase",
        "eraser"
    };
    rep(i,4) reverse(all(c[i]));
    cin >> s;
    reverse(all(s));

    int i = 0;
    while(true){
        bool f = false;
        rep(j,4){
            if(c[j].size() + i > s.size()) continue;
            if(s.substr(i,c[j].size()) == c[j]){
                i += c[j].size();
                f = true;
                break;
            }
        }
        if(not f) break;
    }
    if(i == s.size()) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

typedef long long ll;

int solve() {
    int N, D;
    cin >> N;
    vector<int> c(13, 0);
    rep(i, N) {
        cin >> D;
        if (D == 0) return 0;
        c[D]++;
        if (c[D] == 3) return 0;
        if (D == 12 && c[D] == 2) return 0;
    }
    int ans = 0;
    rep(i, 1 << 11) {
        int d = 0, s = 24;
        for (int j = 1; j < 12; j++) {
            d++;
            if (c[j] == 0) continue;
            if (c[j] == 1 && ((i >> (j - 1)) & 1) == 0) continue;
            s = min(s, d);
            d = 0;
        }
        d++;
        if (c[12] == 1) {
            s = min(s, d);
            d = 0;
        }
        for (int j = 13; j < 24; j++) {
            d++;
            if (c[24 - j] == 0) continue;
            if (c[24 - j] == 1 && ((i >> (23 - j)) & 1) == 1) continue;
            s = min(s, d);
            d = 0;
        }
        d++;
        s = min(s, d);
        ans = max(ans, s);
    }
    return ans;
}

int main() {
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; IN(n);
    VI a(n+2,0); rep(i,n) cin >> a[i+1];
    int ans = 0;
    repe(i,n) ans += abs(a[i] - a[i+1]);
    FOR(i,1,n+1) OUT(ans + abs(a[i-1] - a[i+1]) - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1])));

    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int n;
  cin >> n;
  vecint a(n,0);
  REP(i,n){
    cin >> a[i];
  }
  sort(all(a));
  cout << a[n - 1] - a[0] << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <stdlib.h>
using namespace std;
typedef long long int lld;
typedef long double ld;
string a;
int main(void){
	int n;
	string b;
	scanf("%d",&n);
	cin >> b;
	a += b[0];
	for(int e=1;e<n;e++){
		if(a[a.size()-1]!=b[e]) a += b[e];
	}
	printf("%d",(int)a.size());
	return 0;
}

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

int main(){

    string S, T;
    cin >> S >> T;

    bool ans = false;
    for(int i = 0; i < S.length(); i++){
        rotate(S.begin(), S.begin() + 1, S.end());
        if(S == T) ans = true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import heapq
input=sys.stdin.readline
N=int(input())
A=tuple(map(int,input().split()))
hq=list(A[:N])
heapq.heapify(hq)
s=[0]*(N+1)
s[0]=sum(hq)
for i in range(N):
  x=heapq.heappop(hq)
  if x >= A[N+i]:
    s[i+1]=s[i]
    heapq.heappush(hq,x)
  else:
    s[i+1]=s[i]+A[N+i]-x
    heapq.heappush(hq,A[N+i])
    
hq=list(map(lambda x:-x, A[2*N:]))
heapq.heapify(hq)
t=[0]*(N+1)
t[-1]=-sum(hq)
for i in range(N-1,-1,-1):
  x=heapq.heappop(hq)
  x=-x
  if x <= A[N+i]:
    t[i]=t[i+1]
    heapq.heappush(hq,-x)
  else:
    t[i]=t[i+1]-x+A[N+i]
    heapq.heappush(hq,-A[N+i])
ans=-10**15
for x,y in zip(s,t):
  ans=max(x-y,ans)
print(ans)

Measured memory_bytes: 41516
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {

        //var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = long.Parse(Console.ReadLine());
        var D = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var M = long.Parse(Console.ReadLine());
        var T = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        Array.Sort(D);
        Array.Sort(T);

        var ans = false;
        var t = 0;
        var i = 0;
        for (t = 0; t < N; t++)
        {
            if(T[i] == D[t])
            {
                    i++;
            }

            if (i == M)
            {
                ans = true;
                break;
            }
        }
        Console.WriteLine(ans ? "YES" : "NO");
    }
        

    
}


Measured memory_bytes: 65316
#include <bits/stdc++.h>
using namespace std;
int H,W,N;
char mp[60][60];
int deep[60][60];
vector<pair<int, int>> xy = {{-1,0},{1,0},{0,-1},{0,1}};

void search(int x, int y){
    if(x < 0 || x >= W || y < 0 || y >= H || mp[x][y] == '#') return;
    for(int i = 0; i < 4; i++){
        if(mp[x+xy.at(i).first][y+xy.at(i).second] == '.' && deep[x][y] + 1 < deep[x+xy.at(i).first][y+xy.at(i).second]){
            deep[x+xy.at(i).first][y+xy.at(i).second] = deep[x][y] + 1;
            search(x+xy.at(i).first, y+xy.at(i).second);
        }
    }
}

int main(void){
    // Your code here!
    cin >> H >> W;
    int cnt = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> mp[j][i];
            if(mp[j][i] == '.') cnt++;
        }
    }
    for(int i = 0; i < 60; i++){
        for(int j = 0; j < 60; j++){
            deep[i][j] = 10000;
        }
    }
    deep[0][0] = 1;
    search(0, 0);
    int ans = cnt - deep[W-1][H-1];
    if(ans < 0){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, M := sc.nextInt(), sc.nextInt()
	A := make([]int, M)
	B := make([]int, M)
	for i := 0; i < M; i++ {
		A[i] = sc.nextInt() - 1
		B[i] = sc.nextInt() - 1
	}
	C := make([]int, N)
	for i := 0; i < N; i++ {
		C[i] = 1
	}
	cur := f(N)
	un := NewUnionFind(N)
	ans := []int{}
	for i := M - 1; i >= 0; i-- {
		ans = append(ans, cur)
		a, b := A[i], B[i]
		if !un.isSame(a, b) {
			ra, rb := un.root(a), un.root(b)
			ca, cb := C[un.root(a)], C[un.root(b)]
			diff := f(ca+cb) - f(ca) - f(cb)
			un.unite(a, b)
			C[rb] += C[ra]
			cur -= diff
		}
	}
	for i := M - 1; i >= 0; i-- {
		fmt.Fprintln(wtr, ans[i])
	}
}

func f(n int) int {
	if n < 2 {
		return 0
	} else {
		return n * (n - 1) / 2
	}
}

type UnionFind struct {
	parent []int
}

func NewUnionFind(n int) *UnionFind {
	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = i
	}
	return &UnionFind{p}
}

func (a *UnionFind) root(x int) int {
	if a.parent[x] == x {
		return x
	} else {
		a.parent[x] = a.root(a.parent[x])
		return a.parent[x]
	}
}

func (a *UnionFind) isSame(x, y int) bool {
	return a.root(x) == a.root(y)
}

func (a *UnionFind) unite(x, y int) {
	x = a.root(x)
	y = a.root(y)
	if x == y {
		return
	} else {
		a.parent[x] = y
	}
}


Measured memory_bytes: 9728
#include <iostream>

using namespace std;
int main(void)
{
    int a, b;
    char s[15] = "bbbbbbbbbbbbbb";
    char c;

    cin >> a >> b >> s;
    int i;
    for ( i = 0; i < a; i++) {
        if (s[i] == '-') {
            cout << "No" << endl;
            return 0;
        }
    }

    if (s[i] != '-') {
        cout << "No" << endl;
        return 0;
    }

    int x;
    for (x = ++i; x < a+b+1; x++) {
        if (s[x] == '-') {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
const int MN=150000+5;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<pll> v;
template<typename T>inline T IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n;
int t[MN][2];ll w[MN][2],mn[MN],mid;
vector<pll>f[MN];
inline bool cmpx(pll a,pll b){return a.X<b.X;}
inline bool cmpy(pll a,pll b){return a.Y<b.Y;}
void merge(v &ls,v &rs,v& u){
	int sl=ls.size(),sr=rs.size();if(sl>sr)swap(ls,rs),swap(sl,sr);
	sort(ls.begin(),ls.end(),cmpy),sort(rs.begin(),rs.end(),cmpx),mn[0]=rs[0].Y;
	for(int i=1;i<sr;++i)mn[i]=min(mn[i-1],rs[i].Y);
	for(int i=0,j=sr-1;i<sl;++i){
		while(j>=0&&ls[i].Y+rs[j].X>mid)j--;
		if(j>=0)u.push_back(pll(ls[i].X,mn[j]));
	}
	sort(ls.begin(),ls.end(),cmpx),sort(rs.begin(),rs.end(),cmpy),mn[0]=rs[0].X;
	for(int i=1;i<sr;++i)mn[i]=min(mn[i-1],rs[i].X);
	for(int i=0,j=sr-1;i<sl;++i){
		while(j>=0&&ls[i].X+rs[j].Y>mid)j--;
		if(j>=0)u.push_back(pll(mn[j],ls[i].Y));
	}
}
void dfs(int u){
	if(!f[u].empty())f[u].clear();
	if(t[u][0]+t[u][1]==0)return f[u].push_back(pll(0,0)),void();
	for(int i=0,v;i<2;++i)if(v=t[u][i]){
		dfs(v);
		for(int j=0;j<f[v].size();++j)f[v][j].X+=w[u][i],f[v][j].Y+=w[u][i];
	}
	merge(f[t[u][0]],f[t[u][1]],f[u]);f[t[u][0]].clear(),f[t[u][1]].clear();
}
void input(){
	IN(n);
	for(int i=2,x;i<=n;++i){
		IN(x);
		if(t[x][0])t[x][1]=i,IN(w[x][1]);
		else t[x][0]=i,IN(w[x][0]);
	}
	ll l=0,r=1e10;
	while(l<r){
		mid=l+r>>1;dfs(1);
		if(f[1].empty())l=mid+1;
		else r=mid;
	}
	printf("%lld\n",l);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 28408
# coding: utf-8
# Your code here!

N, M = map(int, input().split(" "))
x = []
y = []
z = []

for i in range(N):
    _x, _y, _z = map(int, input().split(" "))
    x.append(_x)
    y.append(_y)
    z.append(_z)

ans = 0
a = [
    [1,1,1],
    [1,1,-1],
    [1,-1,1],
    [1,-1,-1],
    [-1,1,1],
    [-1,1,-1],
    [-1,-1,1],
    [-1,-1,-1],
    ]

for i in range(8):
    score = []
    for j in range(N):
        score.append(a[i][0]*x[j]+a[i][1]*y[j]+a[i][2]*z[j])
    score.sort(reverse=True)

    ret = 0
    for k in range(M):
        ret += score[k]
    ans = max(ans, ret)
print(ans)

Measured memory_bytes: 3188
from functools import reduce
from decimal import *
from operator import mul

def main():
    n = int(input())
    p = prime_factorize(n)
    sa = list(sorted(p))
    pp = []
    num = 1
    for i, v in enumerate(sa):
        if i > 0 and sa[i-1] != v:
            num = 1
        num *= v
        if num not in pp and n % num == 0:
            pp.append(num)
            num = 1
    print(len(pp))

def input_list():
    return list(map(int, input().split()))

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

if __name__ == '__main__':
    main()


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

string S;

int main() {
    cin >> S;

    ll sum = 0;
    for (int i = 0; i < S.length(); i++) {
        sum += S[i] - '0';
    }

    cout << ((sum % 9 == 0) ? "Yes" : "No") << endl;

    return 0;
}


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

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v,ans;

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

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

	ll n,i,m,j,k,x,y,a,b,sm=0;
	string s;
	cin >> n;
	for(i=0;i<n;i++)
		v.pb(0);
	for(i=0;i<n-1;i++)
	{
		cin >> x;
		v[i+1]=x;
		if(v[i]>x || !i)
			v[i]=x;
	}
	for(i=0;i<n;i++)
		sm+=v[i];
	cout << sm;
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

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

  int n, k;
  string s;
  cin >> n >> k;
  if((n+1)/2 >= k) cout << "YES" << endl;
  else cout << "NO" << endl;
    
  
  return 0;
}


Measured memory_bytes: 256
S = list(input())
a_flag = 0
c_flag = 0
c_count = 0
flag2 = 0
if S[0] == 'A':
    a_flag += 1
for i in range(2, len(S)-1):
    if S[i] == 'C' and i == 2:
        c_flag += 1
        c_count += 1
    elif S[i] == 'C':
        c_flag += 1
        c_count += 1
    elif S[i].isupper():
        flag2 += 1

if S[len(S) - 1].isupper() or S[1].isupper():
    flag2 += 1
if a_flag == 1 and c_flag == 1 and flag2 == 0 and c_count == 1:
    print('AC')
else:
    print('WA')

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

int main(){
     int w,a,b;
     cin >>w>>a>>b;
     if(a>b) swap(a,b);

     if (a+w>=b) {cout <<0 <<endl;
     return 0;}
     cout << b-a-w << endl;
      }

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <iostream>
#include <chrono>

using namespace std;

const int DIV = 1000000007;

int64_t gcdCalc(int64_t a, int64_t b) {
    if (a == 0 && b == 0)
        return 1;
    while (b != 0) {
        int64_t r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int64_t twoPow(int p) {
    if (p == 0)
        return 1;
    int64_t a = twoPow(p / 2);
    int64_t b = (p & 1) ? (a * 2) : a;
    return (a * b) % DIV;
}

int main(int argc, char* argv[]) {
#ifdef VLAD_LOCAL
    ifstream f("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
    istream &f = cin;
#endif
    int n;
    f >> n;
    vector<int64_t> a(n), b(n);
    vector<pair<int64_t, int64_t>> ab(n);
    map<pair<int64_t, int64_t>, int> was;
    for (int i = 0; i < n; i++) {
        f >> a[i] >> b[i];
        int64_t gcd = gcdCalc(abs(a[i]), abs(b[i]));
        ab[i].first = a[i] / gcd;
        ab[i].second = b[i] / gcd;
        pair<int64_t, int64_t> tmp(-ab[i].first, -ab[i].second);
        if (tmp < ab[i])
            ab[i] = tmp;
        auto it = was.find(ab[i]);
        if (it == was.end()) {
            was[ab[i]] = 1;
        }
        else {
            it->second++;
        }
    }
    int64_t count = 1;
    int add = 0;
    for (auto it = was.begin(); it != was.end(); it++) {
        auto p = it->first;
        int n = it->second;
        if (p.first == 0 && p.second == 0) {
            add = n;
            continue;
        }
        pair<int64_t, int64_t> opp(-p.second, p.first);
        auto tmp = make_pair(-opp.first, -opp.second);
        if (tmp < opp)
            opp = tmp;
        auto itOpp = was.find(opp);
        int64_t cur = n + 1;
        if (itOpp == was.end()) {
            cur = twoPow(n);
        }
        else {
            if (p < opp) {
                int m = itOpp->second;
                cur = twoPow(n) + twoPow(m) - 1;
                if (cur < 0)
                    cur += DIV;
            }
            else if (opp < p) {
                cur = 1;
            }
        }
        count = (count * cur) % DIV;
    }
    count--;
    if (count < 0)
        count += DIV;
    count = (count + add) % DIV;
    printf("%lld\n", count);
    
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf\n", seconds);
#endif
	return 0;
}


Measured memory_bytes: 21924
N,K=map(int,input().split())
L=list(map(int,input().split()))
ans=float("inf")
for i in range(N-K+1):
	ans=min(ans,(abs(0-L[i])+abs(L[i]-L[i+K-1])),(abs(0-L[i+K-1])+abs(L[i]-L[i+K-1])))
print(ans)

Measured memory_bytes: 14252
#include<iostream>
#include <stdlib.h>

using namespace std;

  string s[100];
  int p[100];
  int no[100];
int cmp(const void *a, const void *b) {
  int ia = *(int*)a;
  int ib = *(int*)b; 

  int sc = s[ia].compare(s[ib]);
  if(sc != 0) return sc;
  return p[ib] - p[ia];
}


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

  for(int i = 0 ; i < n ;i++) {
    cin >> s[i] >> p[i];
    no[i] = i;
  }


  qsort(no, n, sizeof(int), cmp);

  for(int i = 0 ; i < n;i++) {
    cout << no[i]+1 << endl;
  }
}


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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int judge;
		int a[3];
		cin >> a[0] >> a[1] >> a[2];
		sort(a, a+3);
		judge = a[2] * a[2] - (a[0] * a[0] + a[1] * a[1]);
		if(!judge){ 
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

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

	ll ans = 0;

	for (int i = 1; i <= n; i++) {
		string s = to_string(i);
		if (s.size() % 2 == 1) {
			ans++;
		}
	}

	cout << ans << endl;
}


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

int main(){
    int a,b,c,tmp;
    cin >> a >> b;
    if(b/100==0){
        if(b/10==0){
            c=a*10+b;
        }
        else c=a*100+b;
    }
    else c=a*1000+b;
    tmp = sqrt(c);
    if(c==tmp*tmp)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
  int D, G;
  cin >> D >> G;
  vector<int> P(D), C(D);
  rep(i, D) cin >> P.at(i) >> C.at(i);
  int ans = 1000000;
  
  for(int tmp = 0; tmp < (1 << D); tmp++){
    bitset<10> s(tmp);
    int sum=0, n=0, rest_max = -1;
    
    for(int i = 0; i < D; i++){
      if(s.test(i)){
        n += P.at(i);
        sum += P.at(i)*100*(i+1) + C.at(i);
      } else {
        rest_max = i;
      } 
    }
    
    if(sum < G){
      int s1 = 100*(rest_max + 1);
      int need = (G - sum +s1 -1)/s1;
      if(need >= P.at(rest_max)) continue;
      n += need;
      
    }
    ans = min(ans, n);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll fact_two[1111111];
ll initialised = false;
ll comb_mod_two(ll n, ll r){
	if(n < r)return 0;
	if(!initialised){
		for(int i = 1;i < 1111111;i++){
			fact_two[i] = fact_two[i-1];
			ll now = i;
			while(now % 2 == 0){
				fact_two[i]++;
				now /= 2;
			}
		}
		initialised = true;
	}

	ll a = fact_two[n];
	ll b = fact_two[n-r] + fact_two[r];
	if(a > b)return 0;
	else return 1;
}

bool seica(vector<ll> v){
	ll n = v.size();
	ll cou = 0;
	REP(i, n){
		cou += v[i] * comb_mod_two(n-1, i);
		cou %= 2;
	}
	return cou;
}

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

	ll n;cin >> n;
	string str;cin >> str;

	vector<ll> v;
	REP(i, n)v.PB(str[i] - '1');

	if(seica(v)){
		cout << 1 << endl;
		return 0;
	}

	REP(i, n){
		if(v[i] == 1){
			cout << 0 << endl;
			return 0;
		}
		v[i] /= 2;
	}

	if(seica(v)){
		cout << 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}


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

using namespace std;

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for(int i = 0; i < A.size(); i++) {
    cin >> A[i];
  }
  
  map<int, int> m;
  vector <int> SUM(N + 1);
  SUM[0] = 0;
  for(int i = 0; i < N; i++) {
    SUM[i + 1] = (SUM[i] + A[i]) % M;
  }

  long long ans = 0;
  for(int i = 0; i < SUM.size(); i++) {
    ans += m[SUM[i]];
    m[SUM[i]]++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3968
#include <cstdio>
#include <cstring>
#include <algorithm>
#define P 1000000007

using namespace std;

typedef long long ll;

ll h[111], Mn[111][111], Sm[111][111], SS[111][111], n;

ll F[111];

ll powmod(ll x, ll y = P - 2, ll p = P) {
    ll ans = 1;
    while(y) {
        if(y & 1) ans = ans * x % p;
        x = x * x % p;
        y >>= 1;
    }
    return ans;
}

ll calc(ll a, ll q, ll n) {
    return (powmod(2, a + q * n) - powmod(2, a)) * powmod(powmod(2, q) - 1) % P;
}

int main() {
    scanf("%lld", &n);
    for(int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    h[0] = (h[n + 1] = 1);
    for(int i = 1; i <= n; i++) {
        Mn[i][i] = h[i], Sm[i][i] = h[i], SS[i][i] = h[i];
        for(int j = i + 1; j <= n; j++) Mn[i][j] = min(Mn[i][j - 1], h[j]), Sm[i][j] = Sm[i][j - 1] + h[j], SS[i][j] = SS[i][j - 1] + max(h[j] - h[j - 1], 0ll);
    }
    F[0] = 1;
    for(int i = 1; i <= n; i++) {
        F[i] = F[i - 1] * 2 % P;
        for(int j = 1; j <= i; j++) {
            int r = Mn[j][i], l = max(h[i + 1], h[j - 1]) + 1;
            if(l <= r) F[i] = (F[i] + 2 * F[j - 1] * calc(SS[j][i] - r, 1, r - l + 1)) % P;
        }
    }
    printf("%lld\n", (F[n] % P + P) % P);
    return 0;
}


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

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N, A, B;
    io.read(N, A, B);
    int ans = 0;
    for(int i = 1; i <= N; i++){
        int dsum = 0;
        string s = to_string(i);
        for(int j = 0; j < s.size(); j++){
            dsum += s[j] - '0';
        }
        if(dsum >= A && dsum <= B) ans += i;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#import <Foundation/Foundation.h>
int main() {
	long n;
	scanf("%ld",&n);
	long ans=0, prev=0, s=0;
	for(long i=0;i<n;i++){
		long h;
		scanf("%ld",&h);
		if(prev<h) s=i;
		ans=MAX(ans,i-s);
		prev=h;
	}
	printf("%ld\n",ans);
}

Measured memory_bytes: 7120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  int C, C1 = 0;
  
  for(int i = N.size() - 1, c = 0; i >= 0; i--, c++){
    C += N[i] - 48;
    C1 += (N[i] - 48) * std::pow(10, c);
  }
  
  if( (C1 % C) == 0){
    cout << "Yes" << endl;
  }else
    cout << "No" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pp pair<int,int>
#define MZ 1000000007
#define pq priority_queue
using namespace std;
long long init[100005];
long long dp[100005][2];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    init[1]=1;
    for(int i=2;i<=100000;i++)
        init[i]=(init[i-1]*i)%MZ;
    if(n==m)
        printf("%lld\n",(init[n]*init[m]*2)%MZ);
    else
    {
        if(abs(n-m)==1)
            printf("%lld\n",(init[n]*init[m])%MZ);
        else
            printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = [int(n) for n in input().split()]

from fractions import gcd
L = [0]*(N+1)
R = [0]*(N+1)
ans = 0
for i in range(N):
    L[i] = gcd(L[i-1],A[i])
for i in reversed(range(N)):
    R[i] = gcd(R[i+1],A[i])

for i in range(N):
    if gcd(L[i-1],R[i+1]) > ans:
        ans = gcd(L[i-1],R[i+1])
print(ans)

Measured memory_bytes: 14052
n,m,x,y = map(int,input().split())
li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))
flag = False
for z in range(x+1,y+1):
    if all([i < z for i in li1]) and all([i >= z for i in li2]):
        flag = True
        #print(z)
        break
        
if flag == True:       
    print("No War")
else:
    print("War")

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

int main()
{
    string word;
    stack<int> S;
    while (cin >> word) {
        if (word == "+") {
            int a = S.top(); S.pop();
            int b = S.top(); S.pop();
            S.push(a + b);
        }
        else if (word == "-") {
            int a = S.top(); S.pop();
            int b = S.top(); S.pop();
            S.push(b-a);
        }
        else if (word == "*") {
            int a = S.top(); S.pop();
            int b = S.top(); S.pop();
            S.push(a*b);
        }
        else {
            S.push(atoi(word.c_str()));
        }
    }
    cout << S.top() << endl;
    return 0;
}

Measured memory_bytes: 1200
str = input()
n = int(str.split()[0])

p = []
pS = input()
for i in range(n) :
	p.append(int(pS.split()[i]))
	
a = 0
for i in range(len(p) - 2) :
	if (p[i] < p[i+1]) :
		if (p[i + 1] < p[i + 2]) :
			a+=1
	elif(p[i] > p[i + 1]) :
		if (p[i + 1] > p[i + 2]) :
			a+=1

print(a)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=1e17;
const ll ms=(5e5)+5;

int ar[ms];

int main()
{
    idfc;


    int n;
    cin>>n;
    int i;
    ar[0]=0;
    char e;

    for(i=1;i<=n;i++)
    {
        cin>>e;
        ar[i]=ar[i-1];
        if(e=='R')ar[i]++;
    }
    int a,b;
    int p;
    int ans=n;
    for(i=0;i<=n;i++)
    {
        a=i-ar[i];
        b=ar[n]-ar[i];
        p=min(a,b);
        ans=min(ans,p+(max(a,b)-p));
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
int main(){
    int S,a,b;
    cin >> S;
    a = S/100;
    b = S%100;
    if(a!=0 && a<=12){
        if(b!=0 && b<=12)cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else{
        if(b!=0 && b<=12)cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string s;
    cin >> s;

    int n1 = 0;
    rep(i, s.size()) {
        int c = i % 2 == 0 ? '0' : '1';
        if (s[i] != c) n1++;
    }
    int n2 = 0;
    rep(i, s.size()) {
        int c = i % 2 == 0 ? '1' : '0';
        if (s[i] != c) n2++;
    }

    put(min(n1, n2));

    return 0;
}

Measured memory_bytes: 3764
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int AA[SIZE];
int main(){
    int N,M;
    R(N,M);
    PII an;
    REP(i,M){
        int x;
        string s;
        R(x,s);
        if(s=="WA"){
            if(AA[x]<=0)AA[x]--;
        }
        else{
            if(AA[x]<=0){
                an.F++,an.S-=AA[x];
                AA[x]=1;
            }
        }
    }
    W(an);
    return 0;
}


Measured memory_bytes: 640
// DPL_5_A: Count the number of ways to put
// n distinguishable balls in
// k distinguishable boxes
//
// -> Sum over 1 <= j <= K of j! * S(n,j) * C(k, j)

#include <iostream>
using ll = long long;
ll S[1001][1001];
ll C[1001][1001];
ll M = 1e9 + 7;

int main() {
  int N, K;
  std::cin >> N >> K;

  S[0][0] = 1;
  for (int k = 1; k <= K; ++k)
    for (int n = k; n <= N; ++n)
      S[n][k] = (S[n - 1][k - 1] + k * S[n - 1][k]) % M;

  for (int n = 0; n <= K; ++n)
    C[n][0] = 1;
  for (int k = 1; k <= K; ++k)
    for (int n = k; n <= K; ++n)
      C[n][k] = (C[n - 1][k - 1] + C[n - 1][k]) % M;

  ll res = 0;
  ll F = 1;
  for (int j = 1; j <= K; ++j) {
    F = (F * j) % M;
    res = (res + ((((F * S[N][j]) % M) * C[K][j]) % M)) % M;
  }
  std::cout << res << "\n";
}


Measured memory_bytes: 16852
N = int(input())
RC = [0] * N
for i in range(N):
  RC[i] = list(map(int, input().split()))
  
dp = [[float("inf")] * (N + 1) for _ in range(N + 1)]
for l in range(N + 1):
  for r in range(l, N + 1):
    if abs(l - r) <= 1:
      dp[l][r] = 0
    elif abs(l - r) == 2:
      dp[l][r] = RC[l][0] * RC[l][1] * RC[l + 1][1]
      
#print(dp)
#print("")
now = 3
while now <= N:
  for l in range(N + 1):
    #print(l, now)
    r = l + now
    if r <= N:
      for k in range(l + 1, r):
        dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + RC[l][0] * RC[k][0] *RC[r - 1][1])
  now += 1
        
print(dp[0][N])  



Measured memory_bytes: 5728
#include <stdio.h>
int yu(int a,int b);

int main(void){
	int n,i,max=0;
	scanf("%d",&n);
	int all[n];
	int h[n+1];
	int m[n+1];
	h[0] = 0; m[n] = 0;
	for(i=0;i<n;i++) scanf("%d",&all[i]);
	for(i=0;i<n;i++) h[i+1] = yu(h[i],all[i]);
	for(i=n-1;i>=0;i--) m[i] = yu(m[i+1],all[i]);
	
	for(i=0;i<n;i++){
		if(yu(h[i],m[i+1])>=max) max = yu(h[i],m[i+1]);
	}
	printf("%d\n",max);
	return 0;
}
int yu(int a,int b){
	if(a==0) return b;
	else return yu(b%a,a);
}


Measured memory_bytes: 1280
N,M=map(int,input().split())
A=[list(input()) for _ in range(N)]
B=[list(input()) for _ in range(M)]

def match(ii,jj):
  res=1
  for i in range(M):
    if A[i+ii][jj:jj+M]!=B[i]:
      res=0
      break
  return res

ans="No"
for i in range(N-M+1):
  for j in range(N-M+1):
    if match(i,j)==1:
      ans="Yes"
      break
  else:
    continue
  break

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <queue>
#include <bits/stdc++.h>
#include <stack>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

int main(){
  int N,A,B;
  cin >> N >> A >> B;

  int a[1000];
  int cnt = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    if(a[i]>=A&&a[i]<B){
    }
    else
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256