akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#define repi(a,b,c) for(int a=b;a<=c;a++)
using namespace std;
int main(){
	int n,m,k;
	while(scanf("%d%d%d",&n,&m,&k),n){
		int a[n*m+1],b[n*m+1],*prev=a,*cur=b,*t,ans=0,sum=0;
		repi(i,1,m)cur[i]=1;
		repi(i,2,n){
			t=prev,prev=cur,cur=t;
			repi(j,i,i*m)cur[j]=0;
			repi(x,1,m)repi(y,i-1,(i-1)*m)cur[x+y]+=prev[y];
		}
		repi(i,n,n*m)sum+=cur[i],ans+=(i-k>0?i-k:1)*cur[i];
		printf("%.9f\n",1.*ans/sum);
	}
	return 0;
}

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class TaskA {
public:
    void solve(istream& in, ostream& out) {
        long long N, A, B;
        in >> N >> A >> B;
        
        
        
        long long mn = (N - 1) * A + B;
        long long mx = A + (N - 1) * B;
        out << max(mx - mn + 1, 0LL) << "\n";
    }
};


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

	TaskA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=2e5+5;
bool prime[2*N];

int main()
{	
	int n,m;
	cin>>n;
	int ar[n];
	int sum=0;
	for(int i=0;i<n;i++)
	{cin>>ar[i];sum+=ar[i];}
	int idx,x;
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>idx>>x;
		sum=sum-ar[idx-1]+x;
		cout<<sum<<"\n";
		sum=sum+ar[idx-1]-x;
	}
	
	
}

Measured memory_bytes: 256
from collections import Counter


N = int(input())
lst_A = list(map(int, input().split()))
ctr_A = Counter(lst_A)


ans = 0
for k, v in ctr_A.items():
    compare = v - k
    if compare > 0:
        ans += compare
    elif compare < 0:
        ans += v


print(ans)

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

long long int vacation(vector <vector <long long int>> &happiness, vector <vector <int>> &h)
{
    int i, j;
    happiness[0][1] = h[0][1];
    happiness[0][0] = h[0][0];
    happiness[0][2] = h[0][2];
    for(i = 1; i < h.size(); i++)
    {
        for(j = 0;  j < 3; j++)
        {
            if(j == 0)
                happiness[i][j] = max(happiness[i - 1][1] , happiness[i -1][2]) + h[i][0];
            if(j == 1)
                happiness[i][j] = max(happiness[i - 1][0], happiness[i - 1][2]) + h[i][1];
            if(j == 2)
                happiness[i][j] = max(happiness[i - 1][0], happiness[i - 1][1]) + h[i][2];
        }
    }
    int n = h.size();
    //return max(happiness[h.size() - 1]);
    return max({happiness[n - 1][0], happiness[n -1][1], happiness[n - 1][2]});
}

int main()
{
    int n;
    cin >> n;
    vector <vector <int>> h(n, vector <int>(3));
    vector < vector <long long int>> happiness(n, vector <long long int> (3));
    for(int i = 0;  i  < n; i++)
        cin >> h[i][0] >> h[i][1] >> h[i][2];
    cout << vacation(happiness, h);

}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,s=0,c=0,m=1000000000;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>0) s+=a[i];
        else if(a[i]<0){
            c++;
            s+=-a[i];
        }
        m=min(m,(ll)fabs(a[i]));
    }
    if(m==0 || c%2==0) cout<<s<<endl;
    else cout<<s-2*m<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
 
ll modconbi(ll n,ll r,ll mod){
    ll numerator = 1;
    ll denominator = 1;
 
    for(ll i = 0;i<r;i++){
        numerator = (numerator * (n-i))%mod;
    }
 
    for(ll i = 1;i<=r;i++){
        denominator = (denominator * i)%mod;
    }
 
    return (numerator * modinv(denominator,mod))%mod;
}
 
int main(void)
{
    ll n,k;
    ll mod = 1e9+7;
    cin >> n >> k;
 
    FOR(i,1,k+1){
        cout << (modconbi(k-1,i-1,mod)*modconbi(n-k+1,i,mod))%mod << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    int p[n];
    cin >> p[0];
    int min = p[0], count = 1;
    for(int i = 1; i < n; i++){
        cin >> p[i];
        if(min >= p[i]){
            count++;
            min = p[i];
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    string s,c;
    c="CODEFESTIVAL2016";
    cin>>s;
    int cnt=0;
    for (int i=0;i<16;++i){
        if(s[i]!=c[i]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

int main(){
    int N, a[100000], cnt[4];
    cin >> N;
    for (int i = 0; i < 4; ++i) {
        cnt[i] = 0;
    }
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        cnt[a[i]%4]++;
    }
    if(cnt[2]) {
        if (cnt[1] + cnt[3] <= cnt[0]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else{
        if(cnt[1] + cnt[3] - 1 <= cnt[0]){
            cout << "Yes" << endl;
        } else{
            cout << "No" << endl;
        }
    }
    return 0;
}


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

int main() {
	int n, a, b, c; cin >> n >> a >> b >> c;
	int l[10];
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int p = 1;
	for (int i = 0; i < n; i++) p *= 4;
	int ans = 100000000;
	for (int i = 0; i < p; i++) {
		int mp = 0;
		int s = 0, t = 0, u = 0;
		int d = i;
		for (int j = 0; j < n; j++) {
			if (d % 4 == 0) s += l[j];
			if (d % 4 == 1) t += l[j];
			if (d % 4 == 2) u += l[j];
			if (d % 4 != 3) mp += 10;
			d /= 4;
		}
		if (s == 0 || t == 0 || u == 0) continue;
		mp -= 30;
		ans = min(ans, abs(a - s) + abs(b - t) + abs(c - u) + mp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int sum[10],i;
  for(i = 0; i < 10 ;i++)cin >> sum[i];
  sort(sum,sum+10);
  for(i = 9 ; i > 6 ;i--)cout << sum[i] << endl;
    return 0;
  }

Measured memory_bytes: 3092
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
ll s[100006];
int main() {
int n,m,sum;cin>>n;sum=0;
  for(int i=1;i<=n;i+=2)
  {int a;a=0;
      for(int j=2;j<=sqrt(i);j++)
        if(i%j==0)a++;
      if(a==3)sum++;
  }
  cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

// a^n mod (繰り返し二乗法) 
ll modpow(ll a, ll n) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return ret % MOD;
}

//nが巨大なとき
ll big_nCr_mod(ll n,ll r){
    ll denominator = 1,numerator = 1;
    //nCr = nCn-r
    if(n <= r * 2) r = n - r;
    //分子計算
    for(ll i = 0;i < r;i++){
        numerator *= n - i;
        numerator %= MOD;
    }
    //分母計算
    //フェルマーの小定理より分母をYとすると、
    //Y ^ (MOD - 1) % MOD = 1 より、Yの逆元は Y^(-1) = Y ^ (MOD - 2) % MOD 
    //そのため、乗算(MODが使える)をするために Y ^ (MOD - 2) % MOD を計算
    for(ll i = 1;i < r + 1;i++){
        denominator *= i;
        denominator %= MOD;
    }
    denominator = modpow(denominator,MOD - 2);
    return (numerator * denominator + MOD) % MOD;
}
inline ll mod(ll a){
    while(a < MOD)a += MOD;
    return a % MOD;
}

int main(){
    ll n,a,b,ans;
    cin>>n>>a>>b;
    ans = modpow(2,n);
    ans = mod((ans - 1 - big_nCr_mod(n,a) - big_nCr_mod(n,b) + MOD + MOD));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
lis = [2,1]
for i in range(2, n+1):
  lis.append(lis[i-1] + lis[i-2])

print(lis[n])

Measured memory_bytes: 3060
#include<iostream> 
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
int main(){
	int x,a;
	cin>>x>>a;
	if(x<a){
		cout<<"0";
	}else{
		cout<<"10";
	}
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,k,ans=0;
    cin>>n>>k;
    for (ll i = k+1; i <= n; i++)
    {
        ans+=(n/i)*(i-k);
        ans+=max(0LL,(n%i)-max(0LL,k-1LL));
        //cout<< i<<"\t"<<(n/i)*(i-k)<<"\t"<< (n%i)-k+1<<endl;
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int count=0,D,N,X,Y;
  if(!scanf("%d %d",&N,&D))return-1;
  while(N--)
  {
    if(!scanf("%d %d",&X,&Y))return-1;
    if(1l*X*X+1l*Y*Y<=1l*D*D)count++;
  }
  return printf("%d\n",count),0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <string.h>
#include <vector>
#include <cmath>

using namespace std;
#define ll long long
#define endl "\n";

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    // freopen("r.txt", "r", stdin);
    string s;
    cin >> s;
    if (s[s.length() - 1] == 's') {
        cout << s << "es";
    } else {
        cout << s << "s";
    }
    return 0;
}


Measured memory_bytes: 3648
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()

  l=[]
  l.append('.'*(w+1))
  for _ in range(h):
    x='.'
    x+=S()
    l.append(x)

  dp=[[inf]*(w+10) for _ in range(h+10)]
  if l[1][1]=='#':
    dp[1][1]=1
  else:
    dp[1][1]=0

  for i in range(1,h+1):
    for j in range(1,w+1):
      if i==1 and j==1:
        continue
      if l[i][j]=='#':
        if l[i-1][j]=='.':
          dp[i][j]=min(dp[i][j],dp[i-1][j]+1)
        else:
          dp[i][j]=min(dp[i][j],dp[i-1][j])
        if l[i][j-1]=='.':
          dp[i][j]=min(dp[i][j],dp[i][j-1]+1)
        else:
          dp[i][j]=min(dp[i][j],dp[i][j-1])
      else:
        dp[i][j]=min(dp[i-1][j],dp[i][j-1])

  # print(dp)
  
  return dp[h][w]

# main()
print(main())


Measured memory_bytes: 5648
/******
author :- Mahmoud Tarek.
*******/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
vector<ll> a ;
ll dp[500][500] ;

ll solve(int l, int r){
   if(r - l + 1 == 1) return 0 ;
   if(r - l + 1 == 2) return a[r] - a[l - 1] ;
   ll & ret = dp[l][r] ;
   if(~ret) return ret ;
   ret = 1e18 ;
   for(int i = l ; i < r ; i++){
      ret = min(ret, a[r] - a[l - 1] + solve(l, i) + solve(i + 1, r)) ;
   }
   return ret ;
}

int main()
{
   //  freopen("in.txt", "r", stdin) ;
   ios :: sync_with_stdio(0) ;
   cin.tie(0) ;
   cout.tie(0) ;


   cin >> n ;
   a.resize(n + 1) ;
   for(int i = 1 ; i <= n ; i++){
        cin >> a[i];
        a[i] += a[i - 1] ;
   }
   memset(dp, -1, sizeof dp) ;
   cout << solve(1, n) ;

}




/*
   Empty set of troubles.
*/


Measured memory_bytes: 2432
#include<iostream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>

#define ll long long

using namespace std;

int N, A;

int main()
{
    cin >> N >> A;
    if ((N % 500) <= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
ss = n.times.map { gets.chomp }

m = gets.to_i
ts = m.times.map { gets.chomp }

words = [*ss, *ts].uniq

ans = 0

words.each do |w|
  c = ss.count(w) - ts.count(w)
  ans = c if c >= ans
end

puts ans


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

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

	for (int i = 0; i < S.size() - 1; ++i)
	{
		if (S.substr(i, 1) == S.substr(i + 1, 1))
		{
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    int n;
    ll k;

    cin >> n >> k;
    retif(n < 2*k-1) cout << "-1\n", 0; /// NC
    if (k == 1) {
        /// SC
        for (int i = 1; i <= n; ++i) cout << i << ' ' << i+n << ' ' << i+2*n << '\n';
        return 0;
    }
    for (int i = 1; i <= (n+1)/2; ++i) {
        int a, b, c;
        c = n-i;
        b = n-2*i+1;
        a = n/2+i-1;
        cout << a+k << ' ' << b+k+n << ' ' << c+k+2*n << '\n';
    }
    for (int i = (n+1)/2+1; i <= n; ++i) {
        int a, b, c;
        c = n-i;
        b = n-2*(i-(n+1)/2);
        a = i-(n+1)/2-1;
        cout << a+k << ' ' << b+k+n << ' ' << c+k+2*n << '\n';
    }

    return 0;
}


Measured memory_bytes: 2304
import math
N = int(input())
X = list(map(int, input().split()))

def average(a):
  return sum(a) / len(a)

avg = average(X)

res = 0
if avg - int(avg) >= 0.5:
  for i in X:
    res += (i - math.ceil(avg)) **2
else:
  for i in X:
    res += (i - math.floor(avg)) ** 2
print(res)

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

using namespace std;

int N, A[200005], B[200005];
vector<int> Adj[200005];
vector<int> V[200005];

int REC(int k, int p) {

	int ret = 0;
	for (auto y : Adj[k]) {
		if (y == p) { continue; }
		int tmp = REC(y, k);
		V[k].push_back(tmp);
		ret += tmp;
	}

	ret++;
	return ret;
}

long long int MOD = 1000000007;
long long int P[200005];

long long int POW(long long int a, long long int k) {
	if (k == 0) { return 1; }
	if (k == 1) { return a; }

	if (k % 2 == 1) { return (a*POW(a, k - 1)) % MOD; }

	long long int ret = POW(a, k / 2);

	return (ret*ret) % MOD;
}

long long int INV(long long int val) {
	return POW(val, MOD - 2);
}

int main(void) {

	cin >> N;
	for (int i = 1; i <= N - 1; i++) { cin >> A[i] >> B[i];
	Adj[A[i]].push_back(B[i]);
	Adj[B[i]].push_back(A[i]);
	}

	REC(1, -1);

	for (int i = 1; i <= N; i++) {
		if (Adj[i].size() == V[i].size()) { continue; }
		int tmp = 0;
		for (auto num : V[i]) { tmp += num; }
		V[i].push_back(N - 1 - tmp);
	}

	/*for (int i = 1; i <= N; i++) {
		cout << i << " ";
		for (auto x : V[i]) { cout << " " << x; }cout << endl;
	}*/

	P[0] = 1;
	for (int i = 1; i <= 200000; i++) {
		P[i] = P[i - 1] * 2;
		P[i] %= MOD;
	}

	/*for (int i = 0; i <= 30; i++) {
		cout << i << " P[" << i << "]= " << P[i] << " " << (P[i] * INV(P[i]))%MOD << endl;
	}*/

	long long int ans = 0;

	for (int i = 1; i <= N; i++) {
		if (Adj[i].size() == 1) { continue; }
		long long int tmp = 1;
		for (auto k : V[i]) {
			tmp *= P[k];
			tmp %= MOD;
		}
		//=======//
		tmp = (tmp - 1 + MOD) % MOD;
		for (auto k : V[i]) {
			tmp = (tmp - P[k] + 1 + MOD) % MOD;
		}
		ans += tmp;
		ans %= MOD;
	}

	//cout << ans << endl;

	ans *= INV(P[N]);
	ans %= MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 36352
require 'matrix'

n, m, x = gets.split.map(&:to_i)
a = Matrix.zero(n, m + 1)
n.times do |i|
  b = gets.split.map(&:to_i)
  0.upto(m) do |j|
    a[i, j] = b[j]
  end
end
min = Float::INFINITY
[0, 1].repeated_permutation(n) do |bit|
  ans = 0
  sum = 0
  1.upto(m) do |j|
    sum = (a.column(j).covector * Vector.elements(bit))[0]
    break if sum < x
  end
  if sum >= x
    ans = (a.column(0).covector * Vector.elements(bit))[0]
    min = ans if min > ans
  end
end
puts (min == Float::INFINITY ? -1 : min)

Measured memory_bytes: 15124
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const input = Number(lines[0]);

  //数字の配列
  const inputs = lines[1].split(" ").map(Number);

  for (let i = inputs[0]; i <= inputs[1]; i++) {
    if (i % input === 0) {
      console.log("OK");
      return;
    }
  }

  console.log("NG");
});


Measured memory_bytes: 30076
N,Ma,Mb=map(int,input().split())

dp = [[10**18 for _ in range(401)] for _ in range(401)]

dp[0][0]=0
for i in range(N):
    a,b,c=map(int,input().split())
    for ca in range(i * 10, -1, -1):
        for cb in range(i * 10, -1, -1):
            dp[ca+a][cb+b] = min(dp[ca+a][cb+b],dp[ca][cb]+c)

ans = 10**18
for ca in range(401):
    for cb in range(401):
        if not ca*Mb == cb*Ma or ca == 0:
            continue
        if ans > dp[ca][cb]:
            ans = dp[ca][cb]
        
if ans == 10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 4852
#include <cstdio>
using namespace std;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

const int is = 1 << 20;
char ib[is], *ip = ib + is, it;
inline char getc() {
	if (ip == ib + is) { fread_unlocked(ib, 1, is, stdin); ip = ib; }
	return *ip++;
}
inline int read() {
	int r = 0;
	if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
	else while ((it = *ip++) & 16) r = r * 10 + it - '0';
	return r;
}

const int os = 1 << 20;
char ob[os], *op = ob, ot;
inline void putc(const char c) {
	*op++ = c;
	if (op == ob + os) { fwrite_unlocked(ob, 1, os, stdout); op = ob; }
}
// x shoud be greater than or equal to zero
inline void write(int x) {
	char d[6];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putc(d[i]);
	}
}

int A[200000];
signed main() {
	int n = read();
	int m0 = 0;
	int m1 = 0;
	REP(i, n) {
		int a = read();
		if (a > m0) {
			m1 = m0;
			m0 = a;
		} else if (a > m1) {
			m1 = a;
		}
		A[i] = a;
	}
	REP(i, n) {
		int a = A[i];
		if (a == m0) {
			write(m1);
		} else {
			write(m0);
		}
		putc('\n');
	}
	fwrite_unlocked(ob, 1, op - ob, stdout);
}


Measured memory_bytes: 4352
N, K = map(int, input().split())
X = list(map(int, input().split()))

def bsr_sub(a, v, l, r):
	if r < l:
		return l
	m = (l + r) // 2
	#print(l, m, r)
	if v < a[m]:
		return bsr_sub(a, v, l, m - 1)
	else:
		return bsr_sub(a, v, m + 1, r)

def bsr(a, v):
	return bsr_sub(a, v, 0, len(a) - 1)

cost, center = [], bsr(X, 0)
for l in range(max(0, center - K), min(N - K + 1, center + 1)):
	#print(l, center, l + K - 1)
	cost += [min([abs(X[l]), abs(X[l + K - 1])]) + (X[l + K - 1] - X[l])]

print(min(cost))


Measured memory_bytes: 14844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   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;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
  int main(){
      lint n,m;
      cin>>n>>m;
      vector<vector<lint>> x(m);
      UnionFind uf(n);
      rep(i,n){
          lint k;
          cin>>k;
          rep(j,k){
              lint a;
              cin>>a;
              --a;
               x[a].push_back(i);
                uf.unite(x[a][0],i);
                        }
      }
      rep(i,n-1){
          if(!uf.same(i,i+1)){
              cout<<"NO";
              return 0;
          }
      }
      cout<<"YES";
  }
  
  
     
  

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define U 10050
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#define sp
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	char ch = next<char>();
	if ('a' <= ch && ch <= 'z') cout<<'a'<<endl;
	else cout<<'A'<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

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


def read():
    S = input().strip()
    return S,


def solve(S):
    if S[-1] == "s":
        return S + "es"
    return S + "s"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9032
# ABC154 D Dice in Line

import itertools

n, k = map(int, input().split())
p_list = [int(x) for x in input().split()]
e_list = [None]*n

for i in range(n):
    e_list[i] = (1 + p_list[i])/2

cumsum = list(itertools.accumulate(e_list))
ans = cumsum[k-1]

for i in range(k,n):
    _ = cumsum[i] - cumsum[i-k]
    if ans < _:
        ans = _

print(ans)

Measured memory_bytes: 25152
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()

Anew = []
for i in range(N):
    Anew.append((A[i],i))
Anew.sort(key=lambda x:(-x[0],x[1]))

dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
    for j in range(N):
        if i == 0 and j == 0:
            continue
        if i+j > N:
            continue
        elif i == 0:
            dp[i][j] = dp[i][j-1] + abs(Anew[j-1][1]-(N-j))*Anew[j-1][0]
        elif j == 0:
            dp[i][j] = dp[i-1][j] + abs(Anew[i-1][1]-(i-1))*Anew[i-1][0]
        else:
            val1 = dp[i][j-1] + abs(Anew[i+j-1][1]-(N-j))*Anew[i+j-1][0]
            val2 = dp[i-1][j] + abs(Anew[i+j-1][1]-(i-1))*Anew[i+j-1][0]
            dp[i][j] = max(val1,val2)

ans = 0
for i in range(N):
    if dp[i][N-i] >= ans:
        ans = dp[i][N-i]

print(ans)

Measured memory_bytes: 100608
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        boolean flag = true;

        StringBuffer buf = new StringBuffer();

        int n = in.nextInt();
        int[] raw = new int[n];

        for (int i = 0; i < n; i++) {
            raw[i] = in.nextInt();
        }
        int cnt = 0;

        while (flag) {

            flag = false;

            int init = n-1;
            for (int j = init; j >= 1; j--) {
                if (raw[j] < raw[j-1]) {
                    int tmp1 = raw[j];
                    int tmp2 = raw[j-1];
                    raw[j] = tmp2;
                    raw[j-1] = tmp1;
                    cnt++;
                    flag = true;
                }

            }
        }
        for (int k = 0; k < n; k++) {
            System.out.print(raw[k]);
            if (k != n -1) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);

    }
}



Measured memory_bytes: 26592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    intt n;
    scanf("%lld", &n);
    intt ans = (n-1)*n/2;
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

long search(long h){
    if(h == 1) return 1;
    else return 2*search(h/2) + 1;
}

int main(){
    long h;
    cin >> h;
    cout << search(h) << endl;
}


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

int main(){
  long long int n;
  cin>>n;
  vector<long long int> a(3*n);
  for(int i=0;i<3*n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  long long int ans=0;
  for(int i=3*n-2;i>n-1;i-=2){
    ans+=a[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(void){
    int n,i,cnt=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=1;i<n-1;i++){
        if(a[i-1]<a[i] && a[i]<a[i+1] || a[i-1]>a[i] && a[i]>a[i+1]) cnt++;
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<ll> a(n);
	vector<ll> b(n);
	vector<ll> c(n - 1);

	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	for (int i = 0; i < n; i++)
	{
		cin >> b.at(i);
	}

	for (int i = 0; i < n - 1; i++)
	{
		cin >> c.at(i);
	}

	ll old = -1;
	ull ans = 0;

	for (int i = 0; i < n; i++)
	{
		ans += b.at(a.at(i) - 1);
		if (old == a.at(i) - 1)
		{
			ans += c.at(old - 1);
		}
		old = a.at(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
	int ans = 0;
	char s[200005];
	char t[200005];
	int i;

	fgets(s, sizeof(s), stdin);

	fgets(t, sizeof(t), stdin);

	for(i=0; i<strlen(s); i++) {
		if(s[i] != t[i]) {
			ans = ans + 1;
		}
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 1984
#include <iostream>
using namespace std;
bool exist[100001];
int main(void) {
  int n;
  cin >> n;
  int dup = 0;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (exist[a]) dup++;
    else exist[a] = 1;
  }
  cout << n - dup - dup % 2 << endl;
  return 0;
}

Measured memory_bytes: 384
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def main():
    A, B, C, K = map(int, input().split())
    if K <= A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A - (K - (A + B)))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  s <- map digitToInt <$> getLine
  print . sum $ combi s

combi s = do
  i <- [1..(length s)]
  let (former, latter) = splitAt i s
      formerNum = calc former
  if null latter
    then return formerNum
    else map (+ formerNum) (combi latter)


calc = foldl' (\acc i -> acc * 10 + i) 0

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

/* Segment Tree -----------*/
template <typename M>
class SegmentTree {
    using F = std::function< M(M, M) >;
private:
    int n;
    F func;
    M M_init;
public:
    std::vector<M> t;
    // constructor
    SegmentTree(int &n, F func, const M &M_init): n(n), func(func), M_init(M_init) { t.assign(2*n, M_init); }
    SegmentTree(std::vector<M> &vec, F func, const M &M_init): n(vec.size()), func(func), M_init(M_init) {
        t.assign(2*vec.size(), M_init);
        for(int i = 0; i < vec.size(); ++i) t[i+vec.size()] = vec[i];
    }

    void build() {  // build segment tree
        for(int i = n-1; i > 1; --i) t[i] = func(t[i<<1], t[i<<1|1]);
    }
    void modify(int p, M val) {  // update value at position p
        for(t[p += n] = val; p > 1; p >>= 1) t[p>>1] = func(t[p], t[p^1]);
    }
    M query(int l, int r) {  // reply to query [l, r)
        M resl = M_init, resr = M_init;
        for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if(l & 1) resl = func(resl, t[l++]);
            if(r & 1) resr = func(t[--r], resr);
        }
        return func(resl, resr);
    }
    M operator[](const int &k) const {return t[k+n];}  // mustn't use to input
};

/*FUNCs=================================================*/
long long GCD(long long a, long long b){
    return (b ? GCD(b, a%b) : a);
}
/*MAIN==================================================*/
signed main(){
    using namespace std;

    // input
    int n; cin >> n;
    vector<long long> aa(n);
    for (int i = 0; i < n; ++i) cin >> aa[i];

    // build
    SegmentTree<long long> a(aa, [](long long p, long long q){ return GCD(p,q);}, 0LL);
    a.build();

    // solve
    long long ans = -1, pp;

    for(int i = 0; i < n; ++i) {
        if(i==0) pp = a.query(1, n);
        else if(i==n-1) pp =a.query(0, n-1);
        else pp = GCD(a.query(0,i), a.query(i+1, n));
        ans = max(ans, pp);
    }
    // output
    cout << ans << '\n';
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int cnt[1000000];
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {

        cin>>a[i];
        cnt[a[i]]++;
    }
//     for(int i=0; i<n; i++)
//    {
//
//
//        cout<<cnt[a[i]]<<" ";
//    }
    int maxi=-1,ans,s;
    for(int i=0;i<n;i++)
    {

        if(a[i]!=0)
            s=cnt[a[i]]+cnt[a[i]-1]+cnt[a[i]+1];
        else
            s=cnt[a[i]]+cnt[a[i]+1];
//            cout<<s<<endl;
        if(s>=maxi)
        {
            maxi=s;

        }
    }
    cout<<maxi;

}



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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string s;
    cin >> s;

    ll nums[10] = {0};
    rep(i, s.size()){
        nums[i] = (ll)(s[i] - 48);
    }

    ll ans = 0;
    rep(place, 1 << s.size()){
        int cp_place = place;
        ll sum = 0;
        rep(idx, s.size() - 1){
            sum = sum * 10 + nums[idx];
            if((int)(cp_place & 1) == 1){
                ans += sum;
                sum = 0;
            }
            cp_place = cp_place >> 1;
        }
        sum = sum * 10 + nums[s.size() - 1];
        ans += sum;
    }

    cout << ans / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;
int kakuketanowa(int n) {//各桁の和
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
    int cnt=0;
string s;
cin>>s;
vector<string>a={"dream","dreamer","erase","eraser"};
reverse(s.begin(),s.end());
for(int i=0;i<4;i++){
    reverse(a[i].begin(),a[i].end());
}
while(1){
    bool judge=false;
    for(int i=0;i<4;i++){
        if(s.substr(cnt,a[i].size())==a[i]){
        cnt+=a[i].size();
        judge=true;
        break;
        }
    }
    if(!judge){
        cout<<"NO"<<endl;
        break;
    }
    if(cnt==s.size()){
        cout<<"YES"<<endl;
        break;
    }
}
}











Measured memory_bytes: 512
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  ll ans = llINF;
  for(ll i = 1;i<=sqrt(n);i++){
    if(n%i == 0){
      ans = min(ans,i+n/i);
    }
  }
  cout<<ans-2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     int i,n,t,p=INT_MAX,j=0,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     string s;
     cin>>s;
     for(i=0;i<s.size();i++){
        if(s[i]=='7'){
            l=1;
        }
     }
     (l==1)?cout<<"Yes"<<endl:cout<<"No"<<endl;
 
     return EXIT_SUCCESS;
}

Measured memory_bytes: 3652
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n

for i in range(1,n):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[n-1])



Measured memory_bytes: 13980
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var ai = Sarray();
            var nums = new Dictionary<long, long>();
            foreach (var a in ai)
            {
                if (!nums.ContainsKey(a)) nums[a] = 0;
                ++nums[a];
            }
            var ans = 0L;
            foreach (var kv in nums)
                if (kv.Key < kv.Value) ans += kv.Value - kv.Key;
                else if (kv.Value < kv.Key) ans += kv.Value;
            WriteLine(ans);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 43468
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    vector<int> A(n);
    REP(i, n) cin >> A[i];
    whole(sort, A);
    cout << A.back() - A.front() << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int t;
    cin >> t;
    int h = t / (60 * 60);
    t = t % (60 * 60);
    int m = t / 60;
    int s = t % 60;
    cout << h << ':' << m << ':' << s << endl;
}



Measured memory_bytes: 3116
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    sort_L = sorted(L)
    cnt = 0
    for i in range(N-2):
        for j in range(i+1,N-1):
            tmp = bisect.bisect_left(sort_L,sort_L[i] + sort_L[j])
            if tmp - 1 > j:
                cnt += tmp - j - 1
    print(cnt)

    

if __name__ == "__main__":
    main()

Measured memory_bytes: 42460
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#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(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

bool check(string s, int cnt){
	if(cnt%15 == 0) return s == "FizzBuzz";
	if(cnt%5 == 0) return s == "Buzz";
	if(cnt%3 == 0) return s == "Fizz";
	rep(i, s.size()){
		if(s[i] < '0' || s[i] > '9') return false;
	}
	return atoi(s.c_str()) == cnt;
}

int main(){
	int m, n;
	while(cin >> m >> n, m|n){
		vector<int> player(m);
		rep(i, m) player[i] = i;

		int p = 0;
		FOR(i, 1, n+1){
			string s;
			cin >> s;
			if(player.size()==1) continue;

			if(!check(s, i)) player.erase(player.begin()+p);
			else p++;
			p%=player.size();
		}
		rep(i, player.size()){
			cout << (i?" ":"") << player[i]+1;
		}
		cout << endl;
	}

	return 0;
}

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

const ll MOD = 1000000007;

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 1;
    ll k = 0;
    for(int i = 0; i < n * 2; i++){
        if((s[i] == 'B' && k % 2 == 1) || (s[i] == 'W' && k % 2 == 0)){
            ans = ans * k % MOD;
            k--;
        }
        else k++;
    }
    for(ll i = 1; i <= n; i++) ans = ans * i % MOD;
    if(k) cout << 0 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3760
#include <stdio.h>

#define INF 10000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100

void dijkstra(int);

int n,M[MAX][MAX],D[MAX],P[MAX],colr[MAX],mincost;

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] = INF;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
  
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&M[u][v]);
    }
  }

  dijkstra(0);
  
  return 0;
}

void dijkstra(int x){
  int i,u,v;

  for(u=0;u<n;u++){
    colr[u] = WHITE;
    D[u] = INF;
  }

  D[x] = 0;
  P[x] = -1;
  colr[x] = GRAY;
  
  while(1){
    mincost = INF;
    u = -1;
    for(i=0;i<n;i++){

      if(colr[i] != BLACK && D[i] < mincost){
        mincost = D[i];
        u = i;
      }
    }

    if(u == -1)break;

    colr[u] = BLACK;
    
    for(v=0;v<n;v++){
      if(colr[v] != BLACK && M[u][v] != INF){
        if(D[u] + M[u][v] < D[v]){
          D[v] = D[u] + M[u][v];
          P[v] = u;
          colr[v] = GRAY;
        }
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i,(D[i] == INF ? -1 : D[i]));
  }
}




Measured memory_bytes: 2048
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<ll> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

// 最大公約数を求める
ll gcd(ll a,ll b){
	return b>0?gcd(b,a%b):a;
}
// 最小公倍数を求める
ll lcm(ll a,ll b){
	a = a/gcd(a,b);
	if(b!=0 && a>LONG_MAX/b) return 0;
	return a*b;
}
int n;
ll m;
main(){
	while(cin >> n >> m){
		vi a(n), p(n);
		REP(i, n) cin >> a[i];
		REP(i, n) cin >> p[i];
		vi dp(1<<n);
		REP(i, 1<<n){
			if(!i) continue;
			ll l=1;
			REP(j, n)
				if(l && (i>>j)&1) l = lcm(l, a[j]);
			dp[i] = l?m/l:0;
		}
		REP(i, n)REP(j, 1<<n) if((j>>i)&1) dp[j] -= dp[j^(1<<i)];
		double ans = 0;
		REP(i, 1<<n){
			if(!i) continue;
			double pr=1.0;
			REP(j, n)
				if((i>>j)&1) pr *= p[j]/100.0;
				else pr *= (100-p[j])/100.0;
			ans += pr * abs(dp[i]);
		}
		printf("%.10f\n", ans);
	}
	return 0;
}

Measured memory_bytes: 9252