akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    int div,a,b,count;
    while(cin>>div>>a>>b)
    {
        count=0;
        for(int i=a;i<=b;i++)
        {
            if(i%div==0)
            {
                count++;
            }
        }
        if(count!=0)
        {
            cout<<"OK"<<endl;
        }
        else
        {
            cout<<"NG"<<endl;
        }
        break;
    }
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}
int main()
{
   
  IOS
  ll n;
  cin>>n;
  vl v;
  v.pb(0);
  ll a[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]==v.back()+1)
      v.pb(a[i]);
  }
  if(v.size()==1)
  {
    cout<<-1<<endl;
  }
  else
  {
    cout<<n-v.size()+1<<endl;
  }
  
  


  

}
  


Measured memory_bytes: 3568
N = int(input())
P = sorted([(int(input()), i) for i in range(N)])

cnt = 1
M = 1
for i in range(1, N):
    if P[i-1][1] < P[i][1]:
        cnt += 1
        M = max(M, cnt)
    else:
        M = max(M, cnt)
        cnt = 1

print(N-M)

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

#define int long long
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define sq(x) (x)*(x)
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define t4i tuple<int,int,int,int>
#define mii map<int,int>

const int INF = 1LL<<60;
const int MOD = 998244353;

template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
string to_string(string s) {return s;}
string to_string(bool b) {return b?"true":"false";}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";}
template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}
string bin_string(int x) {
    const int d = 32;
    string result(d, ' ');
    REP(i, 0, d) result[d-1-i] = '0'+(x>>i & 1LL);
    return result;
}

int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

vector<vi> nodes;
vb seen;
void dfs(int u, int p=-1) {
    if (seen[u]) return;
    seen[u] = true;
    for (int v : nodes[u]) if (v!=p) {
        dfs(v, u);
    }
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    string s,t;
    cin >> s >> t;
    cout << t+s;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	A := make([]int, n)
	B := make([]int, n)
	C := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(read, &A[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(read, &B[i])
	}
	for i := 0; i < n-1; i++ {
		fmt.Fscan(read, &C[i])
	}

	pre := -2
	sum := 0
	for i := 0; i < n; i++ {
		sum += B[A[i]-1]
		if pre+1 == A[i]-1 {
			sum += C[pre]
		}
		pre = A[i] - 1
	}
	fmt.Println(sum)

}


Measured memory_bytes: 640
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long x=sc.nextLong();
        System.out.println(b/x-a/x+(a%x==0?1:0));
    }
    
 
}

Measured memory_bytes: 22608
#include <iostream>

using namespace std;

int main(){

    string S,T,U;
    int A,B;
    cin>>S>>T;
    cin>>A>>B;
    cin>>U;
    if(S!=T){
        if(S==U){
            if((1<=A<=10)&&(1<=B<=10)){
                A--;
                cout<<A<<" "<<B<<endl;
            }else
                return 0;
        }else if(T==U){
            if((1<=A<=10)&&(1<=B<=10)){
                B--;
                cout<<A<<" "<<B<<endl;
            }else
                return 0;
        }
    }else
        return 0;
    
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
 
if N == 1:
    print(0)
    quit()

start = 0
moves = []
for i in range(N-1):
    if H[i] < H[i+1]:
        moves.append(i - start)
        start = i + 1
if H[N-2] >= H[N-1]:
    moves.append(i - start + 1)
print(max(moves))

Measured memory_bytes: 14252
def grid(N):
    n = 0
    while n * (n + 1) < N * 2:
        n += 1

    if n * (n + 1) != N * 2:
        print("No")
        return

    S = [[0]*n for _ in range(n+1)]
    cnt = 1
    for i in range(n+1):
        for j in range(n):
            if i <= j:
                S[i][j] = cnt
                cnt += 1
            else:
                S[i][j] = S[j][i-1]
    print("Yes")
    print(len(S))
    for s in S:
        print(n, end=" ")
        print(*s, sep=" ")


if __name__ == "__main__":
    N = int(input())
    grid(N)


Measured memory_bytes: 9296
using System;

namespace ABC161a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);

            int t = a;
            a = b;
            b = t;

            t = a;
            a = c;
            c = t;

            Console.WriteLine($"{a} {b} {c}");
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
     
    int main(void)
    {
        int N, L, sum = 0;
        scanf("%d %d", &N, &L);
        if (L >= 0)
        {
            for (int i = 2; i <= N; ++i)
            {
                sum += L + i - 1;
            }
        }
        else
        {
            if (N > -L)
            {
                for (int i = 1; i <= N; ++i)
                {
                    sum += L + i - 1;
                }
            }
            else
            {
                for (int i = 1; i < N; ++i)
                {
                    sum += L + i - 1;
                }
            }
        }
        printf("%d", sum);
        return 0;
    }

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
#１行に数値一つならparseInt(readline())
#１行に数値複数ならparseMap(split(readline()))を行数分。
# 例：n,k = readline() |> split |> parseMap
#      a = readline() |> split |> parseMap
function main()
  b = parseMap(split(readline()))
  for i in 1:5
  	if b[i] != i
    	println(i)
	end
   end
end

main()

Measured memory_bytes: 163728
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n,q;
  cin>>n>>q;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
 
  vector<long> acc(n+1,0);
  rep(i,n) acc[i+1] = acc[i] + a[i];
  vector<long> step(n+2,0);
  for(int i=(n+1)%2; i<n; i+=2){
    step[i] += a[i];
    step[i+2] += step[i];
  }

  vector<long> keys;
  vector<long> values;
  rep(i,1,(n+1)/2 + 1){
    keys.pb((a[n-i-1]+a[n-i*2-1])/2);
    long v = acc[n] - acc[n-i];
    if(n-2*i-1 >= 0) v += step[n-2*i-1];
    values.pb(v);
  }
  reverse(all(keys));
  reverse(all(values));
dbg(keys, values);
  rep(_,q){
    long x;
    cin>>x;
    int idx = lower_bound(all(keys), x) - begin(keys);
    dbg(idx);
    cout << values[max(0,idx-1)] << "\n";
  }

  return 0;
}


Measured memory_bytes: 4724
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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 A,B,now=1,ans;


int main(){
    cin>>A>>B;
    while(now<B){
        now+=(A-1);
        ans++;
    }
    out(ans);

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}

int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = (r - l) / d;
    if (r % d == 0 or l % d == 0)
    {
        cout << ans + 1;
    }
    else
    {
        cout << ans;
    }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 100000001
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
ll max1(ll a, ll b, ll c=-inf, ll d=-inf) {ll mx1=(a>b)?a:b, mx2=(c>d)?c:d; return ((mx1>mx2)?mx1:mx2);}
#define int ll


signed main() {
	fast;
	
	ll n;
	cin>>n;
	ll ga,gb,sa,sb,ba,bb;
	cin>>ga>>sa>>ba;
	cin>>gb>>sb>>bb;

	ll g=0, s=0, b=0;
	

	ll ans=n;
	ll n1,n2;

	if(ga>=gb) n1=0;
	else n1=n;

	if(sa>=sb) n2=0;
	else n2=n;

	if(n1!=0&&n2!=0){
		swap(ga,ba);
		swap(gb,bb);
		if(ga>=gb) n1=0;
		else n1=n;
		if(sa>=sb) n2=0;
		else n2=n;
	}

	ll gcd1 = min(ga,gb);
	ll gcd2 = min(sa,sb);

	for(int i=0;i<=n1;i+=gcd1){
		for(int j=0;i+j<=n&&j<=n2;j+=gcd2){
			ll cur=0;
			ll g=0, s=0, b=0;
			ll g1=i;
			ll s1=j;
			ll b1=n-i-j;

			g+=(g1/min(ga,gb)); cur+=g1%min(ga,gb);
			s+=(s1/min(sa,sb)); cur+=s1%min(sa,sb);
			b+=(b1/min(ba,bb)); cur+=b1%min(ba,bb);

			cur+=g*gb+s*sb+b*bb;
			g=0; b=0; s=0;

			ans=max(ans,cur);
		}
	}

	n=ans;
	swap(ga,gb);
	swap(sa,sb);
	swap(ba,bb);

	if(ga>=gb) n1=0;
	else n1=n;

	if(sa>=sb) n2=0;
	else n2=n;

	if(n1!=0&&n2!=0){
		swap(ga,ba);
		swap(gb,bb);
		if(ga>=gb) n1=0;
		else n1=n;
		if(sa>=sb) n2=0;
		else n2=n;
	}

	gcd1 = min(ga,gb);
	gcd2 = min(sa,sb);

	for(int i=0;i<=n1;i+=gcd1){
		for(int j=0;i+j<=n&&j<=n2;j+=gcd2){
			ll cur=0;
			ll g=0, s=0, b=0;
			ll g1=i;
			ll s1=j;
			ll b1=n-i-j;

			g+=(g1/min(ga,gb)); cur+=g1%min(ga,gb);
			s+=(s1/min(sa,sb)); cur+=s1%min(sa,sb);
			b+=(b1/min(ba,bb)); cur+=b1%min(ba,bb);

			cur+=g*gb+s*sb+b*bb;
			g=0; b=0; s=0;

			ans=max(ans,cur);
		}
	}


	cout<<ans;

} 

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	vector <int> ans(n,0);
	int x=0;
	for(int i=0;i<n;i++)
	{
		if(i&1)
			x-=arr[i];
		else
			x+=arr[i];
	}
	ans[1]=arr[0];
	ans[0]=x;
	for(int i=2;i<n;i++)
	{
		if(i&1)
			ans[i]=ans[i-1]+arr[i-1];
		else
			ans[i]=ans[i-1]-arr[i-1];
	}
	// for(int i=0;i<n;i++)
	// 	cout << ans[i] << " ";
	// cout << "\n";
 	vector <int> fans(n);
	fans[0]=x;
	for(int i=1;i<n;i++)
	{
		if(i&1)
			fans[i]=2*ans[i]-x;
		else
			fans[i]=ans[0]-2*ans[i];
	}
	for(int i=0;i<n;i++)
	{
		cout << fans[i] <<" ";
	}
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int A[N], B[N], C[N];
  for (int i=0; i<N; i++) cin>>A[i];
  for (int i=0; i<N; i++) cin>>B[i];
  for (int i=0; i<N-1; i++) cin>>C[i];
  int sum=0;
  for (int i=0; i<N; i++) sum+=B[i];
  int tum=0;
  for (int i=0; i<N-1; i++){
    if (A[i]+1==A[i+1]) tum+=C[A[i]-1];
  }
  cout<<sum+tum<<endl;
}
  

Measured memory_bytes: 256
from itertools import combinations

h,w,k=map(int,input().split())
G=[]
for _ in range(h):
  s=input()
  S=[]
  for i in range(w):
    S.append(s[i])
  G.append(S)
ans=0

HH=[]
for i in range(1<<h):
  H=[]
  for j in range(h):
    if (i>>j)&1:
      H.append(j)
  HH.append(H)

WW=[]
for i in range(1<<w):
  W=[]
  for j in range(w):
    if (i>>j)&1:
      W.append(j)
  WW.append(W)

for i in range(1<<h):
  for j in range(1<<w):
    cnt=0
    hl=HH[i]
    wl=WW[j]
    for m in range(h):
      for n in range(w):
        if m in hl:
          continue
        if n in wl:
          continue
        if G[m][n]=='#':
          cnt+=1
    if cnt==k:
      ans+=1
print(ans)

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

char S[1001001];
int D[10], F[10];

int main()
{
	scanf ("%s", S);
	for (int i = 0; i < 10; i++) D[i] = i;

	for (int t = 0; S[t]; t++){
		for (int j = 0; j < 10; j++) F[j] = 1e9;
		for (int j = 0; j < 10; j++) for (int i = 0; i < 10; i++){
			int k = j * 10 + i - (S[t] - '0');
			if (k < 0) continue;
			int c = i + k / 10;
			k %= 10;
			if (F[k] > D[j] + c)
				F[k] = D[j] + c;
		}
		for (int j = 0; j < 10; j++) D[j] = F[j];
	}

	int ans = 1e9;
	for (int j = 0; j < 10; j++) if (ans > D[j] + j) ans = D[j] + j;
	printf ("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1152
/*
 * atcoder/abc128_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * 操作C, Dで捨てる可能性があるのは負の宝石のみ.
 * Kの中でA, Bに当てるk回を全探索かな.
 *
 * 捨てるのは簡単. min(K-k回, 負の宝石の個数)だけ小さい方から捨てれば良い.
 * 取得するのが問題. 100000 -10 10 10 100000 -10 (K=3) のような場合両方から取る必要がある.
 * 左右も全探索だな.
 */

int N, K;
vector<ll> A;
void solve() {
  cin >> N >> K;
  A.resize(N);
  loop(n,0,N) cin >> A[n];

  ll max_ = 0;
  for (int len=0; len<N; len++) {
    for (int l=0; l+len<=N; l++) {
      int r = l+len;
      vector<ll> B;
      for (int i=0; i<l; i++) B.push_back(A[i]);
      for (int i=r; i<N; i++) B.push_back(A[i]);
      sort(B.begin(), B.end());
      if (B.size()>K) continue;
      int k = K-B.size();
      for (int i=0; i<B.size(); i++) {
        if (k>0 and B[i] < 0) {
          B[i] = 0; k--;
        }
      }

      ll score = 0;
      for (auto&& b: B) score += b;
      if (chmax(max_, score)) {
        // dump(B);
      }
    }
  }
  cout << max_ << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int dp[100000+1];


int main()
{    
    memset(dp, -1, sizeof(dp));
    int x, a[6]={100, 101, 102, 103, 104, 105};
    cin >> x;

    dp[0] = 0;
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j <= x; j++) {
            if (dp[j] >= 0) dp[j] = 1000000;
            else if (j < a[i] || dp[j - a[i]] <= 0) dp[j] = -1;
            else dp[j] = dp[j - a[i]] - 1;
        }
    }
    if (dp[x] >= 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 640
#include<stdio.h>

void marge(int *,int,int,int);
void margesort(int *,int,int);

int cnt=0;

int main()
{
  int n,i;

  scanf("%d",&n);

  int a[n];

  for(i = 0 ; i < n ; i++)
    {
      scanf("%d",&a[i]);
    }
  margesort(&a[0],0,n);

  
  for(i = 0 ; i < n ; i++)
    {
      printf("%d",a[i]);
      if(i != n-1 ) printf(" ");
    }
  printf("\n%d\n",cnt);
  
  return 0;
}

void marge(int *a,int left,int mid,int right)
{
  int n1 = mid -left;
  int n2 = right - mid;
  int k;
  int i;

  int L[n1],R[n2];

  for(i = 0 ; i < n1 ; i++)
    {
      L[i] = a[left + i];
    }
   for(i = 0 ; i < n2 ; i++)
    {
      R[i] = a[mid + i];
    }

   L[n1] = 1000000001;
   R[n2] = 1000000001;

   int j = 0;
   i = 0;

   for(k = left ; k < right ; k++)
     {
       cnt += 1;
       if(L[i] <= R[j])
	 {
	   a[k] = L[i];
	   i += 1;
	 }
       else
	 {
	   a[k] = R[j];
	   j += 1;
	 } 
     }
}

void margesort(int *a,int left,int right)
{
  if(left+1 < right)
    {
      int mid = (left + right) / 2;
      margesort(&a[0],left,mid);
      margesort(&a[0],mid,right);
      marge(&a[0],left,mid,right);
    }

}



Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,i,j;
    cin>>a;
    int s[a][3];
    for(i=0; i<a; i++)
    {
        for(j=0; j<3; j++)
        {
            cin>>s[i][j];
        }
    }
    int dp[a][3];
    for(i=0; i<3; i++)
    {
        dp[0][i]=s[0][i];
    }
    for(i=1; i<a; i++)
    {
        dp[i][0]=s[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=s[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=s[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[a-1][0],max(dp[a-1][1],dp[a-1][2]))<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<iostream>
using namespace std;
char m[101][101];
int H,W;
void bfs(char c,int h,int w)
{
 if(m[h][w]!=c)
  return;
 m[h][w]='1';
 for(int v=-1;v<=1;v++)
  for(int k=-1;k<=1;k++)
   if(v==0||k==0)
    if(h+v>=0&&h+v<H&&w+k>=0&&w+k<W)
      bfs(c,h+v,w+k);
  return;
}
int main()
{
  int i,k,ans;
 while(scanf("%d%d",&H,&W)&&H!=0&&W!=0)
 {
  ans=0;
  for(i=0;i<H;i++)
   for(k=0;k<W;k++)
    //scanf("%c",&m[i][k]);
    cin>>m[i][k];
  for(i=0;i<H;i++)
   for(k=0;k<W;k++)
    if(m[i][k]!='1')
    { 
      char d=m[i][k];
      bfs(d,i,k);
      ans++;
    }
   printf("%d\n",ans);
  }
  return 0;
} 

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

using namespace std;
#define ll long long

int g[10][10];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char x;
            cin >> x;
            g[i][j] = x == '#';
        }
    }
    int ans = 0;
    for (int i = 0; i < 1 << h; i++) {
        for (int j = 0; j < 1 << w; j++) {
            int res = 0;
            for (int r = 0; r < h; r++) {
                if (i >> r & 1) continue;
                for (int c = 0; c < w; c++) {
                    if (j >> c & 1) continue;
                    res += g[r][c];
                }
            }
//            cout << res << " " << i << " " << j << endl;
            ans += res == k;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  string s,t;
  cin >>s>>t;
  ////////////////
  rep(i,n){
    cout<<s[i]<<t[i];
  }
  cout<<endl;
  
}




Measured memory_bytes: 256
s = list(input())
a = int(s[0]+s[1])
b = int(s[2]+s[3])

if a<=12 and b<=12 and a>0 and b>0:
  print("AMBIGUOUS")
elif b<=12 and b>0:
  print("YYMM")
elif a<=12 and a>0:
  print("MMYY")
else:
  print("NA")

Measured memory_bytes: 3064
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=400010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int A,B,C;
    A=read(), B=read(), C=read();
    if((B*10+C)%4) puts("NO");
    else puts("YES");
    return 0;
}

Measured memory_bytes: 3568
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

A.sort()

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[-1] * i  % MOD)
inv_factorial = [-1] * (N + 1)
inv_factorial[-1] = pow(factorial[-1], MOD - 2, MOD)
for i in reversed(range(N)):
    inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD


ans = 0
for i in range(N - K + 1):
    c = factorial[N - 1 - i] * inv_factorial[K - 1] * inv_factorial[N - K - i]
    ans += c * (A[-1 - i] - A[i])
    ans %= MOD

print(ans)


Measured memory_bytes: 15184
n, m = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(n)]
C = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    l_min = float('inf')
    ans = 0
    for j in range(m):
        l = abs(S[i][0] - C[j][0]) + abs(S[i][1] - C[j][1])
        if l < l_min:
            l_min = l
            ans = j + 1
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

double p;
constexpr int MN = 100001;
int N;
vector<pii> g[MN];

double poi;

double dfs1(int cur,int pre){
    double ret=0;
    for(pii v : g[cur]){
        int nx = v.first;
        int cost = v.second;
        if(nx==pre) continue;
        ret += p*(double)(cost+dfs1(nx,cur));
    }
    return ret;
}

double dfs2(int cur,int pre){
    double ret=poi;
    for(int i=0;i<g[cur].size();i++){
        if(g[cur][i].first==pre) continue;
        ret += p*(g[cur][i].second+dfs2(g[cur][i].first,cur));
    }
    return ret;
}

int main(){
    cin >> p;
    cin >> N;
    rep(i,N-1){
        int x,y,c;cin>>x>>y>>c;
        x--;y--;
        g[x].pb(MP(y,c));
        g[y].pb(MP(x,c));
    }
    poi = dfs1(0,-1);
    cout << Double(dfs2(0,-1)) << endl;
}

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

inline int query(int x, int y) {
	printf("? %d %d\n", x, y);
	fflush(stdout);
	static char opt[4];
	scanf("%s", opt);
	return opt[0] == 'Y';
}

const int N = 4011;
int Ans[N], st[N], tp;
int n, a, b;

int main() {
	scanf("%d%d",&a,&b), n = a + b;
	if(a <= b) return puts("Impossible"), 0;
	for(int i=0;i<n;++i) {
		if(tp and !query(st[tp], i)) --tp;
		else st[++tp] = i;
	}
	
	for(int i=0;i<n;++i)
		Ans[i] = query(st[tp], i);
	
	printf("! ");
	for(int i=0;i<n;++i)
		printf("%d", Ans[i]);
	putchar(10);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int x[4];
  for (int i = 0; i < 4; i++) {
    x[i] = s.at(i) - '0';
  }
  
  int val = 0;
  string op[3];
  
  for (int bits = 0; bits < (1 << 3); bits++) {
    val = x[0];
    for (int i = 0; i < 3; i++) {
      if ((bits >> i) & 1) {
        val += x[i + 1];
        op[i] = "+";
      } else {
        val -= x[i + 1];
        op[i] = "-";
      }
    }
    
    if (val == 7) {
      for (int i = 0; i < 3; i++) {
        cout << x[i] << op[i];
      }
      cout << x[3] << "=7" << endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
ans=0

for i in range(1,n+1):
    if i%3==0 and i%5==0:
        pass
    elif i%3==0:
        pass
    elif i%5==0:
        pass
    else:
        ans+=i
print(ans)

Measured memory_bytes: 9160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  vector<ll>h(n);
  rep(i,n)cin>>h[i];
  bool ng=false;
  ll maxv=0;
  rep(i,n){
    chmax(maxv,h[i]);
    if(maxv-h[i]>1)ng=true;
  }
  if(ng)cout<<"No";
  else cout<<"Yes";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

using namespace std;

int check(char a,char b){
    if(a==b) return 1;
    return 0;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    n*a<b?cout<<n*a:cout<<b;
return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  vector<ll> v(0);
  v.push_back(a*x+b*y);
  v.push_back(c*min(x,y)*2+a*(x-min(x,y))+b*(y-min(x,y)));
  v.push_back(c*max(x,y)*2);
  sort(all(v));
  cout << v[0] << endl;

}

Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))
ans=0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if abs(L[j]-L[k])<L[i] and L[i]<L[j]+L[k] and L[i]!=L[j] and L[i]!=L[k] and L[k]!=L[j]:
        ans+=1
        #print(L[i],L[j],L[k])
print(ans)

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

int main()
{
  ll n; cin >> n;
  
  string s;
  ll a[5],ans=0;
  rep(i,5) a[i]=0;
  
  rep(i,n) {
    cin >>s;
    if (s[0] =='M') {
      a[0]++;
    }
    else if (s[0] =='A') {
      a[1]++;
    }
    else if (s[0] =='R') {
      a[2]++;
    }
    else if (s[0] =='C') {
      a[3]++;
    }
    else if (s[0] =='H') {
      a[4]++;
    }
  }
    ans = a[0]*a[1]*a[2] + a[0]*a[1]*a[3] + a[0]*a[1]*a[4] +
      a[0]*a[2]*a[3] + a[0]*a[2]*a[4] + a[0]*a[3]*a[4] +
      a[1]*a[2]*a[3] + a[1]*a[2]*a[4] + a[1]*a[3]*a[4] +
      a[2]*a[3]*a[4];
  cout << ans << endl;      
}

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

typedef long long int ll;

int main () {


    ll n;
    cin >> n;

    ll a[n];

    for (ll i=0 ; i<n ; i++) {
    	cin >> a[i];
    }

    ll sum = 0;

    for (ll i=0 ; i<n ; i++) {
    	for (ll j=i+1 ; j<n ; j++) {
    		sum += a[i]*a[j];
    	}
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;

typedef unsigned long long ll;

int main(){
	int N;
	while(scanf("%d",&N),N){
		int data[64]={0};
		rep(i,N){
			int f;
			scanf("%d",&f);
			rep(j,f){
				int tmp;
				scanf("%d",&tmp);
				data[i] |= 1<<tmp;
			}
		}
		int ans = -1;
		ll memo[64]={0};
		rep(i,N){
			memo[i] = 1ll<<i;
		}
		reps(i,1,31){
			rep(j,N){
				if(data[j] & 1<<i){
					reps(k,j+1,N){
						if(data[k] & 1<<i){
							memo[j] |= memo[k];
							memo[k] = memo[j];
						}
					}
				}
			}
			rep(j,N){
				if(memo[j] == (1ll<<N)-1){
					ans = i;
					break;
				}
			}
			if(ans != -1)break;
		}

		printf("%d\n",ans);

	}
	return 0;
}

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

static const int MAX = 1000;
static const int VMAX = 10000;
int n, s, A[MAX], B[MAX], T[VMAX+1];

int solve() {
    int i, ans = 0;
    bool V[MAX];
    for(i=0; i<n; ++i) {B[i] = A[i]; V[i] = false;}
    sort(B, B+n);
    for(i=0; i<n; ++i) T[B[i]] = i;
    for(i=0; i<n; ++i) {
        if(V[i]) continue;
        int S = 0, an = 0, cur = i, m = VMAX;
        while(1) {
            V[cur] = true; ++an;
            int v = A[cur]; m = min(m, v);
            S += v; cur = T[v];
            if(V[cur]) break; 
        }
        ans += min(S+(an-2)*m, m+S+(an+1)*s);
    }
    return ans;
}

int main()
{
    cin >> n;
    s = VMAX;
    for(int i=0; i<n; ++i) {
        cin >> A[i];
        s = min(s, A[i]);
    }
    int ans = solve();
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string str;
map<char,int> ma;

int main() {
    while (cin >> str) {
        ma.clear();
        for (int i = 0; i < str.size(); ++i) ma[str[i]]++;
        int res = ma['K'];
        chmin(res, ma['U']);
        chmin(res, ma['P']);
        chmin(res, ma['C']);
        
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1192
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a) for(int i=(a);;++i)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(int argc, const char * argv[]) {
    int H,W;
    while(true){
        cin >> H >> W;
        if(H==0 && W==0) break;
        FOR(vert, 0, H){
            if (vert==0 || vert==H-1) {
                FOR(hori, 0, W){
                    cout << '#' ;
                }
                cout << endl;
            }
            
            else{
              FOR(hori, 0, W){
                if(hori==0 || hori==W-1) cout << '#' ;
                else cout <<'.';
              }
            cout << endl;
            }
        }
        cout << endl;
    }
}




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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	flag==true;

	cin>>s1>>s2;

//	if(s1==s2){
//        cout<<"EQUAL"<<endl;
//	}
//	else if(s1>s2){
//        cout<<"GREATER"<<endl;
//	}
//	else{
//        cout<<"LESS"<<endl;
//	}

	if(s1.length()>s2.length()){
        cout<<"GREATER"<<endl;
        return 0;
	}
	else if(s1.length()<s2.length()){
        cout<<"LESS"<<endl;
        return 0;
	}
	else{
        f(i,0,s1.length()-1){
            if(s1[i]==s2[i]){
                flag=true;
            }
            else if(s1[i]>s2[i]){
                cout<<"GREATER"<<endl;
                return 0;

            }
            else {
                cout<<"LESS"<<endl;
                return 0;
            }

        }
        cout<<"EQUAL"<<endl;
	}


}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	int count = 0;
	for(int i=1;i<n-i;i++) {
		if(i!=n-i && n-i>=1) {
			count++;
		}
	}
	print(count);
	return 0;
}


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

    for (n in 1..3500) {
        for (w in 1..3500) {
            val h = (N*n*w) / (4*n*w - N*w - N*n)
            if (h - h.toLong().toDouble() == 0.0 && h > 0) {
                println("${h.toLong()} $n $w")
                return
            }
        }
    }
}

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

int main() {


int k,a,b;
cin>>k>>a>>b;
bool x =false;
for(int i=1;i<1000;i++){
    if(k*i<=b&&a<=k*i){
        cout<<"OK"<<endl;
        x=true;
        break;
    }
}
if(x==false){
    cout<<"NG"<<endl;
}



}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;






char ar[100][100];

int main()
{
    idfc;
    int n,m;
    cin>>n>>m;
    int i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)cin>>ar[i][j];
    }
    int x,y;
    int c;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(ar[i][j]=='.')
            {
                c=0;
                for(x=i-1;x<=i+1;x++)
                {
                    for(y=j-1;y<=j+1;y++)
                    {
                        if(i!=x||j!=y)
                        {
                            if(x>=1&&x<=n&&y>=1&&y<=m)
                            {
                                if(ar[x][y]=='#')c++;
                            }
                        }
                    }
                }
                ar[i][j]=48+c;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)cout<<ar[i][j];
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3628
from datetime import datetime as dt
import itertools
N = int(input())
dp = [ [[[0 for _ in range(N + 1) ]for _ in range(5)] for _ in range(5)] for _ in range(5)]

# c1 c2 c3
# 0: dammy (DP を初期化するのにこれがあると便利)
# for c2 in range(4):
#     for c3 in range(4):
#         for c1 in range(4):
#             dp[c3][c2][c1][2] = 1 #末尾2文字に関してDP (規約違反に関しては，
        # 規約違反でない文字列の末尾2文字に対して1文字加えたときに判断できるので)
MOD = 10 ** 9 + 7

dp[0][0][0][0] = 1 # 0→ 存在しない の意味
A = 1
G = 2
C = 3
T = 4

# ~~~~ c1 c2
for i in range(0,N):
    for c1 in range(5): #1文字前
        for c2 in range(5): #2文字前
            for c3 in range(5): # 3文字前
                for c in range(1,5): # 新たな文字を加える
                    if c2 == A and c1 == G and c == C:
                        continue
                    if c3 == A and c2 == G and c == C:
                        continue
                    if c3 == A and c1 == G and c == C:
                        continue
                    if c2 == G and c1 == A and c == C:
                        continue
                    if c2 == A and c1 == C and c == G:
                        continue
                    dp[c2][c1][c][i + 1] +=(dp[c3][c2][c1][i] % MOD)


ans = 0
for c1 in range(1,5):
    for c2 in range(1,5):
        for c3 in range(1,5):
            ans += dp[c3][c2][c1][N]
        # print(f"{alpha[c1] + alpha[c2]}: {dp[c1][c2][N]}")

print(ans % MOD)


Measured memory_bytes: 3568
#include <stdio.h>

int main() {
  int x, y;
  scanf("%d%d",&x,&y);
  
  while(x % y != 0 && y % x != 0) { 
    if (x > y) x = x % y;
    else if (y > x) y = y % x;
  }
  if(x > y) printf("%d\n",y);
  else printf("%d\n",x);

  return 0;
}

Measured memory_bytes: 592
n = int(input())
h = [int(x) for x in input().split()]

dp = [0] * n

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

print(dp[n - 1])


Measured memory_bytes: 13980
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u64,
    }

    let mut ans = n;
    for i in 1..((n as f64).sqrt() as u64 + 1) {
        if n % i == 0 {
            let a = i.to_string().len() as u64;
            let b = (n / i).to_string().len() as u64;

            ans = std::cmp::min(ans, std::cmp::max(a, b))
        }
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{   
    string s,p;
    cin >> s >> p;
    s+=s;
    if(s.find(p)!=-1)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3184