akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long g = a;
    if(b != 0){
        g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return g;
}

long long mod_inverse(long long a, long long m)
{
    long long x, y;
    extgcd(a, m, x, y);
    return (x % m + m) % m;
}

const int MOD[] = {1000000007, 1000000009};
const int BASE = 131;
const int BASE_INV[] = {mod_inverse(BASE, MOD[0]), mod_inverse(BASE, MOD[1])};

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

    vector<vector<long long> > power(2, vector<long long>(n+1, 1));
    for(int i=0; i<2; ++i){
        for(int j=1; j<=n; ++j){
            power[i][j] = power[i][j-1] * BASE;
            power[i][j] %= MOD[i];
        }
    }

    string s;
    cin >> s;

    int a = 0;
    int b = 0;
    long long hash[] = {s[0], s[0]};

    set<pair<long long, long long> > sub;
    for(int i=0; i<m; ++i){
        string q;
        cin >> q;

        if(q == "L++"){
            for(int j=0; j<2; ++j){
                hash[j] -= s[a];
                hash[j] *= BASE_INV[j];
            }
            ++ a;
        }else if(q == "L--"){
            -- a;
            for(int j=0; j<2; ++j){
                hash[j] *= BASE;
                hash[j] += s[a];
            }
        }else if(q == "R++"){
            ++ b;
            for(int j=0; j<2; ++j)
                hash[j] += power[j][b-a] * s[b];
        }else{
            for(int j=0; j<2; ++j)
                hash[j] -= power[j][b-a] * s[b];
            -- b;
        }

        for(int j=0; j<2; ++j){
            hash[j] %= MOD[j];
            hash[j] += MOD[j];
            hash[j] %= MOD[j];
        }

        sub.insert(make_pair(hash[0], hash[1]));
    }

    cout << sub.size() << endl;

    return 0;
}

Measured memory_bytes: 24840
#coding: utf-8
N = int(input())
a = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]))
    dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]))
print(dp[N-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
const auto MOD = 998244353;
int main() {
    int n;
    cin >> n;
    auto counts = vector<int>(n, 0);
    int c;
    cin >> c;
    if (c != 0) {
        cout << 0 << endl;
        return 0;
    }
    counts[0] = 1;
    rep(i, n - 1) {
        int d;
        cin >> d;
        counts[d]++;
    }
    auto iterator = counts.end();
    iterator--;
    while (*iterator == 0) {
        counts.erase(iterator);
        iterator = counts.end();
        iterator--;
    }
    if (counts[0] > 1 || count(ALL(counts), 0) > 0) {
        cout << 0 << endl;
        return 0;
    }
    long long ans = 1;
    reps(i, counts.size() - 1) {
        auto x = counts[i - 1];
        auto y = counts[i];
        rep(j, y) {
            ans *= x;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
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 VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n){
    string x;
    cin >> x;
    sort(x.begin(), x.end());
    s[i] = x;
  }
  
  sort(s.begin(), s.end());
  
  ll ans=0, cons=0;
  string t=s[0];
  rep(i,n-1){
    if(s[i+1] == t){
      cons++;
    }else{
      ans += cons*(cons+1)/2;
      cons = 0;
      t = s[i+1];
    }
  }
  
  if(cons>0){
    ans += cons*(cons+1)/2;
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 5760
a, b, c, x, y = map(int, input().split())
if c <= (a/2) and c <= (b/2):
    print(c*max(x, y)*2)
elif c <= (a + b) / 2:
    if x <= y:
        if b > 2*c:
            print(c*x*2+2*c*(y-x))
        else:
            print(c*x*2+b*(y-x))
    else:
        if a > 2*c:
            print(c*y*2+2*c*(x-y))
        else:
            print(c*y*2+a*(x-y))
else:
    print(a*x+b*y)

Measured memory_bytes: 9144
while True:
    try:
        text = input()
    except:
        break
    
    joi = 0
    ioi = 0
   
    while len(text)>2:
        textlist = list(text)
        judgetext = ''.join(textlist[0:3])
        x = judgetext.find('JOI')
        y = judgetext.find('IOI')
        
        if x==-1 and y==-1:
            pass
        if x==0:
            joi += 1
        if y==0:
            ioi += 1
        
        del(textlist[0])
        text = ''.join(textlist)
    
    print(joi)
    print(ioi)


Measured memory_bytes: 5676
# LCSとその復元
S = input()
T = input()

# 最長共通部分列の長さを求める
dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]

for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:  # 今見ている文字が等しいのであれば斜めに移動する
            dp[i+1][j+1] = dp[i][j]+1
        else:  # 異なるのであれば、上または左の値の大きい方をコピーする
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
# print(dp)
ans = ''
n = len(S)
m = len(T)
while n != 0 and m != 0:  # どちらかが先頭まで来たら終わり
    if dp[n][m] == dp[n-1][m]:  # Sのn文字目が関係ない文字ならn-1文字目を見にいく
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        # 斜めから移動されているところに注目する
        n -= 1
        m -= 1
        # 前に追加していくからこう書く
        ans = S[n] + ans
print(ans)


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

#[allow(dead_code)]
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")
}

#[allow(dead_code)]
fn pow_mod(base: i64, power: i64, modulo: i64) -> i64 {
    let mut base = base;
    let mut power = power;
    let mut ans = 1;
    while power > 0 {
        if power & 1 == 1 {
            ans = ans * base % modulo;
        }
        power >>= 1;
        base = base * base % modulo;
    }
    ans
}

#[allow(dead_code)]
fn inv_mod(a: i64, modulo: i64) -> i64 {
    pow_mod(a, modulo - 2, modulo)
}

const MOD: i64 = 1e+9 as i64 + 7;
const FACT_MAX: usize = 1000010;
static mut FACTORIAL: [i64; FACT_MAX + 1] = [0; FACT_MAX + 1];
static mut RFACTORIAL: [i64; FACT_MAX + 1] = [0; FACT_MAX + 1];
fn init_fact() {
    unsafe {
        if FACTORIAL[0] == 0 {
            FACTORIAL[0] = 1;
            for i in 1..FACT_MAX + 1 {
                FACTORIAL[i] = (FACTORIAL[i - 1] * i as i64) % MOD;
            }
            RFACTORIAL[FACT_MAX] = inv_mod(FACTORIAL[FACT_MAX], MOD);
            for i in (0..FACT_MAX).rev() {
                RFACTORIAL[i] = RFACTORIAL[i + 1] * (i as i64 + 1) % MOD;
            }
        }
    }
}
#[allow(dead_code)]
fn fact(n: usize) -> i64 {
    init_fact();
    unsafe { FACTORIAL[n] }
}
#[allow(dead_code, unused_comparisons)]
fn combi(n: usize, m: usize) -> i64 {
    if n < m || m < 0 {
        return 0;
    }
    init_fact();
    unsafe { FACTORIAL[n] * RFACTORIAL[m] % MOD * RFACTORIAL[n - m] % MOD }
}

fn main() {
    init_fact();
    let x = read::<usize>();
    let y = read::<usize>();
    let mut ans = 0;
    for dx in 0..x + 1 {
        let rx = x - dx;
        if 2 * dx > y {
            continue;
        }
        let dy = y - 2 * dx;
        if dy * 2 != rx {
            continue;
        }
        ans = (ans + combi(dx + dy, dy)) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 17700
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N = II()
    A = LMIIS()
    num_buka = defaultdict(int)
    for a in A:
        num_buka[a] += 1
    for i in range(1,N+1):
        print(num_buka[i])


if __name__ == '__main__':
    main()

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  for (int i = 0; i < n; i++) cin >> m[i];
  int y = 0, ld = 1001;//yは全部を1つ作った時の重さ,ldは最軽ドーナツの重さ
  for (int i: m) {
    y += i;
    ld = min(ld, i);
  }
  int ldnum = (x - y) / ld;//あと全部ldを作るので追加分のldの数
  int num = n + ldnum;
  cout << num;
}

Measured memory_bytes: 3572
#include<iostream>
#include<vector>

int main(){
  int n,k;
  long long int ans=-1000000000;
while(true){
  std::cin>>n>>k;
if(n==0&&k==0)break;
  std::vector<long long int>vec(n+1,0);
  long long int sub;
  for(int i=1;i<=n;i++){
    std::cin>>sub;
    vec.at(i)=vec.at(i-1)+sub;
  }
  for(int i=n;i>=k;i--){
    ans=std::max(vec.at(i)-vec.at(i-k),ans);
  }
  std::cout<<ans<<std::endl;
}
  return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

bool vis[1005][1005];
bool vis2[1005][1005];

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


deque<pair<pi, int>> q;
void cp()
{
    int n, m, sx, sy, ex, ey;
    cin >> n >> m >> sx >> sy >> ex >> ey;
    sx--, sy--, ex--, ey--;
    vector<string> arr(n);
    for(string &x : arr)
        cin >> x;

    int ans = INT_MAX;
	// 0/1 BFS
    if(arr[sx][sy] != '#')
        q.push_back({{sx, sy}, 0});

    while(!q.empty())
    {
        auto node = q.front();
        q.pop_front();
        int x = node.ff.ff, y = node.ff.ss, d = node.ss;
        vis[x][y] = vis2[x][y] = true;

        if(x == ex && y == ey)
        {
            ans = min(ans, d);
            continue;
        }
        // move A
        for(int i = 0; i < 4; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] && arr[nx][ny] == '.')
                q.push_front({{nx, ny}, d}), vis[nx][ny] = true;
        }

        // moveB
        for(int i = -2; i <= 2; i++)
        {
            for(int j = -2; j <= 2; j++)
            {
                if(!i && !j)
                    continue;
                int nx = x + i, ny = y + j;
                if(nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] && !vis2[nx][ny] && arr[nx][ny] == '.')
                    q.push_back({{nx, ny}, d + 1}), vis2[nx][ny] = true;
            }
        }
    }
    
    if(ans == INT_MAX)
        cout << -1;
    else
        cout << ans;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

ll gcd(ll x, ll y) {
  if(y == 0) return x;
  else return gcd(y, x%y);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  
  ll n = gcd(a, b);
  
  cout << a*b/n << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    cin >> S;
    for (int i = 0; i < N; i++) {
        string tmp = S.substr(i, 3);
        if (tmp == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
#define re register
#define ll long long
#define int ll
#define ull unsigned long long
#define rep(i,a,b) for(re int i=a;i<=b;++i)
#define per(i,a,b) for(re int i=a;i>=b;--i)
template<typename T>
inline void read(T&x)
{
	x=0;
	char s=(char)getchar();
	bool f=false;
	while(!(s>='0'&&s<='9'))
	{
		if(s=='-')
			f=true;
		s=(char)getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=(x<<1)+(x<<3)+s-'0';
		s=(char)getchar();
	}
	if(f)
		x=(~x)+1;
}
template<typename T>
inline void clear(T*a,int l,int r,int val)
{
	memset(&a[l],val,sizeof(T)*(r-l+1));
}
const int N=1e6+5;
int n;
ll a[N];
signed main()
{
	int n;
	read(n);
	int ans = 0;
	for(int i = 2 ; 1ll * i * i <= n ; i ++)
	{
		if(n % i == 0)
		{
			int cnt = 0 , now = 1;
			while(n % i == 0)
			{
				n /= i ;
				cnt ++ ;
				if(cnt == now)
					++ans, ++ now, cnt = 0;
			}
		}
	}
	if(n > 1) ++ans;
	printf("%lld\n",ans);
	return 0;
}



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

int main() {
  int N, M, C;
  int A[21][21] = {0};
  int B[21] = {0};
  int count;
  int right = 0;
  
  cin >> N >> M >> C;
  
  for (int i = 0; i < M; ++i) {
    cin >> B[i];
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> A[i][j];
    }
  }
  
  for (int i = 0; i < N; ++i) {
    count = 0;
    for (int j = 0; j < M; ++j) {
      count += A[i][j] * B[j];
    }
    count += C;
    if (count > 0) {
      right++;
    }
  }
  
  cout << right << endl;
  
  return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define TMP 1000000007

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

int n, m;
char a[50][50], b[50][50];

bool solve(int x, int y) {
	rep(i, m) rep(j, m) {
		if(a[x + i][y + j] != b[i][j]) return false;
	}
	return true;
}

int main() {
	scanf("%d %d", &n, &m);
	rep(i, n) rep(j, n) cin >> a[i][j];
	rep(i, m) rep(j, m) cin >> b[i][j];
	rep(i, n) rep(j, n) {
		if(solve(i, j)) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005
typedef struct pp{
	char name[10];
	int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P);
P dequeue();
int min(int,int);


int main(void){
	int elaps=0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
		
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1,tail=n+1;
	
	while(head!=tail){
		u=dequeue();
		c=min(q,u.t);
		u.t -= c;
		elaps += c;
		if(u.t>0){
			enqueue(u);
		}else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	
	
	return 0;
}

void enqueue(P x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
}

P dequeue(){
	P x=Q[head];
	head=(head+1)%LEN;
	return x;
}
int min(int a,int b){
	if(a<b){
		return a;
	}else{
		return b;
	}
}

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

int N, M, Q;
int ans = 0;
vector<int> a, b, c, d;

void func(int n, vector<int> A, int last) {
  if (n == N) {
    bool ok = true;
    for (int i = 1; i < N; i++) {
      if (A.at(i-1) > A.at(i)) ok = false;
    }
    if (false) return;
    int tmp = 0;
    for (int i = 0; i < Q; i++) {
      if (A.at(b.at(i)-1) - A.at(a.at(i)-1) == c.at(i)) tmp += d.at(i);
    }
    ans = max(ans, tmp);
    return;
  }
  for (int i = last; i <= M; i++) {
    A.at(n) = i;
    func(n+1, A, i);
  }
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }
  vector<int> A(N, 0);
  func(0, A, 1);
  cout << ans << endl;
}

Measured memory_bytes: 3632
use std::str::FromStr;

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

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<i32> = get_vec();
    println!("{}", (v[0]-1) * (v[1]-1));
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int main(){
	ll n;
	cin>>n;
	ll s=1000-n%1000;
	cout<<s%1000<<endl;
}


Measured memory_bytes: 3676
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n,W = inpm()
    v = [[] for _ in range(4)]
    w0 = 0
    for i in range(n):
        wv = inpl()
        if i == 0:
            w0 = wv[0]
        v[ wv[0]-w0 ].append(wv[1])
    for i in range(4):
        v[i] = sorted(v[i])
        v[i].reverse()
        vv = [0 for _ in range(len(v[i])+1)]
        for j in range(len(v[i])):
            vv[j+1] = vv[j] + v[i][j]
        v[i] = vv
    ans = 0
    for n1 in range(len(v[0])):
        for n2 in range(len(v[1])):
            for n3 in range(len(v[2])):
                for n4 in range(len(v[3])):
                    if W < w0*(n1+n2+n3+n4) + n2 + n3*2 + n4*3:
                        continue
                    ans = max(ans,v[0][n1]+v[1][n2]+v[2][n3]+v[3][n4])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 42476
list1 = input().split(' ')
list2 = input().split(' ')
list2 =  [int(s) for s in list2]

num = int(list1[1])
HP = int(list1[0])
D = 0
for N in list2:
  D += N

if D >= HP:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 13836
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int dp[201][201] = {0};

int gcd(int a, int b){
	if(dp[a][b] != 0) return dp[a][b];
	if(dp[b][a] != 0) return dp[b][a];
    if(b == 0) {
		dp[a][b] = a;
		dp[b][a] = a;
		return a;
	}
	dp[a][b] = gcd(b, a%b);
	dp[b][a] = gcd(b, a%b);
    return gcd(b, a%b);
}

int main() {
	cin >> K;
	ll _sum = 0;
	rep(i, K){
		rep(j, K){
			rep(k, K){
				_sum += gcd(i+1, gcd(j+1, k+1));
			}
		}
	}
	cout << _sum;
}


Measured memory_bytes: 3748
#include<iostream>
using namespace std;
int main(){
	int H,W,i,j;
	for(;;){
		cin>>H>>W;
		if(H==0&&W==0){
		break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(i==0||i==H-1||j==0||j==W-1){
					cout<<"#";
				}else{
					cout<<".";
				}
			}
			cout<<endl;
		}
			cout<<endl;
	}
	return 0;
}

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536870912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// bit: &/and, |/or, ^/xor, ~/not

#define	MOD 1000000007

int	main() {
	long N, M;
	cin >>N >>M;
	if (M<=2*N) {
		cout <<M/2 <<endl;
		return 0;
	}
	cout <<N+(M-2*N)/4 <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
int main(){
    int N, Q;
    cin >> N >> Q;
    dsu U(N);
    for(int i = 0; i < Q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0) U.merge(u, v);
        else{
            if(U.same(u, v)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 3944
#include <cstdio>
#ifdef _MSC_VER
#define GC getchar
#else
#define GC getchar_unlocked
#endif
int input()
{
	int x=0;
	char c;
	bool minus=false;
	for(;;)
	{
		c=GC();
		if (c=='-')
		{
			minus=true;
			continue;
		}
		if (c==' '||c=='\n')
			if (minus)
				return -x;
			else
				return x;
		x=10*x+c-'0';
	}
}
void fix()
{
	char c;
	for(;;)
	{
		c=GC();
		if (c==-1||c!=' '&&c!='\n')
			break;
	}
	if (c!=-1)
		ungetc(c,stdin);
}
int main()
{
	int N,i,j,k,d=2;
	int a[6];
	int m[32];
	int M[32];
	for (i=0; i<32; i++)
	{
		m[i]=1000000000;
		M[i]=-1000000000;
	}
	scanf("%d",&N);
	fix();
	for (i=0; i<N; i++)
	{
		for (j=0; j<d; j++)
			a[j]=input();//,fix();
		for (j=0; j<1<<(d-1); j++)
		{
			int x=a[0];
			for (k=0; k<d-1; k++)
				if (j&(1<<k))
					x+=a[k+1];
				else
					x-=a[k+1];
			if (m[j]>x)
				m[j]=x;
			if (M[j]<x)
				M[j]=x;
		}
	}
	int ans=0;
	for (i=0; i<1<<(d-1); i++)
		if (ans<M[i]-m[i])
			ans=M[i]-m[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1736
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

queue<int>a[1010];
int step[1010];

int main(void){
    int n,m,x;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            cin>>x;
            a[i].push(x-1);
        }
    }
    m=n*(n-1)/2;
    queue<int> que;
    for(int i=0;i<n;i++)que.push(i);
    int num=0;
    int l=0;
    while(que.size()){
        int ok=0;
        queue<int>q2;
        while(que.size()){
            l=que.front();
            que.pop();
            if(step[l]<=num && a[l].size() &&
            a[a[l].front()].front()==l && step[a[l].front()]<=num){
                step[l]=num+1;
                step[a[l].front()]=num+1;
                q2.push(l);
                q2.push(a[l].front());
                a[a[l].front()].pop();
                a[l].pop();
                m--;
            }
        }
        num++;
        if(m==0)break;
        swap(que,q2);
    }
    if(m)cout<<-1<<endl;
    else cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 4736
K = int(input())
A, B = map(int, input().split())

a, mod_a = divmod(A, K)
b, mod_b = divmod(B, K)

if mod_a == 0 or mod_b == 0:
    print('OK')
    exit()

if a == b:
    print('NG')
else:
    print('OK')


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  a < b < c
  a + b > c -> c < a+b
  b + c > a -> c > a-b
  c + a > b -> c > b-a
  }*/

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

  vi l(n);
  rep(i, 0, n) cin >> l[i];

  sort(all(l));
  l.emplace_back(inf);

  int ans = 0;
  rep(i, 0, n-1) rep(j, 0, i){
    int a = l[j];
    int b = l[i];
    int t = (lower_bound(all(l), a+b)-l.begin())-i-1;
    ans += t;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int D;
  int N;
  int w = 1;
  cin >> D >> N;
  
  if(D == 0 && N == 100){
    cout << 101 << endl;
  }
  else if(D == 1 && N == 100){
    cout << 10100 << endl;
  }
  else if(D == 2 && N == 100){
    cout << 1010000 << endl;
  }else{
    for(int k = 0;k < D;k++){
      w *= 100;
    }
    cout << w * N << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
   ll n;
   cin >> n;
   vector<ll> l(87);
   l[0] = 2;
   l[1] = 1;
   for(ll i = 2; i<=n; ++i) {
     l[i] = l[i-1] + l[i-2];
   } 
   cout << l[n] << endl;
  return 0;
}

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

W = []
Se = set()
for i in range(N):
  st = input()
  W.append(st)
  Se.add(st)
  
if len(Se) != N:
  print("No")
  exit(0)

for i in range(N-1):
  if W[i][-1] != W[i+1][0]:
    print("No")
    exit(0)

print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a1,a2,a3,a4,a5,a6;
	cin>>a1>>a2>>a3>>a4>>a5>>a6;
	if(a3==a4 and a5==a6)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

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

int main() {
  long a;
  cin >> a;
  
  long mx = 1;
  for (long i = 1; i * i <= a; ++i) {
    if (a % i == 0) {
      mx = max(mx, i);
    }
  }
  
  cout << (mx + a / mx - 2) << endl;
}

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

vector< pair<i64, i64> > res;
i64 x;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    res.eb(mp(-1, -1));
    for (i64 i = -2;; --i) {
        i64 temp = i*i*i*i*i;
        if (temp < -(i64)1e11) break;
        res.eb(mp(temp, i));
    }
    res.eb(mp(0, 0));
    res.eb(mp(1, 1));
    for (i64 i = 2;; ++i) {
        i64 temp = i*i*i*i*i;
        if (temp > (i64)1e11) {
            break;
        }
        res.eb(mp(temp, i));
    }
    //cout << SZ(res) << endl;
    cin >> x;
    for (int i = 0; i < SZ(res); ++i) {
        for (int j = 0; j < SZ(res); ++j) {
            if (res[i].fi - res[j].fi == x) {
                cout << res[i].se << ' ' << res[j].se << '\n';
                return 0;
            }
        }
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector < ll > vec;
ll dp[200005],ara[200005],n,m,mod=(1e9)+7;



int main()
{
    ll i,j,k,a,b,c,x=-1,y,z;
    cin>>n;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&ara[i]);
        if(x!=ara[i])
            vec.push_back(ara[i]);
        x=ara[i];

    }
    dp[x]=1;
    for(i=vec.size()-1;i>0;i--)
    {
        x=vec[i-1];
        y=vec[i];
        if(dp[y]==0)
            dp[y]=1;
        dp[x]+=dp[y];
        //cout<<x<<" "<<dp[x]<<endl;
        dp[x]%=mod;
    }
    //vec[x].push_back(y);
    //a=op(0);
    cout<<dp[vec[0]]%mod<<endl;

}


Measured memory_bytes: 5104
use std::collections::VecDeque;
use std::io::stdin;

const INF: usize = 1 << 30;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let n: usize = itr.next().unwrap();
    let m = itr.next().unwrap();
    let mut edge = vec![vec![]; 200002];

    for _ in 0..m {
        s.clear();
        stdin().read_line(&mut s).ok();
        let mut itr = s.split_whitespace().map(|e| e.parse::<usize>().unwrap());
        let a = itr.next().unwrap() - 1;
        let b = itr.next().unwrap() - 1;
        edge[a].push(b);
        edge[b].push(a);
    }

    let mut queue = VecDeque::new();
    let mut ans = vec![INF; n];
    queue.push_back(0);
    while !queue.is_empty() {
        let now = queue.pop_front().unwrap();

        for &e in edge[now].iter() {
            if ans[e] == INF {
                ans[e] = now;
                queue.push_back(e);
            }
        }
    }

    if ans.iter().any(|&e| e < INF) {
        println!("Yes");
        for e in ans.iter().skip(1) {
            println!("{}", e + 1);
        }
    } else {
        println!("No");
    }
}


Measured memory_bytes: 14284
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a;
    double all = 0;
    vector<ll> as = {};

    while (cin >> a)
    {
        as.push_back(a);
        all += a;
    }

    sort(as.begin(), as.end());
    reverse(as.begin(), as.end());

    auto cnt = 0;
    for (auto i = 0; i < m; i++)
    {
        if (as[i] >= (all / (4 * m)))
        {
            cnt++;
        }
    }

    if (cnt == m)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
C = []*2*N
for i in range(N):
    a,b = map(int,input().split())
    C.append(b)
    C.append(a)
D = np.array(C).reshape(N,2).tolist()
D.sort()
time = 0
flag = 1
for i in range(len(D)):
    if time + D[i][1] > D[i][0]:
        flag = 0
        break
    else:
        time += D[i][1]

if flag == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61364
n=int(input())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append([x,y])
f=0;
for i in range(n-2):
  if (a[i][0]==a[i][1]and a[i+1][0]==a[i+1][1] and a[i+2][0]==a[i+2][1]):
    f=1
if f:
  print("Yes")
else :
  print("No")
  

Measured memory_bytes: 9192
#include <iostream> 
#include <string> 
using namespace std; 
int ans; 
string s; 
int main(){ 
  cin >> s; 
  if(s[0]=='1') ans++; 
  if(s[1]=='1') ans++; 
  if(s[2]=='1') ans++; 
  cout << ans << endl; 
}

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e15);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n, b[2][105];
int ans[105];
int main()
{
	std::cin >> n;
	for (int i = 0; i < n; ++i)
		std::cin >> b[0][i];

	int turn = 0;
	bool ok = true;
	for (int i = n - 1; i >= 0; --i) {
		int now = (turn + 1) % 2;
		bool check = true;
		for (int j = i; j > 0; --j) {
			if (check&&b[turn][j] == j + 1) {
				check = false;
				ans[i] = b[turn][j];
			}
			else {
				if (check)
					b[now][j - 1] = b[turn][j];
				else
					b[now][j] = b[turn][j];
			}
		}
		if (check) {
			if (b[turn][0] == 1)
				ans[i] = b[turn][0];
			else {
				ok = false;
				break;
			}
		}
		else
			b[now][0] = b[turn][0];
		turn = (turn + 1) % 2;
	}

	if (ok)
		for (int i = 0; i < n; ++i)
			std::cout << ans[i] << std::endl;
	else
		std::cout << -1 << std::endl;
	return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    if (abs(N - M) > 1)
    {
        cout << 0 << endl;
        return 0;
    }

    long long q = 1000000000 + 7;
    long long ans1 = 1;
    long long ans2 = 1;
    for (int i = 1; i <= N; i++)
    {
        ans1 *= i;
        ans1 %= q;
    }
    for (int i = 1; i <= M; i++)
    {
        ans2 *= i;
        ans2 %= q;
    }

    if (N == M)
    {
        cout << (2 * ans1 * ans2) % q << endl;
    }
    else
    {
        cout << (ans1 * ans2) % q << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import collections

# 素因数分解
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

def main():
    N = int(input())
    tmplist = []
    #restlist = []
    for i in range(2, 55556):
        tmp = prime_factorize(i)
        if len(tmp) == 1:
            tmplist.append(i)
            #restlist.append(i%5)
    
    #count = collections.Counter(restlist)
    #print(count)
    ans = []
    for tmp in tmplist:
        if tmp%5 == 1:
            ans.append(tmp)
        if len(ans) == N:
            print(*ans)
            return

if __name__ == "__main__":
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> c(n);
  int answer = 0;
  for(int i = 0;i < n;i++){
    cin >> c[i];
    if(i >= 1 && c[i] == c[i-1]){
      answer++;
      c[i] = 1000+i;
    }
  }
  cout << answer << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>

#define MAX_N 1000001

using namespace std;

int n;
int data[MAX_N*2-1];

void init(){
	for(int i=0;i<2*MAX_N-1;i++) data[i]=INT_MAX;
}

void update(int i,int x){
	//?????????????????????
	i+=n-1;
	data[i]=x;
	//tree????????????????????´??°????????????.
	while(i>0){
		i=(i-1)/2;
		data[i]=min(data[i*2+1],data[i*2+2]);
		//printf("data[%d]=%d\n",i,data[i]);
	}
}

//??????[a,b)???????????¨??????, ???????????? k ?????????????????????l,r????????????.
int find(int a,int b,int k,int l,int r){
	//if(a==b) return data[a+n-1];
	if(r<=a || b<=l) return INT_MAX;
	if(a<=l && r<=b) return data[k];
	else{
		int vl=find(a,b,k*2+1,l,(l+r)/2);
		int vr=find(a,b,k*2+2,(l+r)/2,r);
		return min(vl,vr);
	}
}

int main(){
	int q;
	int N;
	int com,x,y;
	scanf("%d %d",&N,&q);
	//if(n%2!=0) n+=1;
	init();
	n=1;
	while(n<N) n*=2;
	for(int i=0;i<q;i++){
		scanf("%d %d %d",&com,&x,&y);
		if(com==0)
		update(x,y);
		else{
			if(x==y)
			printf("%d\n",data[x+n-1]);
			else{
				printf("%d\n",find(x,y+1,0,0,n));
			}
		}
	}
}

Measured memory_bytes: 11020
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]

ans = 0

if n >= 2:
    ans += (1 / 2) * n * (n - 1)

if m>= 2:
    ans += (1 / 2) * m * (m - 1)

print(int(ans))

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

using namespace std;

#define int long long

const int MAXN = 2e5 + 7;

int h, w;
int n;
vector <int> a[MAXN];

signed main() {
    #ifdef HOME
        freopen("input.txt", "r", stdin);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> h >> w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        a[x].push_back(y);
    }   

    for (int i = 0; i < MAXN; ++i) {
        sort(a[i].begin(), a[i].end());
    }   

    int p = -1;
    for (int i = 0; i < h - 1; ++i) {
        auto t = upper_bound(a[i].begin(), a[i].end(), p);

        p += (t == a[i].end() || *t != p + 1);

        //cout << "FOR " << i << ' ' << p << '\n';

        int pr = upper_bound(a[i + 1].begin(), a[i + 1].end(), p) - a[i + 1].begin();
        --pr;
        if (pr != -1 && a[i + 1][pr] <= p) {
            //cout << "KEK " << i << ' ' << a[i][pr] << '\n';
            cout << i + 1 << '\n';
            exit(0);
        }   
    }   

    cout << h << '\n';
    return 0;
}   

Measured memory_bytes: 11264
n,m = map(int,input().split())
cake = []

for i in range(n):
    x,y,z = map(int,input().split())
    cake.append([x,y,z])
ans = 0
    
for i in range(2):
    for j in range(2):
        for k in range(2):
            cakesum = []
            ansk = 0
            
            for xx,yy,zz in cake:
                a = xx * ((-1)**i) + yy * ((-1)**j) + zz * ((-1)**k)
                cakesum.append(a)
                
            cakesum.sort(reverse = True)
            ansk = sum(cakesum[:m])
            
            ans = max(ansk,ans)
            
print(ans)

Measured memory_bytes: 73988
#include <iostream>
#include <vector>
#include <map>

const int mod = 1000000007;

long long int dfs(std::map<int, std::vector<int>>& t_dict, int K, int current, int parent, int n_pp){
	long long int ans = K-n_pp-1;
	int n_parent_count = 1;
	if(parent == -1){
		ans = K;
		n_parent_count = 0;
	}
	for(const auto& node: t_dict[current]){
		if(node == parent) continue;
		ans *= dfs(t_dict, K, node, current, n_parent_count);
		ans = ans % mod;
		n_parent_count += 1;
	}
	return static_cast<long long int>(ans);
}


int main(){
	int N,K;
	std::cin >> N >> K;
	std::map<int, std::vector<int>> t_dict;
	for(int i = 0; i < N; i++){
		t_dict[i];
	}
	for(int i = 0; i < N-1; i++){
		int a,b;
		std::cin >> a >> b;
		a--; b--;
		t_dict[a].push_back(b);
		t_dict[b].push_back(a);
	}

	std::cout << dfs(t_dict, K, 1, -1, 0) << std::endl;

	return 0;
}




Measured memory_bytes: 17792
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	long long int N, M;
	cin >> N >> M;
	if (N == M+1) {
		long long int sum = 1;
		for (long long int i = 1; i <= M; i++) {
			sum = i * sum % 1000000007;
		}
		long long int k = 1;
		k = sum * N % 1000000007;
		cout << sum * k % 1000000007;
	}
	else if (N == M) {
		long long int sum = 1;
		for (long long int i = 1; i <= M; i++) {
			sum = i * sum % 1000000007;
		}
		cout << (sum * sum * 2) % 1000000007;
	}
	else if (N+1 == M) {
		long long int sum = 1;
		for (long long int i = 1; i <= N; i++) {
			sum = sum * i % 1000000007;
		}
		long long int k = 1;
		k = sum * M % 1000000007;
		cout << sum * k % 1000000007;
	
	}
	else {
		cout << 0;
	}
}

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

using namespace std;

typedef long long ll;

int main(){
    int A,B; 
    cin >> A >> B;
    if(((A+B)%3 == 0)|| A%3 ==0 || B%3==0){
        cout << "Possible";
    }else{
        cout << "Impossible";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <utility>
#include <set>
#include <cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
using namespace std;
typedef pair<int,int> point;
typedef complex<double> P;
typedef long long ll;

const double eps = 1e-8;
const double INF = 1e12;


double dot(P a,P b){
	return a.real()*b.real()+a.imag()*b.imag();
}
double cross(P a,P b){
	return a.real()*b.imag()-a.imag()*b.real();
}

bool is_orthogonal(P a1,P a2,P b1,P b2){
	return EQ(dot(a1-a2,b1-b2),0.0);
}
bool is_parallel(P a1,P a2,P b1,P b2){
	return EQ(cross(a1-a2,b1-b2),0.0);
}

bool is_point_on_line(P a,P b,P c){
	return EQ(cross(b-a,c-a),0.0);
}

bool is_point_on_linesegment3(P a,P b,P c){
	//|a-c| + |c-b|<=|a-b| ???????????????
	return (abs(a-c)+abs(c-b)<abs(a-b)+EPS);
}

double distance_l_p(P a,P b,P c){
	return abs(cross(b-a,c-a))/abs(b-a);
}


double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a)<EPS)return abs(c-a);
	if(dot(a-b,c-b)<EPS)return abs(c-b);
	return abs(cross(b-a,c-a))/abs(b-a);
}

int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(n==0 && m==0)break;
		double rate[n][n];
		double nobi[m][n];
		rep(i,n){
			nobi[0][i]=1;
			rep(j,n){
				cin>>rate[i][j];
			}
		}
		loop(i,1,m){
			rep(j,n){
				rep(k,n){
					if(k==0)nobi[i][j]=nobi[i-1][k]*rate[k][j];
					else nobi[i][j]=max(nobi[i][j],nobi[i-1][k]*rate[k][j]);
				}
			}
		}
		double ans=-1;
		rep(i,n){
			ans=max(ans,nobi[m-1][i]);
		}
		printf("%.2f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1336
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}

ll z[200001];

//ll fac[100001]={0};
int main()
{/*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    ll n,k;
    cin>>n>>k;
    ll a[n];
    forin(i,0,n-1)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll sum=0;
    forin(i,0,n-k-1)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)
int main()
{
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
double a,b,t;
cin>>a>>t>>b;
if(a/b>t)
cout<<"No"<<endl;
else{ cout<<"Yes";}}

Measured memory_bytes: 3732
//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//std::ios::sync_with_stdio(false);

main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int n;
	cin>>n;
	cout<<180+(n-3)*180<<endl;
	return 0;
} 
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int main(){
  ll N; cin>>N;
  ll a;
  ll bt = pow(10,5)+1;
  ll tp = -1;
  umap<ll,ll> mp;
  REP(i,N){
    cin >>a;
    mp[a]++;
    if(bt>a){bt = a;}
    if(tp<a){tp=a;}
  }
  ll r = 0;
  for(int i=bt;i<=tp;i++){
    r = max( mp[i-1]+mp[i]+mp[i+1]  ,r);
  }
  cout << r;
}

Measured memory_bytes: 4388
from itertools import accumulate

n, k = map(int, input().split())
p = list(map(int, input().split()))

st = list(accumulate(range(1001)))
#print(st)
table = [0] * (n + 1)
for i in range(1, len(table)):
    table[i] = table[i-1] + (st[p[i-1]] / p[i-1])
    #print(i, p[i-1], st[p[i-1]], table[i])
    
ans = table[k]
for i in range(k+1, len(table)):
    ans = max(ans, table[i] - table[i-k])

print(ans)



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

int main(){
int a,b;
cin>>a>>b;
if(a<0&&b<0){
	if((b-a)%2==0)cout<<"Negative"<<endl;
	else cout<<"Positive"<<endl;
}
else if(a<=0&&0<=b)cout<<"Zero"<<endl;
else cout<<"Positive"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a[3];
  int i,count5=0,count7=0;

  for(i=0;i<3;i++){
    scanf("%d",&a[i]);
    if(a[i]==5)
      count5+=1;
    if(a[i]==7)
      count7+=1;
  }

  if(count5==2 && count7==1)
    printf("YES\n");
  else
    printf("NO\n");

  return 0;
}


Measured memory_bytes: 128