akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long a=2;
    long long b=1;
    int n;
    cin>>n;
    
    long long c;
    for(int i=0;i<n-1;i++){
        c=a+b;
        a=b;
        b=c;
    }
    cout<<b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

lli dp[105][100010];
lli n, k;
vector< pair<lli,lli> > items;

lli funcion(lli index, lli sum)
{
    if((index == items.size())and(sum<=k))
    {
        return 0;
    }
    if((index == items.size())and(sum>k))
    {
        return -10000000000LL;
    }
    if(sum > k)
    {
        return -100000000000LL;
    }
    if(sum == k)
    {
        return 0;
    }
    if(dp[index][sum] != -1)
    {
        return dp[index][sum];
    }
    lli si = funcion(index+1, sum+items[index].first) + items[index].second;
    lli no = funcion(index+1, sum);

    return dp[index][sum] = max(si,no);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp, -1, sizeof(dp));
    cin>>n>>k;
    items.resize(n);
    for(auto &x: items)
    {
        cin>>x.first>>x.second;
    }
    cout<<funcion(0,0)<<endl;

    return 0;
}

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

int m,n,k;
int J[1001][1001];
int O[1001][1001];
int I[1001][1001];

int main(){
	cin>>m>>n>>k;
	
	for(int i=0;i<=m;i++){
		J[0][i]=0;O[0][i]=0;I[0][i]=0;
	}
	for(int i=0;i<=n;i++){
		J[i][0]=0;O[i][0]=0;I[i][0]=0;
	}
	
	for(int y=1;y<=m;y++){
		int j=0,o=0,i=0;
		for(int x=1;x<=n;x++){
			char c;cin>>c;
			switch(c){
			case 'J':j++;break;
			case 'O':o++;break;
			case 'I':i++;break;
			}
			J[x][y]=J[x][y-1]+j;
			O[x][y]=O[x][y-1]+o;
			I[x][y]=I[x][y-1]+i;
		}
	}
	
	while(k--){
		int a,b,c,d;cin>>a>>b>>c>>d;
		cout<<(J[d][c]-J[b-1][c]-J[d][a-1]+J[b-1][a-1])<<' ';
		cout<<(O[d][c]-O[b-1][c]-O[d][a-1]+O[b-1][a-1])<<' ';
		cout<<(I[d][c]-I[b-1][c]-I[d][a-1]+I[b-1][a-1])<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 14852
/****************************************************

@author: vichitr
Compiled On: 10th Jan 2020

*****************************************************/
#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define ip pair<int, int>
#define F first
#define S second

#define loop(i,n) for(int i=0;i<n;i++)
#define loops(i,s,n) for(int i=s;i<=n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 1e6+7;
// const ll M = 2e5+7;

ll pwr(ll x, ll y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return r;
}

int inv(int x)
{
    return pwr(x, MOD-2ll);
}

int fact[N], n;

int nCr(int x, int y){
    int ans= fact[x];
    ans *= inv(fact[y]);
    ans %= MOD;
    ans *= inv(fact[x-y]);
    ans %= MOD;
    return ans;
}


void solve()
{ 
    int n,m; cin>>n>>m;
    map<int, int> M, WA;
    int ac = 0, p = 0;
    loop(i, m){
        int x; cin>>x;
        string s; cin>>s;
        if(M[x]) continue;
        if(s=="WA") WA[x]++;
        else {
            ac++;
            M[x] = 1;
            p += WA[x];
        }
    }
    cout<<ac<<" "<<p<<endl;
}

signed main()
{
    fast;
    int t=1;
    // cin >>t;

    // fact[0] =1;
    // for(int i=1;i<N;i++){
    //     fact[i] = fact[i-1]*i;
    //     fact[i] %= MOD;
    // }

    while(t--){
        solve();
        
    }
    return 0;
}

/*****************************

3 595

43 2

300 4

554 10


***************************/

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const int maxn=1e5+7;
ll fac[maxn];
ll inv[maxn];
ll C(int m,int n)
{
    if(m>n)
        return -1;
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
ll quick_mod(ll a,ll m)
{
    ll tmp=a%mod;
    ll ans=1;
    while(m)
    {
        if(m&1)
            ans=ans*tmp%mod;
        tmp=tmp*tmp%mod;
        m>>=1;
    }
    return ans;
}
void init()
{
    fac[0]=1;
    for(int i=1; i<maxn; i++)
        fac[i]=(fac[i-1]*i)%mod;
    inv[maxn-1]=quick_mod(fac[maxn-1],mod-2);
    for(int i=maxn-2; i>=0; i--)
        inv[i]=(inv[i+1]*(i+1))%mod;
}
int n,k;
long long ans=1;
vector<int>g[100005];
int main()
{
    init();
    scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
	{
		int x,y;
		x=g[i].size()-1;
		y=k-2;
		if(i==1)
			y++,x++;
		if(y<x)
		{
			printf("0");
			return 0;
		}
		long long ret=1;
		for(int j=y,ii=1;ii<=x;ii++,j--)
			(ret*=j)%=mod;
		ans=(ans*ret)%mod;
	}
	printf("%lld",(ans*k)%mod);
}


Measured memory_bytes: 7672
#include <iostream>

using namespace std;

long long N,x;
long long a[100000];

int main(){
    long long count = 0;
    cin >> N >> x;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=1;i<N;i++){
        long long t = a[i] + a[i-1] - x;
        if(t > 0){
            if(a[i] >= t){
                a[i] -= t;
            }else{
                a[i] = 0;
            }
            count += t;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    vector<int> l(n);

    ll sum = 0;
    rep(i,n){
        cin >> l[i];
        sum += l[i];
    }

    if(sum <= x){
        dunk(n+1);
        return 0;
    }

    int cnt = 0;
    int ln = 0;

    rep(i,n){
        if(ln > x) break;
        ln += l[i];
        cnt++;
    }

    dunk(cnt);
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX= 3007;



int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n ;
    vector< double > p(n+1);
    for(int i = 1; i <= n ; i++) {
        cin >> p[i];
    }   

    vector< vector<double> > dp(3, vector<double> (n+1,0));
    dp[0][0] = 1;
    for(int i = 1 ; i <= n ; i++) {
        for(int j = 0 ; j<=i ; j++) {
            int old , current;
            if( i % 2 == 1) {
                old = 0;
                current = 1;
        
            } else {
                old = 1;
                current = 0;
            }
            dp[current][j] = dp[old][j-1] * p[i] + dp[old][j] * ( 1 - p[i]);
        }
    }
    double res = 0;
    for(int head = 0 ; head <= n ; head++) {
        int tail = n - head;
        if( head > tail) {
            res += dp[1][head];
        }
    }

    cout.precision(12);
    cout<<fixed<<res<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
 set<ll> S;
  for(ll i=0;i<N;i++) {
ll A;
    cin>>A;
    if(S.count(A)) {
cout<<"NO"<<endl;
      return 0;
    }
    S.insert(A);
  }
  
  cout<<"YES"<<endl;
}


Measured memory_bytes: 12972
def per(n, r, mod=10**9+7):  # 順列数
    per = 1
    for i in range(r):
        per = per*(n-i) % mod
    return per
 
 
def com(n, r, mod=10**9+7):  # 組み合わせ数
    bunshi = per(n, r, mod)
    bunbo = 1
    for i in range(1, r+1):
        bunbo = bunbo*i % mod
    return bunshi*pow(bunbo, -1, mod)%mod
 
 
n, a, b = map(int, input().split())
 
ans = pow(2,n,10**9+7)
 
print((ans-com(n,a)-com(n,b)-1)%(10**9+7))

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std; 
#define loop for(int i=0;i<n;i++)
#define pb push_back
#define int long long int
#define vi vector<int>
#define mod 1000000007
int32_t main()
{
	int n;
	int m;
	cin>>n>>m;
	int val[n+20];
	for(int i=1;i<=n;i++)
	{
		int k;
		cin>>k;
		val[i]=k;
		}
	vector<int> adj[n+1];
	while(m--)
	{
		int u;
		int v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int flag=true;
		for(auto j:adj[i])
		{
			if(val[j]>=val[i])
			{
				flag=false;
				break;
			}
		}
		if(flag==true){
//cout<<i<<endl;
			ans++;
		}
	}
	cout<<ans;

}


Measured memory_bytes: 10256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int myMax(int num[], int length);

int main() {
	int N;
	scanf("%d", &N);
	int p[30];
	int sum = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &p[i]);
		sum += p[i];
	}
	printf("%d", sum - myMax(p, N) / 2);

}

//---配列の最大値を求める---
int myMax(int num[], int length) {
	int temp = c_mINF;
	for (int i = 0; i < length; i++) {
		temp = max(temp, num[i]);
	}
	return temp;
}



/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
<?php
  	fscanf(STDIN, "%d", $n);
	$p = explode(" ", trim(fgets(STDIN)));
	$ordinaryCount = 0;
	
	for ($i=1;$i<$n-1;$i++) {
      	$p_part = array_slice($p, $i-1, 3);
      	$target = $p_part[1];
      	sort($p_part);
      	if (array_search($target, $p_part) == 1) {
          	$ordinaryCount++;
        }
    }

	echo $ordinaryCount;

Measured memory_bytes: 3828
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score=-1000000000;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  if(score<=keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    ans1[randxor()%d]=randxor()%26;
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=i%26;
    ans[i]=ans1[i];
  }
  while(clock()-ti<197.9*CLOCKS_PER_SEC/100){
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3880
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N; long long T; cin >> N >> T;
	vector<long long> t(N+1);
	for (int i = 0; i < N; i++)cin >> t[i];
	t[N] = 1e10;
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		if (t[i + 1] - t[i] >= T)ans += T;
		else ans += t[i + 1] - t[i];
	}
	cout << ans << endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

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

    cout << max(0,A - 2*B);
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
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;}

// combination mod prime
// mintが必要
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};



int main(){
    int n,k;
    cin >> n >> k;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    mint M=0,m=0;
    combination c(n);
    sort(a.begin(),a.end());
    rep(i,n-k+1){
        m+=c(n-i-1,k-1)*a[i];
    }
    reverse(a.begin(),a.end());
    rep(i,n-k+1){
        M+=c(n-i-1,k-1)*a[i];
    }
    mint ans = M-m;
    cout << ans.x << endl;
    
    return 0;
}

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

#define MAX 2000000
#define INFTY 1<<30;

int H, A[MAX+1];

void maxHeapify(int i){
    int l = i*2;
    int r = i*2+1;
    int largest;
    
    if(l <= H && A[l] > A[i])   largest = l;
    else                        largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;
    
    if(largest != i){
        swap(A[largest], A[i]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    if(H < 1)   return -INFTY;

    maxv = A[1];
    A[1]= A[H--];
    maxHeapify(1);
    return maxv;
}

void heapIncreasseKey(int i, int key){
    if(key < A[i]) return;
    A[i] = key;
    while(i > 1 && A[i/2] < A[i]){
        swap(A[i/2], A[i]);
        i = i/2;
    }
}

void insert(int key){
    H++;
    A[H] = -INFTY;
    heapIncreasseKey(H, key);
}

int main(){
    int key;
    char com[10];

    while(1){
        cin >> com;
        if(com[0] == 'e' && com[1] == 'n')  break;

        if(com[0] == 'i'){
            cin >> key;
            insert(key); 
        }else{
            cout << extract() << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 6908
import math
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

diff = sum(b) - sum(a)
if diff < 0:
    print("No")
else:
    count = 0
    count2 = 0
    for i in range(N):
        if a[i] > b[i]:
            count += a[i] - b[i]
        elif a[i] < b[i]:
            count2 += math.ceil((b[i] - a[i])/2)
    if max(count, count2) > diff:
        print("No")
    else:
        print("Yes")


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a>b){
    swap(a,b);
  }
  if(b>c){
    swap(b,c);
  }
  if(b>c){
    swap(b,c);
  }
   if(a>b){
    swap(a,b);
   }
  cout<<a<<' '<<b<<' '<<c<<endl;

}





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

using namespace std;

int h, w;

void f(vector<vector<bool>>& board, vector<vector<bool>>& visited,int& num_black, int& num_white, int hi, int wi){
    if(visited[hi][wi]) return;
    bool color=board[hi][wi];
    if(color) ++num_black;
    else ++num_white;
    visited[hi][wi]=true;
    if(hi>0 && board[hi-1][wi]!=color) f(board, visited, num_black, num_white, hi-1, wi);
    if(hi+1<h && board[hi+1][wi]!=color) f(board, visited, num_black, num_white, hi+1, wi);
    if(wi>0 && board[hi][wi-1]!=color) f(board, visited, num_black, num_white, hi, wi-1);
    if(wi+1<w && board[hi][wi+1]!=color) f(board, visited, num_black, num_white, hi, wi+1);
}

int main(){
    cin >> h >> w;
    auto board=vector<vector<bool>>(h, vector<bool>(w));
    auto visited=vector<vector<bool>>(h, vector<bool>(w, false));
    for(int hi=0; hi<h; ++hi){
        string s;
        cin >> s;
        for(int wi=0; wi<w; ++wi){
            board[hi][wi]= s[wi]=='#';
        }
    }
    long long result=0;
    for(int hi=0; hi<h; ++hi){
        for(int wi=0; wi<w; ++wi){
            int num_black=0, num_white=0;
            f(board, visited, num_black, num_white, hi, wi);
            result+=(long long)num_black*num_white;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 20224
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

bool isPrime(ll x){
    if(x == 2)return 1;
    else if(x < 2 || x%2 == 0)return 0;
    else{
        double sq = sqrt(x);
        for(int i = 3;i<=sq;i+=2)if(x%i == 0)return 0;
        return 1;
    }
}

int main() {
    vector<bool> p(1e5+1,0);
    vector<ll> psum(1e5+1,0);
    rep(i,1e5+1){
        p.at(i) = isPrime(i);
    }
    
    rep(i,1e5+1){
        if(i != 1){
            psum[i] = psum[i-1];
            if(p[i] && p[(i+1)/2])psum[i]++;

        }
    }
    psum[0] = 0;
    ll q;
    cin >> q;
    rep(i,q){
        ll l,r;
        cin >> l >> r;
        ll ans = psum[r] - psum[l-1];
        if(l != r)cout << ans << endl;
        else if(psum[l-1] != psum[l])cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
#define M 1000000007
using namespace std;
long long int arr1[110000]={},arr2[110000]={};
int main(){
  long long int mx=0,mx1=0,mx2=0;
  long long int ans=0;
  int N;
  scanf("%d",&N);
  for(int i=1;i<=N;i++){
    scanf("%lld",&arr1[i]);
    mx1=max(arr1[i],mx1);
  }
  for(int i=1;i<=N;i++){
    scanf("%lld",&arr2[i]);
    mx2=max(arr2[i],mx2);
  }
  for(int i=1;i<=N;i++){
    if(arr1[i]==arr2[i])ans=1;
  }
  if(mx1!=mx2)ans=0;
  mx=mx1;
  for(int i=1;i<=N;i++){
    if(arr1[i]==arr2[i]&&arr1[i]!=mx)ans=0;
  }
  for(int i=1;arr1[i]!=arr2[i];i++){
    if(arr1[i]==arr1[i-1]){
      ans*=arr1[i];
    }
    ans%=M;
  }
  for(int i=N;arr1[i]>=arr2[i]&&i>=0;i--){
    if(arr2[i]==arr2[i+1]&&arr1[i]==arr1[i-1]){
      ans*=arr2[i];
    }
    ans%=M;
  }
  printf("%lld",ans);
}


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

int main() {
    int k;
    cin>>k;
  string str1;
  cin >> str1;
  int s;
  s= str1.size() ;
  std::string sub = str1.substr(0, k); 
  if(k>=s){
      cout<<str1<<endl;
  }
  else if(k<s){
    
      cout<<sub<<"..."<<endl;
 
}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define double long double
#define int long long 
#define f(z) for(int i=1;i<=z;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
int cl(int n ,int m) { if(n%m)return n/m + 1 ;else return n/m ;}
int pw(int a,int b,int M){a%=M;int r=1;while(b>0){if(b&1)r=r*a%M;a=a*a%M;b>>=1;}return r;}
#define mod  1000000007
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e6 + 5  ;

signed main(){
	string s; 
	cin >> s; 
	REP(i,0,2) if( s[i] == '7') {
		cout <<"Yes\n" ;
		exit(0); 
	}
	cout<<"No";
}

Measured memory_bytes: 3616
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			var a = cin.ArrayLong(n);

			long ans = 0;
			long rem = 0;
			for (int i = 0; i < n; i++) {
				ans += (a[i] + rem) / 2;
				if (a[i] == 0) {
					rem = 0;
				} else {
					rem = (a[i] + rem) % 2;
				}
			}

			Console.WriteLine(ans);
		}
	}


	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 17328
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.
	var splitInput = input.split("\n");
	var n = (splitInput[0])
	var a = (splitInput[1])
	var b = (splitInput[2])
	var c = (splitInput[3])
	
	var result = 0
	
	for (var i=0; i<n; i++){
		if (a[i] == b[i] && a[i] == c[i]) {
			result += 0
		} else if (a[i] == b[i] || a[i] == c[i] || c[i] == b[i]) {
			result += 1
		} else {
			result += 2
		}
	}
	
	//output
	console.log('%d',result);
}
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
	stack<int> st;
	string str;
	while(cin >> str){
		char c = str[0];
		if(isdigit(c)){
			st.push(stoi(str));
		}else{
			int y = st.top();st.pop();
			int x = st.top();st.pop();
			if(c == '+'){
				st.push(x+y);
			}else if(c == '-'){
				st.push(x-y);
			}else if(c == '*'){
				st.push(x*y);
			}
		}
		cin.ignore();
	}
	cout << st.top() << endl;
	
	return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	int n, val;
  	int fail = 0;
  	cin >> n;
  	for(int i = 0; i < n; i++) {
    	cin >> val;
      	if (val % 2 == 0) {
        	if (val % 3 != 0 && val % 5 != 0) {
            	fail += 1;
            }
        }
    }
    if (fail == 0) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	unsigned int N, K, ans = 0, i = 0;
	scanf("%d %d", &N, &K);
	ans = K;
	for( i = 1; i < N; i++ ){
		ans *= K - 1;
	}
	printf("%u\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long int
int ans=0;
int h[1<<21]={0};
int dp[1<<22][22];
main() {
    int n;
    cin>>n;
    double a[n+5];
    double ans=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ans+=((double)1/a[i]);
    }
    ans=(double)1/ans;
    printf("%.10lf",ans);
    // cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
import itertools

n = int(input())
xy = []
sum_xy = 0

for i in range(n):
    a = list(map(int, input().split()))
    xy.append(a)

xy_itertools = list(itertools.permutations(xy, n))
fac = math.factorial(n)

for i in range(fac):
    for j in range(n):
        if j != n - 1:
            a = math.sqrt((((xy_itertools[i][j][0] - xy_itertools[i][j + 1][0])) ** 2) + (((xy_itertools[i][j][1] - xy_itertools[i][j + 1][1])) ** 2))
            sum_xy += a

print(sum_xy / fac)


Measured memory_bytes: 8052
#include <stdio.h>
int main(void){
   
   int H, W;
   int i, t;
   
   while(1){
        scanf("%d %d\n", &H, &W);
        if(H == 0 && W == 0) break;
        for(i = 0; i < H; i++){
            for(t = 0; t < W; t++){
                if (i == 0 || t == 0 || i == H -1 || t == W -1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
   }
   
  return 0;
   
}

Measured memory_bytes: 576
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_H = 300000;
int h, w, m;
int cntr[MAX_H];
int cntc[MAX_H];
vi idx[MAX_H];

int main() {
    fastio();

    cin >> h >> w >> m;

    multiset<int, greater<int>> curc;
    forn(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        cntr[a]++;
        cntc[b]++;
        idx[a].push_back(b);
    }

    forn(i, w) {
        curc.insert(cntc[i]);
    }

    int ans = 0;
    forn(i, h) {
        for (auto j : idx[i]) {
            curc.erase(curc.find(cntc[j]));
            curc.insert(cntc[j] - 1);
        }

        chmax(ans, cntr[i] + *curc.begin());

        for (auto j : idx[i]) {
            curc.erase(curc.find(cntc[j] - 1));
            curc.insert(cntc[j]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 36484
n, k = gets.split.map(&:to_i)
weights = []
n.times {weights << gets.to_i}

#最大積載量pのとき積める荷物の数
pack_num = ->(p) {
  i = truck_n = 0
  while truck_n < k
    truck_w = 0
    while i < n
      truck_w += weights[i]
      break if truck_w > p.to_i
      i += 1
    end
    truck_n += 1
  end
  i
}

left, right = 0.0, 100_000 * 10_000
until right - left < 1
  mid = (left + right) / 2
  num = pack_num.(mid)
  if num >= n
    right = mid
  else
    left  = mid
  end
end
puts right.to_i


Measured memory_bytes: 8928
#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e9 + 7;
const int F = (int)2e5 + 5;
long long a[F];

int main()
{
	int N, K;
	cin >> N >> K;
	a[0] = 0;
	for (int i = 1; i <= N; ++i) {
		a[i] = a[i - 1] + i;
	}
	long long ans = 0;
	for (int i = K; i <= N + 1; ++i) {
		ans = (ans + (a[N] - a[N-i] - a[i-1] + 1)) % M;
	}
	cout << ans;
	

}




Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;
    --t;
    vector<vector<int>> edge(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a;
        --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> ds(n, -1);
    vector<int> cs(n, 0);
    queue<int> q;
    q.push(s);
    ds[s] = 0;
    ++cs[0];
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i : edge[p]) {
            if (ds[i] == -1) {
                ds[i] = ds[p] + 1;
                ++cs[ds[i]];
                q.push(i);
            }
        }
    }
    vector<int> dt(n, -1);
    vector<int> ct(n, 0);
    q.push(t);
    dt[t] = 0;
    ++ct[0];
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i : edge[p]) {
            if (dt[i] == -1) {
                dt[i] = dt[p] + 1;
                ++ct[dt[i]];
                q.push(i);
            }
        }
    }
    int l = ds[t] - 1;
    long long ans = 0;
    for (int i = 0; i <= l; ++i) {
        ans += cs[i] * (long long)ct[l - i - 1];
    }
    cout << ans << "\n";
    return 0;
}

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

int c[12][12],a[210][210];

int main(void){
	int h,w,i,j,k,ans=0;
	cin >> h >> w;
	for(i=0; i<=9; i++){
		for(j=0; j<=9; j++){
			cin >> c[i][j];
		}
	}
	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			cin >> a[i][j];
		}
	}
	
	for(k=0; k<=9; k++){
		for(i=0; i<=9; i++){
			for(j=0; j<=9; j++){
				if( c[i][j] > (c[i][k]+c[k][j]) ){
					c[i][j] = (c[i][k]+c[k][j]);
				}
			}
		}
	}

	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			if(a[i][j]!=-1){
				ans += c[a[i][j]][1];
			}
		}
	}

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


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();
        int t = 0;
        t = x;
        x = y;
        y = t;
        t = x;
        x = z;
        z = t;
        System.out.println(x+ " "+y+" "+z);
    }
}


Measured memory_bytes: 21588
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
	//カード枚数
	int card_num;

	int pt_taro = 0;	//太郎のポイント
	int pt_hanako = 0;	//花子のポイント

	//太郎のカードに書かれている文字列
	string card_taro;

	//花子のカードに書かれている文字列
	string card_hanako;

	//カード枚数を入力
	cin >> card_num;

	for(int i = 0; i < card_num; i++)
	{
		//カード情報を入力
		cin >> card_taro >> card_hanako;

		if( card_taro > card_hanako)	//太郎の勝ち
		{
			pt_taro += 3;
		}
		else if(card_taro < card_hanako)	//花子の勝ち
		{
			pt_hanako += 3;
		}
		else
		{	
			//引き分けの場合は両者に１ポイント
			pt_taro++;
			pt_hanako++;
		}
	}

	//得点を出力
	cout << pt_taro << " " << pt_hanako << endl;

	return 0;
}



Measured memory_bytes: 3140
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int main(void)
{
	int a, b;
	char c;
	scanf("%d %c %d",&a,&c,&b);
	if (c == '+')
	{
		printf("%d",a+b);
	}
	else
	{
		printf("%d",a-b);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};
 
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;}

int N,M;
int a[2000],b[2000];
int c[2000][2000]; 

int dp[2000][6000];
int ans=INF;

void init(){
    for(int i=0;i<2000;++i)for(int j=0;j<6000;++j)dp[i][j]=INF;
}

signed main(){
    init();
    cin>>N>>M;
    for(int i=0;i<M;++i){
        cin>>a[i]>>b[i];
        for(int j=0;j<b[i];++j){
            cin>>c[i][j];
            c[i][j]--;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<M;++i){
        for(int j=0;j<(1<<N)-1;++j){
            chmin(dp[i+1][j],dp[i][j]);
            int nj=j;
            for(int k=0;k<b[i];++k){
                if((j>>c[i][k])&1)continue;
                nj+=(1<<c[i][k]);
            }
            chmin(dp[i+1][nj],dp[i][j]+a[i]);
        }
    }
    for(int i=0;i<=M;++i){
        chmin(ans,dp[i][(1<<N)-1]);
    }
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 101372
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

constexpr ll mod = 998244353LL;
long long powmod(long long x, long long n) {
    long long ret = 1LL;
    long long t = x % mod;
    while (n > 0) {
        if (n & 1LL) {
            ret *= t;
            ret %= mod;
        }
        t *= t;
        t %= mod;
        n >>= 1;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<ll> c(n);
    bool valid = true;
    for (int i = 0; i < n; ++i) {
        int d;
        cin >> d;
        ++c[d];
        if (i == 0 && d != 0)
            valid = false;
    }

    int idx_max = n - 1;
    while (c[idx_max] == 0) {
        --idx_max;
    }

    ll ans = 1;
    for (int i = 1; i <= idx_max; ++i) {
        ans *= powmod(c[i - 1], c[i]);
        ans %= mod;
    }

    if (c[0] != 1)
        ans = 0;
    
    if (!valid)
        ans = 0;

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}

template<typename T>
struct BIT {
    // 0 indexed
    int n;
    vector<T> bit;
    
    BIT(vector<T> v) {
        n = sz(v);
        bit.resize(n);
        rep(i, n) add(i, v[i]);
    }
    void add(int a, T w) {
        for (int x = a; x < n; x |= x + 1) bit[x] += w;
    }
    // [0, a)
    T sum(int a) {
        T ret = 0;
        for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
            ret += bit[x];
        }
        return ret;
    }
    // [a, b)
    T sum(int a, int b) {
        return sum(b) - sum(a);
    }
};

// http://kyopro.hateblo.jp/entry/2019/06/30/053725
void solve() {
    int n, k;
    cin >> n >> k;
    
    // ブロックを作る
    vector<int> v2;
    for (int i = 1; i * i <= n; ++i) {
        v2.eb(n / i);
        v2.eb(i);
    }
    sort(all(v2));
    v2.erase(unique(all(v2)), v2.end());
    
    vector<int> v;
    v.eb(1);
    rep3(i, 1, sz(v2)) {
        v.eb(v2[i] - v2[i - 1]);
    }
    // cout << v << endl;
    
    // ブロックの個数
    vector<ll> dp(sz(v));
    rep(j, sz(v)) dp[j] = v[j];
    
    rep3(i, 1, k) {
        BIT<ll> bit(dp);
        dp = vector<ll>(sz(v), 0);
        rep(j, sz(v)) {
            (dp[j] = bit.sum(0, sz(v) - j) % mod * v[j]) %= mod;
        }
    }
    cout << accumulate(all(dp), 0LL) % mod << endl; // debuged, 0LL
    
}



Measured memory_bytes: 2428
def solve():
    _ = input()
    l = list(map(int, input().split()))
    count = 0
    is_sorted = True
    while is_sorted:
        is_sorted = False
        for i in range(len(l) - 1, 0, -1):
            if l[i] < l[i - 1]:
                l[i], l[i-1] = l[i-1], l[i]
                is_sorted = True
                count += 1

    print(' '.join(map(str, l)))
    print(count)


if __name__ == '__main__':
    solve()



Measured memory_bytes: 5600
/*
  Contest 085
  A - Already 2018
  Rakesh Kumar --> 17/09/2020
 */

#include <bits/stdc++.h>

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

    std::string s;
    std::getline(std::cin, s);
    s[3] = '8';
    std::cout << s << std::endl;

    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%s", &t);
  len = strlen(t);
  for(i=0;i<len;i++){
    if(i%2==1){
      if( !( (t[i]=='L') || (t[i]=='U') ||  (t[i]=='D'))){
        printf("No\n");
        return 0;
      }
    }
    else {
      if( !( (t[i]=='R') || (t[i]=='U') ||  (t[i]=='D'))){
        printf("No\n");
        return 0;
      }
    }
  }
         
  printf("Yes\n");     
 

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d\n", cnt);
   

return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(rall(a));

    ll m = n/2;
    if(n%2 == 0) {  // nが偶数のとき
        // p1 < p2 > p3 < … のパターンでも
        // p1 > p2 < p3 < … のパターンでも結果は同じ
        ll ans = 0;
        rep(i, n) {
            if(i < m-1) {
                ans += 2*a[i];
            }
            else if(i == m-1) {
                ans += a[i];
            }
            else if(i == m) {
                ans -= a[i];
            }
            else {
                ans -= 2*a[i];
            }
        }
        out(ans);
    }
    else {  // nが奇数のとき
        // p1 > p2 < p3 < … のパターン
        ll ans1 = 0;
        rep(i, n) {
            if(i < m-1) {
                ans1 += 2*a[i];
            }
            else if(i <= m) {
                ans1 += a[i];
            }
            else {
                ans1 -= 2*a[i];
            }
        }
        // p1 < p2 > p3 < … のパターン
        ll ans2 = 0;
        rep(i, n) {
            if(i < m) {
                ans2 += 2*a[i];
            }
            else if(i <= m+1) {
                ans2 -= a[i];
            }
            else {
                ans2 -= 2*a[i];
            }
        }
        out(max(ans1, ans2));
    }

    re0;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
s = input()
ans, cnt = 0, 1
for i in range(n-1):
    if s[i] != s[i+1]:
        cnt += 1
    if s[i] == s[i+1]:
        ans += 1
if cnt // 2 <= k:
    print(n - 1)
else:
    print(k * 2 + ans)

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<iomanip>

// saw editional

class DP{
public:
    int N;
    std::vector<long double>dp;
    std::vector<bool>flags;
    DP(int N){
        this->N=N;
        dp=std::vector<long double>((N+1)*(N+1)*(N+1),1);
        flags=std::vector<bool>((N+1)*(N+1)*(N+1),0);
    }
    long double f(int c1,int c2,int c3){
        if(flags[c1*(N+1)*(N+1)+c2*(N+1)+c3]){
            return dp[c1*(N+1)*(N+1)+c2*(N+1)+c3];
        }
        long double ans=0;
        long double buf=1-(N-c1-c2-c3)/(double)N;
        if(0!=c1+c2+c3){
            ans+=1/buf;
        }
        if(c1>0){
            ans+=f(c1-1,c2,c3)*c1/(double)N/buf;
        }
        if(c2>0){
            ans+=f(c1+1,c2-1,c3)*c2/(double)N/buf;
        }
        if(c3>0){
            ans+=f(c1,c2+1,c3-1)*c3/(double)N/buf;
        }
        dp[c1*(N+1)*(N+1)+c2*(N+1)+c3]=ans;
        flags[c1*(N+1)*(N+1)+c2*(N+1)+c3]=1;
        return ans;
    }
};
int main(){
    int N;
    std::cin>>N;
    int cnt[3]={0,0,0};
    for(int i=0;i<N;++i){
        int buf;
        std::cin>>buf;
        cnt[buf-1]++;
    }
    DP dp(N);
    std::cout << std::fixed << std::setprecision(12);
    std::cout<<dp.f(cnt[0],cnt[1],cnt[2])<<std::endl;
}

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

int main(void){

int time;
//????????\???
scanf("%d",&time);

//??????????¨????
int hour=floor(time/3600);

//?????????????????????????¨????
int minute=floor( (time - hour * 3600) / 60);

//???????????????????????????????¨????
int second=time-hour*3600-minute*60;

printf("%d:%d:%d\n",hour,minute,second);

return 0;
}

Measured memory_bytes: 592
K, N = map(int, input().split())
A = list(map(int,input().split()))
for i in range(N):
  A.append(A[i]+K)
d = [0]*(N)
max_d, max_i = 0, -1
for i in range(N):
  d[i] = A[i+1] - A[i]
  if d[i] > max_d:
    max_d = d[i]
    max_i = i + 1
ans = 0
for i in range(N-1):
  ans += A[i+max_i+1] - A[i+max_i]
print(ans)

Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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 (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    vector<ll> a(n);
    vector<pair<ll,int>> p(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        p[i]={a[i],i};
    }
    sort(p.begin(),p.end(),greater<pair<ll,int>>());
    ll dp[n+1][n+1]={};
    for(int i=0;i<n;i++){
        ll u=p[i].first,v=p[i].second;
        for(int j=0;j<i+1;j++){
            chmax(dp[j+1][n-(i-j)],dp[j][n-(i-j)]+u*abs(j-v));
            chmax(dp[j][n-(i-j)-1],dp[j][n-(i-j)]+u*abs(n-(i-j)-1-v));
        }
    }
    ll ans=0;
    for(int i=0;i<=n;i++){
        chmax(ans,dp[i][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 34984
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,cnt=0,z=0;
    cin>>x;
    while(x--){
        int n;
        cin>>n;
        if(n%2==0){
                z++;
                if(n%3==0 || n%5==0){
                    cnt++;
                }

        }
    }

    if(z==cnt)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;


}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toLong()

    val set = mutableSetOf<Int>()
    for (i in 0 until N) {
        val r = readLine()!!.toInt()

        if (set.contains(r)) set.remove(r)
        else set.add(r)
    }

    println(set.size)
}

Measured memory_bytes: 47776