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


void solve(long long N, long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> p, std::vector<long long> x){

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N,Q;cin >> N >> Q;
    vector<long long> link[N + 1];
    long long point[N + 1] = {0};
    long long used[N + 1] = {0};

    for(long long i = 0;i<N-1;i++){
        long long edge1,edge2;cin >> edge1 >> edge2;
        link[edge1 -1].push_back(edge2 -1);
        link[edge2 - 1].push_back(edge1 -1);
    }
    
    for(long long i = 0;i < Q;i++){
        long long n,p;cin >> n >> p;
        point[n - 1] += p;
    }

    queue <long long> q;
    q.push(0);
    while(not q.empty()){
        long long node = q.front();q.pop();
        for(long long j = 0;j < link[node].size();j++){
            if(used[link[node][j]]) continue;
            else {
                point[link[node][j]] += point[node];
            }
            q.push(link[node][j]);
        }
        used[node] = 1;
    }

    cout << point[0];
    for(int i = 1;i < N;i++) {
        cout << " " << point[i];
    }
    cout << endl;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;


int main(){
  ll n;
  cin >> n;
  bool ans = false;
  rep(i, 1, 10)rep(j, 1, 10) if(i * j == n) ans = true;
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python

def factorization(n):
    arr = []
    tmp = n
    i = 2
    while i ** 2 <= n:
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                tmp //= i
                cnt += 1
            arr.append([i, cnt])
        i += 1
    if tmp != 1:
        arr.append([i, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

def main():
    n = int(input())
    if n == 1:
        print(0)
        exit()

    f = factorization(n)
    ans = 0
    c = len(f)
    for i in range(c):
        s = 0
        g = f[i][1]
        if g <= 2:
            ans += 1
        else:
            for j in range(g):
                f[i][1] -= j+1
                s += j+1
                if s > g:
                    break
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9140
a,b=gets.split.map &:to_i
aa=[]
aa+=[?.*(100+a)]*50
a.times do
  aa<< ?.*50+gets.chomp+?.*50
end
aa+=[?.*(100+a)]*50
ab=[]
c=0
b.times do
  ab<< s=gets.chomp
  c+=s.count(?.)
end
jd=true
(a+50-b+1).times do |i|
  (a+100-b+1).times do |j|
    jd=true
    b.times do |k|
      b.times do |l|

        if ab[k][l]==?# && aa[i+k][j+l]==?.
          jd=false
          break
        end
      end
      break if !jd
    end
    break if jd
  end
  break if jd
end
puts jd ? :Yes : :No

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
int N,K;
long A[1<<17];
long mod=1e9+7;
long F[1<<17],I[1<<17];
long C(int a,int b){return F[a]*I[b]%mod*I[a-b]%mod;}
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	cin>>N>>K;
	F[0]=1;
	for(long i=1;i<=N;i++)F[i]=F[i-1]*i%mod;
	I[N]=power(F[N],mod-2);
	for(long i=N;i--;)I[i]=I[i+1]*(i+1)%mod;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	long ans=0;
	for(int i=K-1;i<N;i++)
	{
		(ans+=A[i]*C(i,K-1))%=mod;
		(ans-=A[N-i-1]*C(i,K-1))%=mod;
	}
	cout<<(ans%mod+mod)%mod<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n;
    int arr[n][3];
    int i, j;
    int dp[n][3];
    for(i=0;i<n;i++){
        for(j = 0;j<3;j++){
            dp[i][j]=0;
            cin>>arr[i][j];
        }
    }
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(i=1;i<n;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+arr[i][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+arr[i][1];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0])+arr[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 2560
S = int(input())
def ff(x):
  if x % 2 == 0:
    return x/2
  else:
    return x * 3 +1
A = [0] * 1000
A[0] = S
for i in range(1,1000):
  A[i] = ff(A[i-1])
  if A.count(A[i]) == 2:
    print(i+1)
    exit()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

bool is_palindromic(int num) {
    string str_num = to_string(num);
    int l_str = str_num.size();
    range(i, 0, l_str / 2) {
        if (str_num.at(i) != str_num.at(l_str - 1 - i)) return false;
    }
    return true;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    int num_palindromic = 0;
    range(num, A, B + 1) {
        if (is_palindromic(num)) num_palindromic += 1;
    }
    cout << num_palindromic << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
  unordered_map<string, int> red, blue;

  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    blue[s]++;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    red[s]++;
  }

  int mx = 0;

  for (auto it = blue.begin(); it != blue.end(); it++) {
    string s = it->first;
    int v = it->second;
    v -= red[s];

    mx = max(mx, v);
  }

  cout << mx << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    n=n%1000;
    if(n!=0)
        cout<<1000-n<<endl;
    else
        cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3644
from typing import List


class RollingHash:
    """Rolling Hash"""

    __slots__ = ["_source", "_length", "_base", "_mod", "_hash", "_power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
        self._source = source
        self._length = len(source)
        self._base = base
        self._mod = mod
        self._hash = self._build_hash_from_zero()
        self._power = self._build_base_power()

    def _build_hash_from_zero(self) -> List[int]:
        """Compute hash of interval [0, right)."""
        res = [0] * (self._length + 1)
        prev = 0
        for i, c in enumerate(self._source, 1):
            res[i] = (prev * self._base + ord(c)) % self._mod
            prev = res[i]
        return res

    def _build_base_power(self) -> List[int]:
        """Compute mod of power of base."""
        res = [1] * (self._length + 1)
        prev = 1
        for i in range(1, self._length + 1):
            res[i] = prev * self._base % self._mod
            prev = res[i]
        return res

    def get_hash(self, left: int, right: int):
        """Return hash of interval [left, right)."""
        return (
            self._hash[right] - self._hash[left] * self._power[right - left]
        ) % self._mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()
    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg = False
        memo = set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = True
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()


Measured memory_bytes: 11320
#include<stdio.h>
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(c>a && c<b){
        printf("Yes\n");
    }else if(c<a && c>b){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

int main()
{
  double a,b,c,d,e,f,x,y;

  while(cin>>a>>b>>c>>d>>e>>f){

    y=(c*d-a*f)/(b*d-a*e);

    x=(c-b*y)/a;

    cout<<fixed;
    cout<<setprecision(3)<<x<<" "<<setprecision(3)<<y<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <iostream>
#include <boost/range/algorithm/count.hpp>
using namespace std;

int main(){
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.length(); i++){
    if (s.at(i) == '1'){
      count++;
    }
  }
  cout << count << endl;
}


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
int n, m, x;
int books[15][15];
int prices[15];
int dfs(int index, int current_price, vector<int> keiken, bool buy_this=false) {
  // 最初の呼出では本を買わない
  if(buy_this) {
    REP(i,m) {
      keiken[i] += books[index][i];
    }
    current_price += prices[index];
  }
  if(index == 0) {
    REP(i,m) {
      if(keiken[i] < x) {
        return -1;
      }
    }
    return current_price;
  }
  int price1 = dfs(index-1, current_price, keiken, true);
  int price2 = dfs(index-1, current_price, keiken);
  if(price1 >= 0 && price2 >= 0) {
    return min(price1, price2);
  }
  
  // 少なくとも片方が-1の時
  return max(price1, price2);
}
/***** MAIN *****/
signed main() {
  cin >> n >> m >> x;
  REP(i,n) {
    cin >> prices[i];
    REP(j,m) {
      cin >> books[i][j];
    }
  }
  cout << dfs(n, 0, vector<int>(m,0));
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3564
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        for (int i=1; i<100; i++) {
            int sum = 0;
            for (int j=0; j<n; j++) {
                sum += Math.pow((double)(i - array[j]),2);
            }
            min = Math.min(min, sum);
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register ll i=(a);i<(b);i++)
typedef long long ll;
inline ll read(){ll sign=1; ll x=0; char ch; while(!isdigit(ch=getchar())) if(ch=='-') sign=-1; while(isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x*sign;}
inline void write(ll k){ if(k<0) putchar('-'),k*=-1; char ch[20]; int num=0; while(k)ch[++num]=k%10,k/=10; if(num==0) ch[++num]=0; while(num)putchar(ch[num--]+'0');}
const ll INF=1ll<<62;
const ll MOD=1000000007;
ll h,w,a[500][500],b[500][500];
void sett(ll i,ll j){
	a[i][j]=0;
	b[i][j]=1;
}
int main() {
	h=read(); w=read();
	rep(i,0,h){
		rep(j,0,w) {
			a[i][j]=1;
			if(getchar()=='#') b[i][j]=1;
		}
		getchar();
	}
	rep(j,0,w) sett(0,j);
	rep(i,0,h-1) for(ll j=0;j<w;j+=2) if(!b[i][j]) sett(i,j);
	rep(i,0,h){
		rep(j,0,w) putchar(a[i][j]?'#':'.');
		putchar('\n');
	}
		putchar('\n');
	rep(i,0,h){
		rep(j,0,w) putchar(b[i][j]?'#':'.');
		putchar('\n');
	}
    return 0;
}

Measured memory_bytes: 4608
n = int(input())
a = list(map(int,input().split()))

lst = []
c = 1
for i in range(n-1):
    if a[i+1]==a[i]:
        c+=1
    else:
        lst.append(c)
        c = 1
if c > 1: lst.append(c)

ans = 0
for c in lst:
    ans += int(c/2)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n,k;

int main(){
	cin>>n>>k;
	int s=(1+2+3+8+9+10+15+16+17)%11,ans=0;
	for(int i=0;i<5;i++){
		int t=(s+9*i)%11,m=n-3;
		while(m&&t!=k){
			(t+=8)%=11;
			m--;
		}
		if(!m&&t!=k) continue;
		ans++;
		ans+=m/11;
		m%=11;
		for(int i=0;i<m;i++){
			(t+=8)%=11;
			if(t==k) ans++;
		}
	}
	cout<<ans<<endl;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using llu = long long unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll a,b,c;
    cin >> a >> b >> c;
    if( c - a - b < 0 ) YesNo(false);
    else{
        YesNo( 4*a*b < (c-a-b)*(c-a-b) );
    }

    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
	int a[100];
	int i;
	for(i=0;i<=n-1;i++)
	   scanf("%d",&a[i]);
	int sum=0;
	for(i=1;i<n-1;i++)
	  {
	  	if((a[i]-a[i-1])*(a[i]-a[i+1])<0)
	  	 sum=sum+1;
	  }
	printf("%d\n",sum);
    }
	  return 0;
}

Measured memory_bytes: 128
# include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;

const ll mod=1000000007;	
ll f[501010], rf[501010];

ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}

ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}

ll P(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n - k]; // = (n-k)!
    return (a * b) % mod;
}

ll H(int n, int k) {
    return C(n + k - 1, k);
}

void init() {
    f[0] = 1;
    rep(i, 1, 501010) f[i] = (f[i - 1] * i) % mod;
    rf[501010 - 1] = inv(f[501010 - 1]);
    rrep(i, 501010 - 2, 0) rf[i] = (rf[i + 1] * (i + 1)) % mod;
}

int main() {
  int N,M;
  cin >> N >> M;
  init();
  ll res=0;
  ll sign=1;
  ll tmp;
  rep(i,0,N+1){
    tmp = C(N,i)*P(M,i) % mod;
    tmp = tmp*P(M-i,N-i) % mod;
    tmp = tmp*P(M-i,N-i) % mod;
    res += mod + sign*tmp; //引き算のmod
    res = res % mod;
    sign *= -1;
  }
  cout << res;
  return 0;
}


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

int main(int argc, char const *argv[])
{
    int n, l;
    cin >> n >> l;

    int ate;
    if(l > 0) {
        ate = l;
    } else if(l + n -1 < 0) {
        ate = l + n -1;
    } else {
        ate = 0;
    }
    
    cout << (2*l + n - 1) * n / 2 - ate << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d,i,j,k,l,ans;
	double g;
	char n[30005];
	int m[1000];
	int p[1000];
	int o[1000];
	while(~scanf("%d",&a))
	{
		memset(m,0,sizeof(m));
		
	
		ans=0;
	scanf("%s",n);
//	sort(n,n+a); 
		for(i=0;i<a-2;i++)
		{
			if(!m[n[i]-'0'])
			{memset(p,0,sizeof(p));
			m[n[i]-'0']=1;
			for(j=i+1;j<a-1;j++)
			{
				if(!p[n[j]-'0'])
				{	 memset(o,0,sizeof(o));
					p[n[j]-'0']=1;
				for(k=j+1;k<a;k++)
				{
					if(!o[n[k]-'0'])
					{
						o[n[k]-'0']=1;
						ans+=1;
					}
				}	
				}
				
			}	
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

typedef long long ll;

using namespace std;
int main(){
    int N;
    cin >> N;

    int A[N] = {};
    int max = 0;
    int second = 0;
    int maxIndexCount = 0;
    for (int i = 0; i < N; i++) {
    	cin >> A[i];
    	if (A[i] > max) {
    		second = max;
    		max = A[i];
    		maxIndexCount = 1;
    	}
    	else if (A[i] == max) {
    		maxIndexCount++;
    	}
    	else if (A[i] > second) {
    		second = A[i];
    	}
    }

    int ans;
    for (int i = 0; i < N; i++) {
    	if (A[i] == max){
    		if (maxIndexCount > 1){
    			ans = max;
    		}
    		else {
    			ans = second;
    		}
    	}
    	else if (A[i] < max) { 
    		ans = max;
    	}
    	
	    cout << ans << "\n";
    }
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    sort(All(s));
    sort(All(t));
    reverse(All(t));
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int N = input.nextInt();
		
		if(N%2==0) {
			System.out.println(N/2);
		}
		else {
			System.out.println((N+1)/2);
		}
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, ans;
int main() {
	read(n);
	while (n != 0) {
		ans += n % 10;
		n /= 10;
	}
	if (ans == 1) ans += 9;
	writeln(ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int N, M, A, B, C = ~(1 << 31), D = 65535, lim = 1000001, x[300009], y[300009], z[300009], p[300009];
vector<int> cp[1000009], bit[1000009];
int func() {
	A = 36969 * (A & D) + (A >> 16);
	B = 18000 * (B & D) + (B >> 16);
	return (C & ((A << 16) + B)) % 1000000;
}
void assign(int px, int py, int val) {
	for (int i = px + 1; i <= lim; i += i & (-i)) {
		int ptr = lower_bound(cp[i].begin(), cp[i].end(), py) - cp[i].begin();
		for (int j = ptr + 1; j <= cp[i].size(); j += j & (-j)) {
			bit[i][j - 1] = max(bit[i][j - 1], val);
		}
	}
}
int query(int px, int py) {
	int ret = 0;
	for (int i = px; i >= 1; i -= i & (-i)) {
		int ptr = lower_bound(cp[i].begin(), cp[i].end(), py) - cp[i].begin();
		for (int j = ptr; j >= 1; j -= j & (-j)) {
			ret = max(ret, bit[i][j - 1]);
		}
	}
	return ret;
}
int main() {
	while (scanf("%d%d%d%d", &N, &M, &A, &B), N + M) {
		for (int i = 0; i < N; ++i) scanf("%d%d%d", &x[i], &y[i], &z[i]);
		for (int i = 0; i < M; ++i) x[N] = func(), y[N] = func(), z[N] = func(), ++N;
		for (int i = 0; i < N; ++i) p[i] = i;
		sort(p, p + N, [](int i, int j) { return z[i] != z[j] ? z[i] < z[j] : y[i] > y[j]; });
		for (int i = 0; i <= lim; i++) cp[i].clear();
		for (int i = 0; i < N; i++) {
			for (int j = x[p[i]] + 1; j <= lim; j += j & (-j)) {
				cp[j].push_back(y[p[i]]);
			}
		}
		for (int i = 0; i <= lim; i++) {
			sort(cp[i].begin(), cp[i].end());
			cp[i].erase(unique(cp[i].begin(), cp[i].end()), cp[i].end());
			bit[i] = vector<int>(cp[i].size(), 0);
		}
		int ret = 0;
		for (int i = 0; i < N; i++) {
			int res = query(x[p[i]], y[p[i]]);
			assign(x[p[i]], y[p[i]], res + 1);
			ret = max(ret, res + 1);
		}
		printf("%d\n", ret);
	}
	return 0;
}


Measured memory_bytes: 127268
#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()
{
    ll d, g;
    cin >> d >> g;

    vector<int> p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];
    
    // 全問正解
    vector<int> nums(d);
    rep(i, 10) nums[i] = i;
    int best = 1e8;
    do {
        ll G = g; 
        int sum = 0;
        rep(_i, d) {
            int i = nums[_i];
            int C1 = 100 * (i+1) * p[i];
            int C2 = C1 + c[i];
            if (G >= C1) {
                G -= C2;
                sum += p[i];
            }
            else {
                int u = (100 * (i+1));
                int np = (G + u - 1) / u;
                G -= np * u;
                sum += np;
            }
            if (G <= 0) {
                break;
            }
        }
        best = min(sum, best);
    } while (next_permutation(nums.begin(), nums.end()));

    put(best);

    return 0;
}

Measured memory_bytes: 3616
// AC Please
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    
    bool small = false;
    set<int> S;
    rep(i, M) {
        int x = N / 2 - i;
        int y = N / 2 + 1 + i;
        if (S.count(y - x)) small = true;
        if (S.count(x + N - y)) small = true;
        if (y - x == x + N - y) small = true;
        if (small) --x;
        cout << x << " " << y << "\n";
        S.insert(y - x);
        S.insert(x + N - y);
    }
    return 0;
}


Measured memory_bytes: 11996
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    double a,b;
    cin>>a>>b;
    double h,m;
    cin>>h>>m;
    double pie=acos(-1);
    //一周に占める割合だろ
    double ax=a*cos(2*pie*(60*h+m)/720);
    double ay=a*sin(2*pie*(60*h+m)/720);
    double bx=b*cos(2*pie*(m)/60);
    double by=b*sin(2*pie*(m)/60);
    printf("%.10lf",hypot(ax-bx,ay-by));
    return 0;
}




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

int main()
{
  int h, m, l, c;
  scanf("%d%d%d%d", &h, &m, &l, &c);
  printf("%d\n", ((h * m) - (l * m)) - (c * (h - l)));
  return 0;
}

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

int main() {

	int W, H, x, y;
	cin >> W >> H >> x >> y;

	int mult = 0;
	if (W == x * 2 && H == y * 2) mult = 1;

	float s = W / 2.0 * H;
	cout << s << " " << mult << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
x_str = input().split()
xs = [int(c) for c in x_str]

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

[print(c_xs[center+1] if x <= c_xs[center] else c_xs[center]) for x in xs]


Measured memory_bytes: 106708
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int X=sc.nextInt();
		int Y=sc.nextInt();
		int ans=0;

		if(A/2+B/2<C) {
			ans=A*X+B*Y;
		}else{
			if(X>Y){
				if(A<2*C){
					ans=Y*2*C+(X-Y)*A;
				}else{
					ans=X*2*C;
				}
			}else if(X<Y){
				if(B<2*C){
					ans=X*2*C+(Y-X)*B;
				}else{
					ans=Y*2*C;
				}
			}else if(X==Y){
				ans=2*C*X;
			}
		}

		System.out.println(ans);
				
	}
}

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

struct prim{
    vector<int> color;
    vector<vector<int>> M;
    vector<int> d;
    vector<int> p;
    int n_;
    prim(int n):color(n,0),M(n,vector<int>(n,-1)),d(n,INF),p(n,-1){
        n_ = n;
    }
    void init(){
        rep(i,n_){
            rep(j,n_){
                int tmp;cin>>tmp;
                M[i][j] = tmp;
            }
        }
    }

    void solve(){
        init();
        d[0] = 0;
        p[0] = -1;

        while(true){
            int mincost = INF;
            int u;
            rep(i,n_){
                if(color[i] != 2 && d[i] < mincost ){
                    mincost = d[i];
                    u = i;
                }
            }
            if( mincost == INF){
                break;
            }
            color[u] = 2;

            rep(v,n_){
                if(color[v] != 2 && M[u][v] != -1){
                    if(M[u][v] < d[v]){
                        d[v] = M[u][v];
                        p[v] = u;
                        color[v] = 1;
                    }
                }
            }
        }
        int ans = 0;
        rep(i,n_){
            ans += d[i];
        }
        cout<<ans<<endl;
    }
};

int main(){
    int n;cin >> n;
    prim p(n);
    p.solve();
    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for (int i = (a) ; i <= (b); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	int N, K, ans=0;
	cin >> N >> K;
	VI p(N);
	rep(i, N){
		cin >> p[i];
	}

	sort(all(p));

	rep(i, K){
		ans += p[i];
	}

	cout << ans << endl;


}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
import sys

H,W=map(int, sys.stdin.readline().split())
dp=[ [ float("inf") for j in range(10) ] for i in range(10) ]

for i in range(10):
    c=map(int, sys.stdin.readline().split())
    for j,x in enumerate(c):
        dp[i][j]=x


#ワーシャルフロイド
for k in range(10):
	for i in range(10):
		for j in range(10):
			dp[i][j]=min(dp[i][j], dp[i][k]+dp[k][j])


ans=0
for _ in range(H):
    A=map(int, sys.stdin.readline().split())
    for a in A:
        if a==-1: continue
        ans+=dp[a][1]

print ans


Measured memory_bytes: 32748
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	long long ans = 0;
	int ws = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'W') {
			ans += (long long) i - ws;
			ws++;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            // string s = Console.ReadLine();

            // 整数の入力
            long a = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            // string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            // var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();




            long result = a + a * a + a * a * a;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
int a[maxn];
int main()
{
    for(int i=2;i<maxn;i++){
        if(a[i]==0)
        for(int j=i;j<maxn;j+=i)
            if(a[j]==0) a[j]=i;
    }
    int x;
    scanf("%d",&x);
    for(int i=x;i<maxn;i++)
    if(a[i]==i) {printf("%d\n",i);return 0;}
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,c,x;
int d[34][34],t[3][34];
int main(){
   scanf("%d%d",&n,&c);
    for(int i=1;i<=c;i++)
      for(int j=1;j<=c;j++)
        scanf("%d",&d[i][j]);
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
      {
      	 scanf("%d",&x);
      	 t[(i+j)%3][x]++;
      }
      int minn=1<<30;
      for(int i=1;i<=c;i++){ 
        for(int j=1;j<=c;j++)
      { 
      	if(i==j)continue;
      	for(int k=1;k<=c;k++)
      	{
      		if(i==k||j==k)continue;
      		int tt=0;
      		for(int l=1;l<=c;l++)tt+=d[l][i]*t[0][l];
      		for(int l=1;l<=c;l++)tt+=d[l][j]*t[1][l];
      		for(int l=1;l<=c;l++)tt+=d[l][k]*t[2][l];
      		if(tt<minn)minn=tt;
      	}
      }
    }
    printf("%d\n",minn);
	return 0;
}


Measured memory_bytes: 256
import copy
from collections import deque

H, W = map(int, input().split())
field_s = []

# フィールドを作る
for h in range(H + 2):
    field_s.append(["#"] * (W + 2))
    if 1 <= h <= (H):
        field_s[h][1:-1] = list(map(str, input().rstrip()))

#　動き方のセットを準備
moves = [[1, 0], [-1, 0], [0, 1], [0, -1]]

# スタート座標を取得
start = []
for y in range(1, H + 1):
    for x in range(1, W + 1):
        if field_s[y][x] == ".":
            start.append([y, x])

# 答え
ans = 0

for s in start:

    # fieldの初期化
    field = copy.deepcopy(field_s)

    # startをキューに追加
    que = deque([s])

    # startの距離は0に
    field[s[0]][s[1]] = 0

    # キューに何かがある限り探索を続ける
    while que:
        c = que.popleft()

        # 今の距離
        dist = field[c[0]][c[1]]

        # 動いた先が「.」なら、距離を記録してキューに追加
        for m in moves:
            my = c[0] + m[0]
            mx = c[1] + m[1]

            if field[my][mx] == ".":
                field[my][mx] = dist + 1
                que.append([my, mx])
            else:
                continue

    # キューを消化したら最大値を取り出す
    field = sum(field, [])
    ans = max(ans, max([x for x in field if type(x) == int]))

print(ans)

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {
  int n, k;
  double out;

  cin >> n >> k;

  cout << (int)(k*pow(k-1, n-1)) << endl;
}

Measured memory_bytes: 256
object Main extends App{

  val n = io.StdIn.readLine().toInt
  
  for (i <- 1 to n) {
    val sideAry = io.StdIn.readLine().split(' ').map { _.toInt }.sorted.reverse
    val a = sideAry(0) * sideAry(0)
    val b = sideAry(1) * sideAry(1)
    val c = sideAry(2) * sideAry(2)

    if (a == (b + c))
      println("YES")
    else
      println("NO")
  }
}

Measured memory_bytes: 45276
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
  int n=0;
  while(cin >> n){
    int res=0;
    if(n>36)
      res = 0;
    else if(n==36)
      res = 1;
    else{
      for(int i=0; i<10; i++){
	for(int j=0; j<10; j++){
	  for(int k=0; k<10; k++){
	    for(int l=0; l<10; l++){
	      if(i+j+k+l==n)
		res++;
	    }
	  }
	}
      }
    }
    cout << res << endl;
  }

  return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> P(M),Y(M);
  vector<pair<int,int>> p(M);
  for(int i=0;i<M;i++){
    cin>>P.at(i)>>Y.at(i);
    p.at(i).first=Y.at(i);
    p.at(i).second=i;
  }

  sort(p.begin(),p.end());
  vector<int> count(N,0);
  for(int i=0;i<M;i++){
    count.at(P.at(p.at(i).second)-1)++;
    p.at(i).first=count.at(P.at(p.at(i).second)-1);
    int tmp=p.at(i).first;
    p.at(i).first=p.at(i).second;
    p.at(i).second=tmp;
  }
  sort(p.begin(),p.end());

  for(int i=0;i<M;i++){
    cout<<setfill('0')<<setw(6)<<right<<P.at(i)<<setfill('0')<<setw(6)<<right<<p.at(i).second<<endl;
  }
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  string s;
  cin >> s;
  int n = s.size();
  int ans = 1000;
  int x = 0;
  REP(i, n-2){
    x = (s[i] - '0') * 100 + (s[i+1]- '0') * 10 + (s[i+2]-'0');
    ans = min(abs(753-x), ans);
    //cout << x << endl;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
 int K,A,B;
 bool Ans=false;
 cin>>K>>A>>B;
 for(int i=A;i<=B;i++){
   if(i%K==0) Ans=true;
 }
 if(Ans) cout<<"OK"<<endl;
 else cout<<"NG"<<endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

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

int main()
{
    ll N,M;
    cin >> N >> M;
    if(N == 1 || M == 1)
    {
        if(N > 1 || M > 1)
        {
            cout << max(N,M) - 2 << endl;
            return(0);
        }
        else if (N == 1 && M == 1)
        {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << N * M - (2 * N + 2 * M - 4) << endl;
}

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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define print(x) cout << x << endl
#define debug print("reaching\n")
#define mll map<ll,ll>
#define lsb(i) i&(-i)
#define printv(x) \
	FORALL(i, x.size()) \
	{ \
		cout << x[i] << ' '; \
	} \
	cout << endl \
;
#define printm(m) \
	for(auto i: m){\
		cout<<i.ff<<' '<<i.ss<<endl; \
	}\
;
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
	if(b<=0) return 1;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}



template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	else
	{
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m)
{
	T x, y;
	extGcd(a, m, x, y);
	return (x % m + m) % m;
}


int main()
{
	fast;
	// cin.tie(0);
	// cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int t=1;
	// cin>>t;
	ll tot=t;
	while(t--){
		ll n;
		cin>>n;
		vll v(n);
		FORALL(i,n){
			cin>>v[i];
		}
		ll ans = 0;
		ll odd = 0;
		ll even = 0;
		FORALL(i,n){
			if(i%2==0){
				even += v[i];
				even%=MOD;
			}
			else{
				odd +=v[i];
				odd %=MOD;
			}
		}
		ans = (odd * even)%MOD;
		ans += MOD;
		ans %=MOD;
		for(int i = 0; i < n; i ++){
			if(i%2 == 0){
				even -= v[i];
				even +=MOD;
				even%=MOD;
				ans = (ans + (even * v[i])%MOD)%MOD;
			}
			if(i%2){
				odd -= v[i];
				odd +=MOD;
				odd%=MOD;
				ans = (ans + (odd * v[i])%MOD)%MOD;
			}
		}
		print(ans);
	}
	return 0;
}


Measured memory_bytes: 4740
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def diff(i, j, k):
	return i - (i//j) - (i//k) + (i//lcm(j,k))

a,b,c,d = map(int, input().split())

print( diff(b, c, d) - diff(a-1, c, d) )

Measured memory_bytes: 5088
/// Thank you tanakh!!!
///  https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;
const INF: usize = 1 << 60;

fn main() {
    input!(n: usize, p: usize, x: [usize; n]);

    let mut sum = vec![0; n + 1];
    for i in 0..n {
        sum[i + 1] = sum[i] + x[i];
    }

    let mut min = INF;
    for k in 1..(n + 1) {
        let mut ans = p * k + n * p;
        for i in 0..n {
            if n < k * i {
                break;
            }
            let to = n - k * i;
            let from = if to >= k { to - k } else { 0 };

            let t = if i == 0 { 5 } else { 2 * i + 3 };
            ans += t * (sum[to] - sum[from]);
            if ans > INF {
                break;
            }
        }
        min = cmp::min(min, ans);
    }

    println!("{}", min);
}


Measured memory_bytes: 10492
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    string s;
    cin>>s;
    vector<bool> news(4);
    int n = sz(s);
    rep(i, n) {
        if (s[i] == 'N') news[0] = true;
        if (s[i] == 'E') news[1] = true;
        if (s[i] == 'W') news[2] = true;
        if (s[i] == 'S') news[3] = true;
    }
    if ((news[0] && news[1] && news[2] && news[3]) ||
        (news[0] && news[3] && !news[1] && !news[2]) ||
        (!news[0] && !news[3] && news[1] && news[2])) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include<algorithm>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	vi t(3);
	rep(i, 3) cin >> t[i];
	vsort(t);
	cout << t[0] + t[1] << endl;
}



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

int main()
{
    int A, B;
    double T;
    cin >> A >> B >> T;
    int answer = 0;

    cout << ((int)((T + 0.5) / A)) * B << endl;
    return 0;
}

Measured memory_bytes: 256