akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>

#define for0(i, n)    for (int i = 0  ; i <  (n); ++i)
#define for1n(i, n)   for (int i = 1  ; i <= (n); ++i)
#define for1(i, n)    for (int i = 1  ; i <  (n); ++i)
#define forn(i, n)    for (int i = 0  ; i <= (n); ++i)
#define forx(i, n, x) for (int i = (x); i <  (n); ++i)

#define mod 1000000007LL

using namespace std;

typedef long long ll;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll> ,greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;


int main(void){
    int N;
    ll K;
    cin >> N >> K;
    int a[2000]={};

    for0(i, N){
        cin >> a[i];
    }

    pair<ll, ll> p[2000];

    for0(i, N){
        p[i].first=0;           // all
        p[i].second=0;          // after
    }

    for0(i, N){
        for0(j, N){
            if (a[i] > a[j]) {
                ++p[i].first;
                if (i < j) {
                    ++p[i].second;
                }
            }
        }
        p[i].first%=mod;
        p[i].second%=mod;
    }

    ll result = 0;

    for0(i, N){
        result = (result + (p[i].second *K %mod)) %mod;
        result = ((p[i].first  * ((K-1) *K/2 % mod)) %mod  + result) % mod;
    }

    cout << result;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


N = int(input())
P = list(map(int, input().split()))

Q = list(range(1,N+1))

counter = 0
for i in range(N):
    if P[i] != Q[i]:
        counter += 1

if counter < 3:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18,INF=1<<30;

int dp[MAX][51];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<vector<int>> A(N,vector<int>(N));
    vector<int> aa(N),bb(N);
    for(int i=0;i<N;i++) cin>>aa[i];
    for(int i=0;i<N;i++) cin>>bb[i];
    for(int j=0;j<N;j++){
        int a,b;a=aa[j];b=bb[j];
        if(j%2==0){
            for(int i=0;i<N;i++){
                if(i%2==0) A[i][j]=a;
                else A[i][j]=b;
            }
        }else{
            for(int i=0;i<N;i++){
                if(i%2==0) A[i][j]=b;
                else A[i][j]=a;
            }
        }
    }
    
    for(int i=0;i<(1<<N);i++){
        for(int j=0;j<=50;j++){
            dp[i][j]=INF;
        }
    }
    
    dp[0][0]=0;
    
    for(int bit=0;bit<(1<<N);bit++){
        for(int to=0;to<N;to++){
            if(bit&(1<<to)) continue;
            int turn=0;
            for(int i=0;i<N;i++) if(bit&(1<<i)) turn++;
            if(turn==N) continue;
            
            for(int j=0;j<=50;j++){
                if(dp[bit][j]==INF) continue;
                if(j>A[turn][to]) continue;
                
                int cnt=0;
                
                for(int x=to+1;x<N;x++){
                    if(bit&(1<<x)) cnt++;
                }
                
                dp[bit|(1<<to)][A[turn][to]]=min(dp[bit|(1<<to)][A[turn][to]],dp[bit][j]+cnt);
            }
        }
    }
    
    int ans=INF;
    
    for(int j=0;j<=50;j++){
        ans=min(ans,dp[(1<<N)-1][j]);
    }
    
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
    
    
}



Measured memory_bytes: 52608
#include <iostream>
#include <cstring>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	bool snuke[101];
	memset(snuke, false, sizeof snuke);
	while (k--) {
		int d;
		cin >> d;
		while (d--) {
			int x;
			cin >> x;
			snuke[x] = true;	
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		if (!snuke[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3604
n, k = list(map(int, input().split()))
H = list(map(int, input().split()))

dp = [0] * n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(H[0] - H[i])
    else:
        cands = []
        for j in range(1, k+1):
            if i - j >= 0:
                cost = dp[i - j] + abs(H[i - j] - H[i])
                cands.append(cost)

        dp[i] = min(cands)

print(dp[-1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
using namespace std;
int n , m;
vector<vector<int>>vi(200005);
map<int,int>mp;
int mem[200005];
bool ok[200005];
int dfs(int node){
	if(mem[node])
		return mem[node];
	for(auto it : vi[node]){
		mem[node] = max(dfs(it) + 1 , mem[node]);
	}
	return mem[node];
}
int main() {
	memset(mem,0,sizeof(mem));
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int x , y ; cin>>x>>y;
		vi[x].push_back(y);
		mp[y]++;
	}
	for(int i  = 1 ; i <= n ; i++){
		if(!mp[i]){
			dfs(i);
		}
	}
	int ans = 0;
	for(int i = 1 ; i <=  n; i++)
		ans = max(ans,mem[i]);
	cout<<ans;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
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 MOD = 1e9+7;

vector<int> G[100100];

ll memo[100100][2];
bool isvisit[100100];

ll dfs(int v, bool black, int par){
    //isvisit[v] = true;
    if(memo[v][black] >= 0)
        return memo[v][black];
    
    //if(G[v].size() == 1){
    //    return memo[v][black] = 1;
    //}

    ll ret = 1;
    for(auto&& n : G[v]){
        if(n == par) continue;
        ll tmp = 0;
        //if(isvisit[n]) continue;
        tmp += dfs(n, false, v);
        tmp %= MOD;
        if(!black){
            tmp += dfs(n, true, v);
            tmp %= MOD;
        }

        ret *= tmp;
        ret %= MOD;
    }

    //if(ret == 0)
    //    ret = 1;
    //if(G[v].size() == 1 && G[v][0] == par)
    //    ret = 1;

    return memo[v][black] = ret;
}

int main(){
    int N;
    cin >> N;
    REP(i,N-1){
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    REP(i,N){
        memo[i][0] = -1;
        memo[i][1] = -1;
    }

    ll ans = 0;
    //fill(isvisit, isvisit+N, false);
    ans += dfs(0, false, -1);
    ans %= MOD;

    //fill(isvisit, isvisit+N, false);
    ans += dfs(0, true, -1);
    ans %= MOD;

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


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

int N;
string S;

int main(){
	cin >> N >> S;
	int ans = 0;
	for(int i = 0; i < N-1; i++){
		char now = S[i];
		char nxt = S[i+1];
		if(now != nxt){
			ans++;
			i++;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
int n;
int a[10005];
int main()
{
	scanf("%d",&n);
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		while(a[i]%2==0)
		{
			a[i]/=2;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define LL long long
#define LD long double

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	LL n;
	cin >> n;
	vector<LD> a(n);
	LD res = 0;
	for (LL i = 0; i < n; i++){
		cin >> a[i];
		res += 1/a[i];
	}
	cout << fixed << setprecision(12) << 1/res << "\n";
}


Measured memory_bytes: 256
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

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

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n;
	int ans = 0;
	if( n >= 500 )
	{
		int yy = n/500;
		n -= yy*500;
		ans += 2*500*yy;

		yy = n/5;
		ans += 5*yy;
		cout << ans << endl;
	}
	else cout << 5*(n/5) << endl;
}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}

 

Measured memory_bytes: 5504
import Prelude

main :: IO ()
main = do
  [_, w] <- readInts
  ss <- lines <$> getContents
  let sharps = replicate (w + 2) '#'
  putStrLn sharps
  mapM_ putStrLn $ map (\s -> '#' : s ++ "#") ss
  putStrLn sharps

readInts :: IO [Int]
readInts = map read . words <$> getLine


Measured memory_bytes: 1020
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b):return (a + b - 1) // b


def solve(N, Y):
    for a in range(N + 1):
        for b in range(N + 1):
            r = Y - (10000 * a + 5000 * b)
            if r >= 0 and r % 1000 == 0:
                c = r // 1000
                if a + b + c == N:
                    return a, b, c
    return -1, -1, -1


def main():
    N, Y = map(int, input().split())
    print(*solve(N, Y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 43244
#include<iostream>
#define l int64_t
#define c continue
#define o(a) cout<<a<<endl
using namespace std;
int main(){l m=1e9+7,x,y,z,w,o,p,q,v[93],t[91][91][2],a,b;v[0]=1,v[1]=1;for(l i=2;i<93;i++)v[i]=v[i-1]+v[i-2];for(l i=2;i<91;i++){for(l j=1;j<i;j++){a=v[i],b=v[i+1];if(j<2){t[i][0][0]=a,t[i][0][1]=b,t[i][j][0]=b,t[i][j][1]=2*b-a;c;}t[i][j][0]=t[i-1][j-1][1],t[i][j][1]=t[i-1][j-1][1]+t[i-1][j-1][0];}}cin>>q;while(q--){cin>>x>>y;if(x>y)swap(x,y);if(y<2){o("1 1");c;}for(l i=0;i<93;i++){if(v[i]>x||v[i+1]>y){z=i-1;break;}}o(z);if(z<2){o(x*y%m);c;}w=0;for(l j=0;j<z;j++){o=t[z][j][0],p=t[z][j][1];if(o>x||p>y)c;w+=(y-p)/o+1;if(x>=p)w+=(x-p)/o+1;}o(w%m);}}

Measured memory_bytes: 4452
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 105
#define N 100005
#define MX (1LL<<60)
using namespace std;
int n,m,w[M],v[M];
long long dp[N];
int main()
{
    scanf("%d %d",&n,&m);
    REP(i,1,n) scanf("%d %d", &w[i], &v[i]);
    
    fill(dp, dp+N, MX);
    dp[0] = 0;
    REP(i,1,n) for (int j=N-1; j>=v[i]; j--) {
        if (dp[j-v[i]] != MX) {
            dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
        }
    }

    int ans = 0;
    REP(i,0,N-1) if (dp[i]<=m) ans = i;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4524
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

ll sign(ll A) {
  return (A > 0) - (A < 0);
}

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans_1 = 0;
  ll sum = 0;
  int sig = 1;
  rep(i, N) {
    sum += a[i];
    if (sig * sum <= 0) {
      ll diff = sig - sum;
      sum += diff;
      ans_1 += abs(diff);
    }
    sig *= -1;
  }

  ll ans_2 = 0;
  sum = 0;
  sig = -1;
  rep(i, N) {
    sum += a[i];
    if (sig * sum <= 0) {
      ll diff = sig - sum;
      sum += diff;
      ans_2 += abs(diff);
    }
    sig *= -1;
  }

  cout << min(ans_1, ans_2) << endl;
}

Measured memory_bytes: 1024
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pob pop_back
#define ft first
#define ftt ft.ft
#define ftc ft.sc
#define sc second
#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define ctz __builtin_ctz
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 1e3;
 




int main(){FAST;
    int a ,b ,c ,d, res;
    cin >> a >> b >> c >> d;
    res = min(a ,b) + min(c ,d);



    out(res);
   return 0;
}
 












Measured memory_bytes: 256
from time import time
from random import randint

from numba import njit
from numpy import int64

@njit('i8(i8[:],i8[:])')
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(i-last[j])
        score=score+s[i*26+v]-c
    return score

def main():
    start=time()
    d,*s=map(int,open(0).read().split())
    s=int64(s)
    x=int64(([*range(26)]*15)[:d])
    M=func(s,x)
    while time()-start<1.3:
        y=x.copy()
        if randint(0,1):
            y[randint(0,d-1)]=randint(0,25)
        else:
            i=randint(0,d-15)
            j=randint(i+1,i+7)
            k=randint(j+1,j+7)
            if randint(0,1):
                y[i],y[j],y[k]=y[j],y[k],y[i]
            else:
                y[i],y[j],y[k]=y[k],y[i],y[j]
        t=func(s,y)
        if t>M:
            M=t
            x=y
    print(*x+1,sep='\n')

main()

Measured memory_bytes: 112048
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
int pa[200005][64];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    for (int i = 1 ; i <= n ; i++) {
        cin >> pa[i][0];
    }
    for (int i = 1 ; i <= 64 ; i++) {
        for (int j = 1 ; j <= n ; j++) {
            pa[j][i] = pa[pa[j][i-1]][i-1];
        }
    }
    int cur;
    cur = 1;
    int z = 0;
    while (k) {
        if (k & 1) {
            cur = pa[cur][z];
        }
        z++;
        k>>=1;
    }
    cout << cur << '\n';

}


Measured memory_bytes: 53656
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int N,M,C,i,j,a,ans=0;
  scanf("%d%d%d",&N,&M,&C);
	int A[N][M],B[M];
	FOR(i,0,M)scanf("%d",&B[i]);
	FOR(i,0,N)FOR(j,0,M)scanf("%d",&A[i][j]);
	FOR(i,0,N){
		a=C;
		FOR(j,0,M)a+=A[i][j]*B[j];
		if(a>0)ans++;
	}

  printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var dp = new int[N + 1, 3];
		var acts = new int[N][];
		for (var i = 0; i < N; i++) acts[i] = G;
		for (var i = N - 1; i >= 0; i--)
			for (var j = 0; j < 3; j++)
				for (var k = 0; k < 3; k++)
					if (j != k) dp[i, j] = Max(dp[i, j], acts[i][j] + dp[i + 1, k]);
		var ans = 0;
		for (var i = 0; i < 3; i++) ans = Max(ans, dp[0, i]);
		WriteLine(ans);
	}
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {

    int N; cin >> N;
    vector<int> a(N), w(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> w[i];

    vector<int> v(N, 0);
    iota(v.begin(), v.end(), 0);
    int ans = 1e8;
    do {

        int tmp = 0;
        rep(i, N) {
            // 右効き

            if (a[v[i]] == 0) {
                if (i+1 == N) {
                    if (a[v[0]] == 1) tmp += w[v[i]];
                }
                else {
                    if (a[v[i+1]] == 1) tmp += w[v[i]];
                }
            }
            else {
                if (i == 0) {
                    if (a[v[N-1]] == 0) tmp += w[v[i]];
                }
                else {
                    if (a[v[i-1]] == 0) tmp += w[v[i]];
                }
            }
        }

        ans = min(ans, tmp);

    } while (next_permutation(v.begin(), v.end()));

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



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

int main()
{
	int n;
	cin >> n;
	string ans;
	switch(n % 10)
	{
		case 1:
			ans = "pon";
			break;
		case 2:
			ans = "hon";
			break;
		case 3:
			ans = "bon";
			break;
		case 4:
			ans = "hon";
			break;
		case 5:
			ans = "hon";
			break;
		case 6:
			ans = "pon";
			break;
		case 7:
			ans = "hon";
			break;
		case 8:
			ans = "pon";
			break;
		case 9:
			ans = "hon";
			break;
		case 0:
			ans = "pon";
			break;
	}
	cout << ans << endl;
	return 0;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
const int MAX = 3;
const int MOD = SC ( int, 1e9 + 7 );



const int MAT1[MAX][MAX] =
{
	1, 2, 1,
	0, 1, 1,
	1, 2, 2
};

const int MAT2[MAX][MAX] =
{
	1, 2, 1,
	0, 1, 1,
	0, 0, 1
};



int Add ( int x, int y )
{
	x += y;
	if ( x >= MOD ) x -= MOD;
	return x;
}

void Addv ( int &x, int y )
{
	x += y;
	if ( x >= MOD ) x -= MOD;
}

int Dec ( int x, int y )
{
	x -= y;
	if ( x < 0 ) x += MOD;
	return x;
}

void Decv ( int &x, int y )
{
	x -= y;
	if ( x < 0 ) x += MOD;
}



struct mT
{
	mT ()
	{
		Clear ();
	}
	
	void Clear ()
	{
		INIT ( a, 0 );
	}
	
	void Setunit ()
	{
		Clear ();
		lp ( i, 0, MAX ) a[i][i] = 1;
	}
	
	mT operator * ( const mT &x ) const
	{
		mT Ans;
		lp ( i, 0, MAX ) lp ( j, 0, MAX ) lp ( k, 0, MAX ) Addv ( Ans.a[i][j], SC ( LL, a[i][k] ) * x.a[k][j] % MOD );
		return Ans;
	}
	
	void operator *= ( const mT &x )
	{
		( *this ) = ( *this ) * x;
	}
	
	int a[MAX][MAX];
};



int N, M;
int A[MAXN];



void init ();
void input ();
void work ();

mT Qpow ( mT &a, int b )
{
	mT Base = a, Ans;
	Ans.Setunit ();
	while ( b ){
		if ( b & 1 ) Ans *= Base;
		Base *= Base;
		b >>= 1;
	}
	return Ans;
}



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d%d", &M, &N );
	lpi ( i, 1, N ) scanf ( "%d", &A[i] );
}

void work ()
{
	// main work
	
	mT Bs1, Bs2;
	lp ( i, 0, MAX ) lp ( j, 0, MAX ) Bs1.a[i][j] = MAT1[i][j], Bs2.a[i][j] = MAT2[i][j];
	
	mT Ret;
	Ret.Setunit ();
	int Pre = 0;
	lpi ( i, 1, N ){
		Ret = Qpow ( Bs1, A[i] - Pre - 1 ) * Ret;
		Ret = Bs2 * Ret;
		Pre = A[i];
	}
	Ret = Qpow ( Bs1, M - Pre ) * Ret;
	
	cout << Ret.a[0][2] << endl;
}

Measured memory_bytes: 640
/*input
1000 1 1000
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int long long
int n,x,t;
signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	int ans=0;
	cin>>s;
	for(char i:s){
		ans += i-'0';
		ans %= 9;
	}
	if(ans==0){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;	
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string k;
    int d;
    const i64 mod = 1000000007;
    std::cin >> k >> d;

    std::vector<std::vector<i64>> dp(d, std::vector<i64>(2));
    for (int i = 0; i < k[0] - '0'; i++) dp[i % d][0]++;
    dp[(k[0] - '0') % d][1] = 1;
    for (unsigned i = 1; i < k.size(); i++) {
        int t = k[i] - '0';
        decltype(dp) cp(d, std::vector<i64>(2));
        for (int j = 0; j < d; j++) {
            for (int p = 0; p < 10; p++) cp[(j + p) % d][0] = (cp[(j + p) % d][0] + dp[j][0]) % mod;
            for (int p = 0; p < t; p++) cp[(j + p) % d][0] = (cp[(j + p) % d][0] + dp[j][1]) % mod;
            cp[(j + t) % d][1] = dp[j][1];
        }
        std::swap(cp, dp);
    }

    std::cout << (dp[0][0] + dp[0][1] + mod - 1) % mod << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
string s;

ll dp[11];
ll solve(int k){
  if(k >= (int)s.size()) return 0;
  if(dp[k]) return dp[k];

  ll ret = 0;
  ll d = 0;
  for(int i = k; i < (int)s.size(); i++){
    d *= 10;
    d += s[i]-'0';
    ret += (1<<max((int)s.size()-i-2,0))*d + solve(i+1);
  }
  return dp[k] = ret;
}

int main(void){
  cin >> s;
  cout << solve(0) << endl;
}


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

int main() {
	// your code goes here
	char s[105];
	cin>>s;
	int l=0;
	int h=strlen(s)-1;
	int c=0;
	while(h>l)
	{
	    if(s[l++]!=s[h--])
	    {
	        c++;
	    }
	}
	cout<<c<<endl;
	return 0;
}

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

//関数

//main関数
int main() {
    
    
    
    //入力
    long X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    
    vector<long> A(X),B(Y),C(Z);
    for(int i=0;i<X;i++){
        cin>>A.at(i);
    }
    for(int i=0;i<Y;i++){
        cin>>B.at(i);
    }
    for(int i=0;i<Z;i++){
        cin>>C.at(i);
    }
    
    
    //計算
    long k=3000;
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    sort(B.begin(),B.end());
    reverse(B.begin(),B.end());
    sort(C.begin(),C.end());
    reverse(C.begin(),C.end());
    
    vector<long> cand(0);
    for(int a=0;a<X;a++){
        for(int b=0;b<Y;b++){
            long maxc=min(k/((a+1)*(b+1))+2,Z);
            for(int c=0;c<maxc;c++){
                cand.push_back(A.at(a)+B.at(b)+C.at(c));
            }
        }
    }
    sort(cand.begin(),cand.end());
    reverse(cand.begin(),cand.end());
    
    //出力
    for(int i=0;i<K;i++){
        cout<<cand.at(i)<<endl;
    }
}



Measured memory_bytes: 35176
#include"bits/stdc++.h"
#include"math.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
  int n;cin >>n;
  vector<ll> a(n);rep(i,n)cin >> a[i];
  sort(a.begin(),a.end());
  int ans=0;
  rep(i,a.size()){
    ans++;
    if(a[i]==a[i+1]){
      ans--;i++;}}
  cout << ans << endl;}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){

  int G[101][101],n;
  int flg[101]={};
  int t[101],i,j,count;
  int min1,min2,mini,sum;

  for(i=1;i<=100;i++)
    t[i]=1000000;

  t[1]=0;
  scanf("%d",&n);
 
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      scanf("%d",&G[i][j]);

  min2=1;
  sum=0;
  flg[1]=1;

  while(1){
    
    count=0;
    for(i=1;i<=n;i++)
      if(flg[i]==1)count++;
    if(count==n)break;
    
    min1=10000000;
    
    for(i=1;i<=n;i++){
      if(flg[i]!=1 && G[min2][i]!=-1 && t[i]>G[min2][i])
	t[i] = G[min2][i];
      if(flg[i]!=1 && min1>t[i]){
	mini=i;
	min1=t[i];
      }
    }
  sum += min1;
  flg[mini]=1;
  t[mini] = min1;
  min2 = mini;
  }
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 636
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
q=int(input())
dp=[0]*(10**5+1)
for i in a:
  dp[i]+=1

for j in range(q):
  b,c=map(int,input().split())
  ans+=(c-b)*dp[b]
  dp[c]+=dp[b]
  dp[b]=0
  print(ans)

Measured memory_bytes: 83252
use std::cmp::{max, min};
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, t: usize);
    const M: usize = 61;
    let msb = |x: &usize| {
        let mut ret = M;
        while ret > 0 && *x >> ret == 0 {
            ret -= 1
        }
        ret
    };
    'outer: for _ in 0..t {
        parse!(it, n: usize, a: [usize; n]);
        let s: Vec<bool> = it.next().unwrap().bytes().map(|x| x == b'1').collect();
        let mut bases = vec![];
        for i in (0..n).rev() {
            let mut res = a[i];
            let mut j = !0;
            while res > 0 {
                let m = msb(&res);
                match bases.binary_search_by_key(&m, msb) {
                    Ok(i) => res ^= bases[i],
                    Err(i) => {
                        j = i;
                        break;
                    }
                }
            }
            if res != 0 {
                if s[i] {
                    println!("{}", 1);
                    continue 'outer;
                } else {
                    bases.insert(j, res);
                }
            }
        }
        println!("{}", 0);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2416
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<unordered_map>
#include<string.h>
#include<math.h>
using namespace std;
using ll = long long;
int main(){
    int X;
    cin >> X;
    if(X < 100){cout << 0;return 0;}
    int a = X % 100;
    if(a % 5 == 0 && a / 5<= X / 100)cout << 1;
    else if(a / 5 + 1 <= X/100)cout << 1;
    else cout << 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   int a;
   cin >> a;
   cout << a/3 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, s;

	scanf("%d%d", &a, &b);

	s = a - (b * 2);

	if (s > 0) //カーテンが窓すべてを覆わない場合
	{
		printf("%d\n", s);
	}
	else //カーテンが窓すべてを覆う場合
	{
		printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 128
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

ll N,ans=inf;
vector<tdata> fv,v;
void solve(int f,int s){
  ll i,back=-inf,bf=inf;
  rep(i,N){
    ll x=v[i].first,y=v[i].second.first,d=v[i].second.second;
    if(d!=f&&d!=s)continue;
    if(back!=x){
      bf=inf;
      back=x;
    }
    if(d==f){
      bf=y;
    }else{
      if(bf!=inf)chmin(ans,(y-bf)*5);
    }
  }
}
int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,a,b;
  cin>>N;
  string s;
  rep(i,N){
    cin>>a>>b>>s;
    fv.eb(a,datas(b,(s[0]=='U')+(s[0]=='D')*2+(s[0]=='L')*3+(s[0]=='R')*4));
  }
  vsort(fv);
  v=fv;

  //eq x
  solve(1,2);
  //eq y
  rep(i,N){
    swap(v[i].first,v[i].second.first);
  }
  vsort(v);
  solve(4,3);

  //eq x+y collision R&U
  v=fv;
  rep(i,N){
    v[i].first+=fv[i].second.first;
    v[i].second.first*=2;
  }
  vsort(v);
  solve(1,4);
  //eq x+y collision D&L
  solve(3,2);
  //eq x-y collision L&U
  v=fv;
  rep(i,N){
    v[i].first-=fv[i].second.first;
    v[i].second.first*=2;
  }
  vsort(v);
  solve(1,3);

  //eq x-y collision R&D
  solve(4,2);

  if(ans!=inf)print(ans);
  else print("SAFE");
}

Measured memory_bytes: 12692
//Problem *
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=405;
int n;ll dp[N][N],a[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
	for(int i=2;i<=n;i++)for(int l=1;l<=n-i+1;l++){
		int r=l+i-1;dp[l][r]=1000000000000000000ll;//printf("x %lld\n",dp[l][r]);
		for(int m=l;m<r;m++)dp[l][r]=min(dp[l][r],dp[l][m]+dp[m+1][r]);//printf("t [%d,%d] [%d,%d]\n",i,m,m+1,r);
		dp[l][r]+=a[r]-a[l-1];
	}
	//for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)printf("(%lld,%lld) ",dp[i][j],a[j]-a[i-1]);printf("\n");}
	printf("%lld",dp[1][n]);
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
ll mod;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin>>a[i];
	}
	Sort(a);
	Reverse(a);
	cout << a[0] << " ";
	double dis = numeric_limits<int>::max();
	int now = 0;
	for (int i = 1; i < a.size(); i++) {
		if (abs(a[0] / 2.00 - a[i]) < dis) {
			dis = abs(a[0] / 2.00 - a[i]);
			now = a[i];
		}
	}
	cout << now << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  int i = 1, j = 1;
  int ans = 0;

  for (; i <= a; ++i, ++j) {
    if (i < a) {
      ans++;
    } else if (i == a) {
      if (j <= b) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int n;
string p[9];
bool use[9];
int dir[9],id[9];

int rec(int d){
  if(d==9)return 1;

  int res = 0;
  for(int i=0;i<9;i++){
    if(use[i])continue;
    use[i] = true;

    for(int j=0;j<4;j++){
      if(d>2){
	if(abs( p[id[d-3]][(2+dir[d-3])%4] - p[i][j] ) != 32)continue;
      }
      if(d%3!=0){
	if(abs( p[id[d-1]][(1+dir[d-1])%4] - p[i][(j+3)%4] ) != 32)continue;
      }
      id[d] = i; dir[d] = j;
      res += rec(d+1);
    }
    use[i] = false;
  }
  return res;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<9;j++){
      cin >> p[j];
      use[j] = false;
    }

    cout << rec(0) << endl;
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int x; cin >> x;
    vector<bool> a(100001, false);
    a[0] = true;
    rep(i, 6){
        int t = 100 + i;
        rep(j, 100002){
            if(j+t > 100000) break;
            if(a[j]) a[j+t] = true;
        }
    }

    pr(a[x]);
    return 0;}

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

using namespace std;

#define ll long long

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

    int n;
    cin >> n;

    int m = INT32_MAX;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        if (x < m) {
            ans++;
            m = x;
        }
    }

    cout << ans;


    return 0;
}

Measured memory_bytes: 256
/*
Author : N_o_o_B
Created : April 11 2020 10:59:31 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    ll k,n;
    cin >> k >> n;
    vl a(n);
    fori(i,n) cin >> a[i];
    ll ans = k;
    fori(i,n){
        ll cur = k - (a[i] - a[(i-1+n)%n] + k)%k;
        ans = min(ans,cur);
    }

    cout << ans << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 1792
// 6/28 バーチャル参加
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    vector<ll> S(N+1), T(M+1);
    S[0] = 0; T[0] = 0;
    rep(i, N) S[i+1] = S[i] + A[i];
    rep(i, M) T[i+1] = T[i] + B[i];

    ll res = 0;
    for(ll i = 0; i <= N; i++) {
        ll tb = K - S[i];
        if (tb < 0) break;
        auto it = upper_bound(T.begin(), T.end(), tb);
        ll now = i + (it - T.begin()) - 1;  // T[0]のぶん、1を引く。
        // printf("i, now, tb = %d, %d, %d\n", i, now, tb);
        res = max(res, now);
    }

    // ll res = 0;
    // ll time = 0;
    // int a = 0, b = 0;
    // while (true) {
    //     if (a == N && b == M) {
    //         break;
    //     }
    //     else if (a == N) {
    //         time += B[b];
    //         b++;
    //         // res++;
    //     }
    //     else if (b == M) {
    //         time += A[a];
    //         a++;
    //         // res++;
    //     } else {
    //         if (A[a] <= B[b]) {
    //             time += A[a];
    //             a++;
    //             // res++;
    //         } else {
    //             time += B[b];
    //             b++;
    //             // res++;
    //         }
    //     }

    //     if (time <= K) {
    //         res++;
    //     } else {
    //         break;
    //     }
    // }

    cout << res << endl;
}

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

using namespace std;

class matching {
  public:
  vector< vector<int> > g;
  vector<int> pa;
  vector<int> pb;
  vector<int> was;
  int n, m;
  int res;
  int iter;

  matching(int _n, int _m) : n(_n), m(_m) {
    assert(0 <= n && 0 <= m);
    pa = vector<int>(n, -1);
    pb = vector<int>(m, -1);
    was = vector<int>(n, 0);
    g.resize(n);
    res = 0;
    iter = 0;
  }

  void add(int from, int to) {
    assert(0 <= from && from < n && 0 <= to && to < m);
    g[from].push_back(to);
  }

  bool dfs(int v) {
    was[v] = iter;
    for (int u : g[v]) {
      if (pb[u] == -1) {
        pa[v] = u;
        pb[u] = v;
        return true;
      }
    }
    for (int u : g[v]) {
      if (was[pb[u]] != iter && dfs(pb[u])) {
        pa[v] = u;
        pb[u] = v;
        return true;
      }
    }
    return false;
  }

  int solve() {
    while (true) {
      iter++;
      int add = 0;
      for (int i = 0; i < n; i++) {
        if (pa[i] == -1 && dfs(i)) {
          add++;
        }
      }
      if (add == 0) {
        break;
      }
      res += add;
    }
    return res;
  }
};

int main() {
  int n;
  cin >> n;
  matching ma(n, n);
  vector< pair<int,int> > red, blue;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    red.emplace_back(x, y);
  }
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    blue.emplace_back(x, y);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int a, b, c, d;
      tie(a, b) = red[i];
      tie(c, d) = blue[j];
      if (a < c && b < d) {
        ma.add(i, j);
      }
    }
  }
  cout << ma.solve() << '\n';
  return 0;
}


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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a;
string s;
cin>>a;
cin>>s;
if(a>=3200){
    cout<<s<<endl;
}
else{
    cout<<"red"<<endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int n;
	cin >> n;
	VI s(n);
	REP(i, n)
		cin >> s[i];
	sort(ALL(s));
	double ans = s[0];
	for (int i = 1; i < n; i++)
		ans = (ans + s[i]) / 2;
	cout << setprecision(9) << ans;
}

Measured memory_bytes: 256
n,a,b,c,d = ( int(i) for i in input().split())
s = input()

a_to_c = s[(a-1)+1:(c-1)-1 +1]

possibility = True

if c>d:
    b_to_d = s[(b-1)-1:(d-1)+1 +1]
    if "##" in a_to_c or "..." not in b_to_d:
        possibility = False
else:
    b_to_d = s[(b-1)+1:(d-1)-1 +1]
    if "##" in a_to_c or "##" in b_to_d:
        possibility = False

if possibility:
    print("Yes")
else:
    print("No")

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> h(N);
    rep (i, 0, N) cin >> h[i];

    vector<int> dp(N+10, INF);
    dp[0] = 0;
    for (int now = 0; now < N; now++) 
    {
        for (int next = now+1; next <= min(N, now+2); next++) 
        {
            dp[next] = min(dp[next], abs(h[now]-h[next])+dp[now]);
        }
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using Int =long long;


int main() {

	Int N;
	std::cin >> N;

	std::vector<Int> A(N + 1);
	std::vector<Int> B(N);

	for (Int i = 0; i < N + 1; i++)std::cin >> A[i];
	for (Int i = 0; i < N; i++)std::cin >> B[i];

	Int ans = 0;

	for (Int i = 0; i < N; i++) {

		if (B[i] >= A[i]) {
			ans += A[i];
			B[i] -= A[i];

			if (B[i] >= A[i + 1]) {

				ans += A[i + 1];
				A[i + 1] = 0;
			}
			else {
				ans += B[i];
				A[i + 1] -= B[i];
			}

		}
		else {
			ans += B[i];
					}

	}

	std::cout << ans << std::endl;

}

Measured memory_bytes: 1792