akhauriyash/Code-Regression huggingface dataset:
h, w, k = map(int, input().split())
a = [0]*(w-1) + [0,1]
for i in range(w-1):
    a[i] = a[i-1] + a[i-2]
dp = [0]*(w+1)
tmp = [0]*(w+1)
dp[0] = 1
for _ in range(1, h+1):
    for i in range(w):
        tmp[i] = (dp[i]*a[i-1]*a[w-i-2]
            + dp[i+1]*a[i-1]*a[w-i-3]
            + dp[i-1]*a[i-2]*a[w-i-2]) % (10**9+7)
    dp, tmp = tmp, dp
print(dp[k-1])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
int main() {
	int n;
	std::cin >> n;
	bool is_four = false;
	std::string color;
	for (auto i = 0; i < n; ++i) {
		std::cin >> color;
		if (color == "Y") is_four = true;
	}
	if (is_four) std::cout << "Four" << std::endl;
	else std::cout << "Three" << std::endl;
}

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

vector<int> solve(int n) {
    vector<int> a;
    unordered_map<int, vector<int> > mp;
    for (int i = 2; a.size() < n; i++) {
        if (mp.find(i) == mp.end()) {
            if (i % 5 == 1)
                a.push_back(i);
            mp[i * i].push_back(i);
        } else {
            for (int x: mp[i]) {
                mp[i + x].push_back(x);
            }
            mp.erase(i);
        }
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    vector<int> res = solve(n);
    cout << res[0];
    for (int i = 1; i < n; i++) {
        cout << ' ' << res[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long x;
  cin>>x;
  int l=0;
  long long p=100;
  while(!(p>=x)){
    p=p+p*0.01;
    l=l+1;
  }
  cout<<l<<endl;
}
  

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<setprecision(3); cout<<fixed;
  #ifdef DEBUG
  freopen("ip.txt","r",stdin);
  clock_t tStart = clock();
  #endif
  char s1[3],s2[3];
  for(int i=0;i<3;++i) cin>>s1[i];
  for(int i=0;i<3;++i) cin>>s2[i];
  for(int i=0;i<3;++i) if(s1[i]!=s2[2-i]) {cout<<"NO\n"; return 0;}
  cout<<"YES\n";


  #ifdef DEBUG
	cout<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)<<"s.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char str[5006];
int main(){
	int n;
	double a,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lf",&a),sum+=1.0/a;
	printf("%.6lf\n",1.0/sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int a = 0, b = 0, c = 0, d = 0;
  cin >> a >> b >> c >> d;
  
  if((abs(b-a) <= d && abs(c-b) <= d) || abs(c-a) <= d) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int L[] = new int[M];

        for(int i = 0; i < N; ++i) {
            int K = sc.nextInt();
            for(int j = 0; j < K; ++j) {
                ++L[sc.nextInt() - 1];
            }
        }

        int ans = 0;
        for(int i = 0; i < M; ++i) {
            if(L[i] == N) ++ans;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 22192
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
bool enough(vector<ll>& arr, ll B, ll extra, ll guess) {
    ll used = 0;
    for(auto& val: arr) {
        if (val > B*guess) {
            used += 1+(val-B*guess-1) / extra;
        }
    }
    return used <= guess;
}
int main() {
    int n;
    ll A, B;
    cin >> n >> A >> B;
    vector<ll> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    ll l = 1;
    ll r = 1+(*max_element(arr.begin(), arr.end())-1) / B;
    while (l < r) {
        ll mid = l+(r-l)/2;
        if (enough(arr, B, A - B, mid)) {
            r = mid;
        } else {
            l = mid+1;
        }
    }
    cout << l <<endl;
    return 0;
}




Measured memory_bytes: 1024
import math


def check(deg):
    if deg > 180:
        return 360 - deg
    else:
        return deg


a, b, h, m = map(int, input().split())
deg_h = 360 * (h / 12) + 360 * 5 / 60 * (m / 60)
deg_m = 360 * (m / 60)

deg = abs(deg_h - deg_m)
deg = check(deg)

print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(deg))))

Measured memory_bytes: 9588
def main():
    N, M, Q = map(int, input().split())
    A = [[0] * (N + 1) for _ in range(N + 1)]
    for _ in range(M):
        L, R = map(int, input().split())
        A[L][R] += 1
    
    S = [[0] * (N + 2) for _ in range(N + 2)]
    for i in range(N+1):
        for j in range(N+1):
            S[i+1][j+1] = S[i][j+1] + S[i+1][j] - S[i][j] + A[i][j]
    for _ in range(Q):
        p, q = map(int, input().split())
        ans = S[q+1][q+1] - S[p][q+1] - S[q+1][p] + S[p][p]
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 80168
#include <iostream>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;
    if(a != 1 && b != 1)
        cout << 1;
    else if(a != 2 && b != 2)
        cout << 2;
    else if(a != 3 && b != 3)
        cout << 3;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
zahyou = [list(map(int,input().split())) for i in range(N)]
 
H = -1
C_x = 0
C_y = 0
 
def height(C_x,C_y,x,y,h):
  H = h + abs(x-C_x) + abs(y-C_y)
  return H
 
def koud(C_x,C_y,H,x,y):
  h = H - abs(x-C_x) - abs(y-C_y)
  return h
 
flag = False
for i in range(0,101):
  C_x = i
  for j in range(0,101):
    C_y = j
    H = -1
    memo = []
    for k in range(N):
      if zahyou[k][2] == 0:#高度が0のとき
        memo.append(k)
        continue
      if H < 0:
        H = height(C_x,C_y,zahyou[k][0],zahyou[k][1],zahyou[k][2])
      else:
        if zahyou[k][2] != koud(C_x,C_y,H,zahyou[k][0],zahyou[k][1]):
          break
        else:
          continue        
    else:
      for l in range(len(memo)):
        if H <= height(C_x,C_y,zahyou[l][0],zahyou[l][1],zahyou[l][2]):
          continue
        else:
          break
      else:  
        flag = True
        break
    if flag:
      break
  if flag:
    break

print(C_x,C_y,H)

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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2 * 1000 * 1000 + 17, mod = 1e9 + 7;

int sum(int a, int b) { 
	a += b;
	if (a < 0)
		a += mod;
	else if (a >= mod)
		a -= mod;
	return a;
}
int mul(int a, int b) { return (1LL * a * b) % mod; }
int pw(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1)
			res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int fac[MAXN], ifac[MAXN];

void prep() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i < MAXN; i++)
		fac[i] = mul(fac[i - 1], i), ifac[i] = pw(fac[i], mod - 2);
}
int C(int n, int r) { return mul(fac[n], mul(ifac[r], ifac[n - r])); }
int get(int x, int y) {
	int res = 0;
	for (int i = 0; i <= x; i++)
		res = sum(res, C(i + y + 1, i + 1));
	return res;
}

int r1, r2, c1, c2;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	prep();
	cin >> r1 >> c1 >> r2 >> c2;
	r1--, c1--;
	cout << sum(sum(get(r2, c2), -sum(get(r1, c2), get(r2, c1))), get(r1, c1)) << endl;
	return 0;
}


Measured memory_bytes: 15872
#include<cstring>
#include<iostream>
#include<cstdlib>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int n, a[101];
    cin >> n;
    rep(i, n) cin >> a[i];
    int ap = 0;
    rep(i, n) {
        if (a[i] % 2 == 0) {
            if (0 != a[i] % 3 && 0 != a[i] % 5) ap++;  
        } 
    }
    if (ap == 0) {
        cout << "APPROVED" << endl;
    } else {
       cout << "DENIED" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto V = new long[](N);
    auto W = new long[](N);
    foreach (i; 0 .. N)
        scan(V[i], W[i]);
    auto memo = new long[][](min(2 ^^ 10 + 1, N + 1), 10 ^^ 5 + 2);
    foreach (i; 1 .. memo.length)
    {
        foreach (j; 0 .. 10 ^^ 5 + 1)
        {
            memo[i][j] = memo[i][j].max(memo[i / 2][j]);
            memo[i][min(j + W[i - 1], 10 ^^ 5 + 1)] = memo[i][min(j + W[i - 1], 10 ^^ 5 + 1)].max(
                    memo[i / 2][j] + V[i - 1]);
        }
    }
    long solve(long v, long l)
    {
        long[] I;
        long i = v;
        while (memo.length <= i)
            I ~= i, i /= 2;
        // writeln(I);
        long ans;
        foreach (ulong state; 0UL .. 2UL ^^ I.length + 1)
        {
            long value, weight;
            foreach (j; 0 .. I.length)
                if ((1 << j) & state)
                {
                    value += V[I[j] - 1];
                    weight += W[I[j] - 1];
                }
            if (l < weight)
                continue;
            ans = ans.max(memo[i][l - weight] + value);
        }
        return ans;
    }

    long Q = lread();
    foreach (_; 0 .. Q)
    {
        long v, l;
        scan(v, l);
        solve(v, l).writeln();
    }
}


Measured memory_bytes: 813412
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll a,b,c,d,x,y;
ll k;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b>>c>>d>>k;
	x=a*60+b;y=c*60+d;
	cout<<y-x-k;
	return 0;
}



Measured memory_bytes: 3640
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)

if sum(a[i] % 2 for i in a) != center:
    print('No')
    exit()
a = {i: a[i] - (a[i] % 2) for i in a}
cnt = sum(a[i] % 4 == 2 for i in a)
print('Yes' if cnt <= side else 'No')


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int d[51][51];
char g[51][51];
int h,w;

bool isin(pi c){
  int y=c.first, x=c.second;
  return x>=0 && x<w && y>=0 && y<h;
}

bool is_w(pi c){
  int y=c.first, x=c.second;
  return g[y][x]=='#';
}

int main(){
  cin>>h>>w;
  int wall_count=0;
  rep(y, h)rep(x, w){
    cin>>g[y][x];
    if(g[y][x]=='#')wall_count++;
  }

  queue<pair<pi, int>>q;
  q.push( {{0,0}, 1} );
  while( !q.empty() ){
    auto pc = q.front();q.pop();
    pi c = pc.first;
    int y = c.first, x=c.second;
    int cost = pc.second;

    if( !isin(c) )continue;
    if( is_w(c) )continue;
    if(d[y][x]>0)continue;

    d[y][x]=cost;
    if(y==h-1 && x==w-1)break;
    q.push( {{y+1, x}, cost+1} );
    q.push( {{y-1, x}, cost+1} );
    q.push( {{y, x+1}, cost+1} );
    q.push( {{y, x-1}, cost+1} );
  }

  if(d[h-1][w-1]==0)cout<<-1;
  else cout<<w*h - wall_count - d[h-1][w-1];

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <utility>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
#define max(a,b) a > b ? a : b
using namespace std;
using ll = long long;
const int INF = 1e9;

bool ReachFrom1[2510];
bool ReachToN[2510];
bool ok[2510];
vector<int> Graph[2510];
vector<int> RGraph[2510];

void dfs(int v){
    if(ReachFrom1[v])return;
    ReachFrom1[v] = true;
    for(int u : Graph[v]){
        dfs(u);
    }
}

void rdfs(int v){
    if(ReachToN[v])return;
    ReachToN[v] = true;
    for(int u : RGraph[v]){
        rdfs(u);
    }
}

int main(){
    int n,m,p;
    cin >> n >> m >> p;
    vector<tuple<int,int,int> > edges;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        --a; --b;
        c -= p;
        c *= -1;
        edges.emplace_back(a,b,c);
        Graph[a].push_back(b);
        RGraph[b].push_back(a);
    }
    dfs(0);
    rdfs(n-1);
    rep(i,n) ok[i] = ReachFrom1[i] & ReachToN[i];
    {
        vector<int> d(n,INF);
        d[0] = 0;
        bool update = true;
        int step = 0;
        while(update){
            update = false;
            rep(i,m){
                int a,b,c;
                tie(a,b,c) = edges[i];

                if(!ok[a]) continue;
                if(!ok[b]) continue;
                if(d[a]+c < d[b]){
                    update = true;
                    d[b] = d[a]+c;
                }
            }
            step++;
            if(step > n){
                cout << -1 << endl;
                return 0;
            }
        }
        int ans = -d[n-1];
        ans = max(ans,0);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    string s;
    cin>>s;
    ll last=0;
    ll l=s.length();
    ll ans=0;
    ll sum=0;
    for(ll i=0;i<l;++i){
        if(s[i]=='C'){
            last=i;
            ans+=1;
            break;
        }
    }
    for(ll i=last;i<l;++i){
        if(s[i]=='F'){
            sum+=1;
            break;
        }
    }
    if(ans==1 and sum==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int[][] arr = new int[N-1][3];
		for (int i = 0; i < N-1; i++) {
			arr[i][0] = reader.nextInt();
			arr[i][1] = reader.nextInt();
			arr[i][2] = reader.nextInt();
		}
		for (int i = 0; i < N-1; i++) {
			int ans = arr[i][1] + arr[i][0];
			for (int j = i+1; j < N-1; j++) {
				ans += Math.max(0, arr[j][1] - ans);
				if (ans % arr[j][2] != 0) {
					ans =  (ans / arr[j][2] + 1) * arr[j][2];
				}
				ans += arr[j][0];
			}
			System.out.println(ans);
		}

		System.out.println(0);
		reader.close();
	}
}





Measured memory_bytes: 26840
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


typedef long long ll;
typedef pair<ll, ll> P;


ll dist[2600];
int main()
{
  ll N, M, P; cin >> N >> M >> P;
  vector<vector<pair<ll, ll>>> v(N);
  REP(i, M) {
    ll a, b, c; cin >> a >> b >> c;
    a--; b--;
    v[a].PB(MP(b, -(c-P)));
  }

  REP(i, 2600) dist[i] = LLINF;
  dist[0] = 0;
  REP(i, N - 1) {
    REP(j, N) {
      if (dist[j] == LLINF) continue;
      for (auto e : v[j]) {
        if (dist[e.first] > dist[j] + e.second) {
          dist[e.first] = dist[j] + e.second;
        }
      }
    }
  }

  ll ans = dist[N - 1];
  REP(i, N - 1) {
    REP(j, N) {
      if (dist[j] == LLINF) continue;
      for (auto e : v[j]) {
        if (dist[e.first] > dist[j] + e.second) {
          dist[e.first] = dist[j] + e.second;
        }
      }
    }
  }
  if (ans != dist[N - 1]) cout << "-1" << endl;
  else cout << max(0LL, -ans) << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long h = sc.nextInt();
        long w = sc.nextInt();

        if(h == 1 || w == 1) {
            System.out.println(1);
            return;
        }

        long res = h * w / 2 + (h*w) % 2;
        System.out.println(res);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
using namespace std;

int main(){
	int N,M;
	while(cin>>N>>M,N||M){
		int latte[1001],ans=0;
		vector<int> comb;
		latte[0]=0;
		for(int i=1;i<=N;i++){
			cin>>latte[i];
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				comb.push_back(latte[i]+latte[j]);
			}
		}
		sort(comb.begin(),comb.end());
		//for(int i=0;i<comb.size();i++) printf("%d ",comb[i]); puts("");
		for(int i=0;i<=N;i++){
			for(int j=0;j<=N;j++){
				vector<int>::iterator itr;
				itr = upper_bound(comb.begin(),comb.end(),M-latte[i]-latte[j]);
				if(itr!=comb.begin()) ans = max(ans,latte[i]+latte[j]+*(itr-1));
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 9172
#include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(M=1<<31,i=s=0;i<n;s+=a[i],k<++i&&(s-=a[i-k-1])&&M<s&&(M=s))std::cin>>a[i];}

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

int main() {
  string S; cin >> S;
  int len; len = S.length();
  int zeros; zeros = 0;
  int ones; ones = 0;
  char one; one = '1';
  for(int i=0; i < len; i++){
    if(S[i] == one){
      ones += 1;
    }
    else{
      zeros += 1;
    }
  }
  int ans; ans = 0;
  if(zeros == ones){
    ans = 2 * zeros;
  }else if(zeros > ones){
    ans = 2 * ones;
  }else{
    ans = 2 * zeros;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
const int SIZE = 100000;

int Partition(int *A, int p, int r)
{
    int x = A[r - 1];
    int i = p;
    for (int j = p; j < r - 1; j++)
    {
        if (A[j] <= x)
        {
            int tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;

            i++;
        }
    }

    int tmp = A[i];
    A[i] = A[r - 1];
    A[r - 1] = tmp;

    return i;
}

int main()
{
    int A[SIZE];
    int n;

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

    int par = Partition(A, 0, n);

    int i;
    for (i = 0; i < par; i++)
    {
        cout << A[i] << ' ';
    }
    cout << '[' << A[i] << ']' << ' ';
    i++;
    for (; i < n - 1; i++)
    {
        cout << A[i] << ' ';
    }
    cout << A[i] << endl;

    return 0;
}


Measured memory_bytes: 3384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    char[] s = scanner.next().toCharArray();
    int K = scanner.nextInt();
    for (int i = 0; i < s.length; i++) {
      int r = 'z' - s[i] + 1;
      if (s[i] != 'a' && K >= r) {
        s[i] = 'a';
        K -= r;
      }
    }
    if (K > 0) {
      s[s.length - 1] = (char) (s[s.length - 1] + K % 26);
    }
    System.out.println(new String(s));
  }
}


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

int main(){
  int n;
  string s;
  cin >>n >>s;
  int ans = 0;
  for(int i = 1; i<n; i++){
    int cnt = 0;
    for(char c= 'a'; c<='z'; c++){
      bool left=false, right=false;
      rep(j,i){
        if(s[j]==c) left = true;
      }
      for(int j = i; j<n; j++){
        if(s[j]==c) right = true;
      }
      if(left&&right) cnt++;
    }
    if(ans<cnt) ans = cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

struct item_1 {
    bool possible;
    int weight;
};

struct item_2 {
    int weight;
    int mimi;
};

double rev(double a) {
    return (double(1) - a);
}

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int n;
    scanf("%d", &n);
    vector<double> a(n + 1);
    for (int i = 1; i <= n; i++)
        scanf("%lf", &a[i]);
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
    dp[1][1] = a[1];
    dp[1][0] = rev(a[1]);
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= (i - 1); j++) {
            dp[i][j + 1] += (dp[i - 1][j] * a[i]);
            dp[i][j] += (dp[i - 1][j] * rev(a[i]));
        }
    }
    double ans = 0;
    for (int i = (n / 2) + (n % 2); i <= n; i++)
        ans += (dp[n][i]);
    printf("%.9f", ans);
    return 0;
}

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

int main (void){
  long long int n,a = 0;

  cin >> n;
  for(int i = 0; i <= n; i++){
    if(i % 3 == 0 || i % 5 == 0){
    }else{
      a = a + i;
    }
  }

  cout << a << "\n";

  return 0;
}


Measured memory_bytes: 3632
/**Bismillahir Rahmanir Rahim.**/

/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<cstring>
#include<cstdio>

using namespace std;

//----------------------------------------------------------//

typedef long long int                        ll;
typedef unsigned long long int              ull;
typedef long double                          ld;

//-----------------------------------------------------------//
#define      test                       int t; cin>>t;  while(t--)

#define      cube(x)                    (x*x*x)
#define      sqr(x)                     (x*x)

#define      sc1(x)                     scanf("%lld",&x);
#define      sc2(x,y)                   scanf("%lld %lld", &x, &y)
#define      scf1(x)                    scanf("%lf",&x)
#define      scf2(x,y)                  scanf("%lf %lf", &x, &y)

#define      INPUT                      freopen("input.txt", "r", stdin)
#define      OUTPUT                     freopen("output.txt", "w", stdout)

#define      srev                       reverse(s.begin(),s.end())
#define      sortstr                    sort(s.begin(), s.end());
#define      gtl(x)                     getline(cin, (x))

#define      PI                         acos(-1) // 3.1415926535897932
#define      MIN                        9999999

#define      Faster                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


//-----------------------------------------------------------//

int main()
{
    Faster;




    int n ;

    cin >> n ;

    if ( n < 30 )
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

   return 0 ;
}







Measured memory_bytes: 3620
# 整数 a と、英小文字からなる文字列 s が入力
# a が 3200 以上なら s と出力し、 a が 3200 未満なら red と出力
# 2800 ≦ a < 5000
# s は長さ 1 以上 10 以下の文字列である
# s の各文字は英小文字である

# 入力された値を数値と文字列として扱う
a = int(input())
s = input()

# print(a)
# print(s)

# 条件分岐
if a >= 3200:
    print(s)
else:
    print('red')

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

int main()
{
	int a, b, c; cin >> a >> b >> c;
	int x, y; cin >> x >> y;

	const int n = 100000;

	int ans = 2147483647;

	for (int i = 0; i <= n; i++) {

		int x_mai = max(0, x - i);
		int y_mai = max(0, y - i);

		ans = min(ans, c * 2 * i + a * x_mai + b * y_mai);

	}

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

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

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;

int main()
{
	fastio;
	
	int k;
	cin>>k;
	int rem=0;
	for(int i=1; i<=k; i++)
	{
		rem= (rem*10 + 7)%k;
		if(!rem)
		{
			cout<<i<<nl;
			bdyptb;
		}
	}    
	cout<<-1<<nl;
}

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

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

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

int N, M, X;
ll level[15], arr[15][15], cost[15];

ll solve(int pos) {
    if (pos == N+1) {
        bool ok = true;
        FOR(i, 1, M+1) ok &= (level[i] >= X);
        return (ok) ? 0 : INF;
    }

    ll ans = INF;
    FOR(i, 1, M+1) level[i] += arr[pos][i];
    ans = min(ans, solve(pos+1)+cost[pos]);
    FOR(i, 1, M+1) level[i] -= arr[pos][i];
    ans = min(ans, solve(pos+1));
    return ans;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> N >> M >> X;

    FOR(i, 1, N+1) {
        cin >> cost[i];
        FOR(j, 1, M+1) {
            cin >> arr[i][j];
        }
    }

    ll ans = solve(1);

    if (ans == INF) {
        ans = -1;
    }

    cout << ans << "\n";

}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
int N;
cin >> N;
ll K;
cin >> K;
int Q;
cin >> Q;

vector<ll>P(N, K - Q);

vector<int>ans(Q);
REP(i, Q){
    cin >> ans.at(i);
    ans.at(i)--;
    P.at(ans.at(i))++;
}


REP(i, N){
if(P.at(i) <= 0) no;
else yes;

}


}

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

using namespace std;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  
  vector<int> a;
  vector<int> b;
  int min_a = 100000;
  for(int i=0; i<A; ++i) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
    if (min_a > tmp) {
      min_a = tmp;
    }
  }
  int min_b = 100000;
  for(int i=0; i<B; ++i) {
    int tmp;
    cin >> tmp;
    b.push_back(tmp);
    if (min_b > tmp) {
      min_b = tmp;
    }
  }
  int x, y, c;
  int minm = 200000;
  for(int i=0; i<M; ++i) {
    cin >> x >> y >> c;
    if (minm > a[x-1] + b[y-1] - c) {
      minm = a[x-1] + b[y-1] -c;
    }
  }

  cout << min(minm, min_a+min_b) << endl;
}

Measured memory_bytes: 1400
eval'K,X,Y='+`dd`.split*?,;x,y,*s=X.abs,Y.abs;d=x+y;x,y=y,x if f=x>y;K%2-d%2<0&&(p -1;exit);n=(d-1)/K+1;n+=d<K ? 1 :(d-n*K)%2;a=n<2 ?x:(d-n*K)/2;b=K-a.abs;d%2-d/K>0&&(s=[[0,-K]];a=b=(d-K)/2);n.times{s<<[a,b];t=[x-a,K].min;a+=t;b+=K-t};p s.size;s.each{|a,b|f&&(a,b=b,a);puts [a*(X<=>0.1),b*(Y<=>0.1)]*?\s}

Measured memory_bytes: 20868
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    ll K;
    cin >> N >> K;
    vll A(N);
    rep(i, N) cin >> A[i];
    vll S(N + 1);
    rep(i, N) {
        S[i + 1] = S[i] + A[i];
    }
    map<ll, int> cnt;
    ll ans = 0;
    REP(i, 0, N + 1) {
        S[i] -= i;
        S[i] = mod(S[i], K);
        
        //S[i] =mod(S[i], K);
    }
    REP(i, 0, min(ll(N) + 1, K)) {
        ans += cnt[S[i]];
        cnt[S[i]]++;
    }

    //for (auto& c : cnt) {
    //    ans += c.second * (c.second - 1) / 2;
    //}

    REP(i, K, N + 1) {
        int j = i - K;
        cnt[S[j]]--;
        ans += cnt[S[i]];
        cnt[S[i]]++;
    }

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

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
    ll n, d;
    cin >> n >> d;
    Graph x(n, vll(d, 0));
    REP(i, n) {
      REP(j, d) {
        cin >> x[i][j];
      }
    }

    ll count = 0;
    REP(i, n) {
      FOR(i2, i + 1, n - 1) {
        ll dist = 0;
        REP(j, d) {
          dist += (x[i][j] - x[i2][j]) * (x[i][j] - x[i2][j]);
        }
        // cout << dist << " " << i << " " << i2 << endl;
        ld ans = sqrt(dist);
        if (ceil(ans) == floor(ans)) {
          count++;
        } 
      }
    }
    COUT(count);

}



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

/*
3 2
1 2
5 5
-2 8
*/


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

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin>>h.at(i);
    int maxt=0,t=0;
    int i=0;
    while(i<n-1){
        if(h.at(i)>=h.at(i+1)){
            t++;
        }
        else{
            t=0;
        }
        maxt=max(t,maxt);
        i++;
    }
    cout << maxt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

std::string solve(std::string str){
  std::string a(str.begin(), str.begin()+4);
  
  return a;
}

int main(){
  std::string str;
  std::cin >> str;
  int tmp = str.size();

  std::string result = solve(str);

  std::cout << result << ' ';
  for(int i = 0; i < tmp - 4; i++){
    std::cout << str[i + 4];
  }

  std::cout << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var ans = 0;
            //var s = int.Parse(ReadLine());
            var s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            for (int i = s[0]; i <= s[1]; i++)
            {
                if (i % s[2] == 0)
                    ans++;
            }
            //var s = Console.ReadLine().Split(' ');

            WriteLine(ans);
            Out.Flush();
        }
    }
}

Measured memory_bytes: 28140
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int bfs(int a, int b, int c, int count)
{
	if (a == b && b == c) {
		return count;
	}
	int mn = INF;
	if (a < c && b < c)
		mn = min(bfs(a + 1, b + 1, c, count + 1), mn);
	if (b < a && c < a)
		mn = min(bfs(a, b + 1, c + 1, count + 1), mn);
	if (a < b && c < b)
		mn = min(bfs(a + 1, b, c + 1, count + 1), mn);
	if (c == b && a < b)
		mn = min(bfs(a + 2, b, c, count + 1), mn);
	if (a == c && b < a)
		mn = min(bfs(a, b + 2, c, count + 1), mn);
	if (a == b && c < a)
		mn = min(bfs(a, b, c + 2, count + 1), mn);
	return mn;
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << bfs(a, b, c, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

   int N; cin >> N;

   int x_now = 0, y_now = 0, t_now = 0;
   
   vector < int > t(N),x(N),y(N);
   REP(i,N) {
        cin >> t[i] >> x[i] >> y[i];
   }

   REP(i,N) {
        int diff = abs(x_now - x[i]) + abs(y_now - y[i]);
        int t_diff = abs(t_now - t[i]);
        x_now = x[i];
        y_now = y[i];
        t_now = t[i];
        if (diff % 2 != t_diff % 2) {
            cout << "No" << endl;
            return 0;
        }
        if (diff > t_diff) {
            cout << "No" << endl;
            return 0;
        }
   }

   cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int K,S;
  cin >> K >> S;
  int count = 0;
  for(int x=0; x<=K; x++){
    for(int y=0; y<=K; y++){
      if(0<=S-x-y && S-x-y<=K) count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
n = int(input())
for a in range(1,3501):
    for b in range(a,3501):
        if 4/n <= 1/a + 1/b:
            continue
        if 4/n > 1/a + 2/b:
            break
        c = 1/(4/n - 1/a - 1/b)
        x = int(c)
        if 4/n == 1/a + 1/b + 1/x:
            print(a,b,x)
            exit()
        x = int(c)+1
        if 4/n == 1/a + 1/b + 1/x:
            print(a,b,x)
            exit()

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

int m[100001];

bool a[100001];

int search(int n){
    if(m[n]!=-1) return m[n];
    else if(a[n]) return m[n]=0;
    else  return m[n]=(search(n-1)+search(n-2))%1000000007;
} 

int main(){
    int N;
    int M;
    cin>>N>>M;

    for(int i=0;i<M;i++){
        int x;
        cin>>x;
        a[x]=true;
    }


    m[0]=1;
    if(a[1]) m[1]=0; else m[1]=1;
    for(int i=2;i<100001;i++) m[i]=-1;

    int x=search(N);

    //for(int i=0;i<=N;i++) cout<<m[i]<<' ';
    //cout<<endl;

    cout<<m[N]<<endl;

}


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

import sys

def gcd(aa,bb):
    aa, bb = max(aa,bb), min(aa,bb)
    while bb!=0:
        aa,bb=bb,aa%bb
    return aa

def f(n,m):
    nm = n % m
    if nm==0: return n
    else: return n + m - nm
#
a,b,c,d = [ int(x) for x in sys.stdin.readline().split() ]
cd = c * d // gcd(c,d)

# nc
aa = f(a,c)
if aa>b: nc=0
else: nc= (b-aa)//c + 1

# nd
aa = f(a,d)
if aa>b: nd=0
else: nd= (b-aa)//d + 1

# ncd
aa = f(a,cd)
if aa>b: ncd= 0
else: ncd= (b-aa)//cd + 1
#
print( b-a+1 - ( nc + nd - ncd ) )


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()

using namespace std;


int main(){
	// freopen("input.text" , "r" , stdin);
	// freopen("output.text" , "w" , stdout);

	int x ; cin >> x;
	int ans = 0;
	if(x >= 400 && x <= 599)ans = 8;
	if(x >= 600 && x <= 799)ans = 7;
	if(x >= 800 && x <= 999)ans = 6;
	if(x >= 1000 && x <= 1199)ans = 5;
	if(x >= 1200 && x <= 1399)ans = 4;
	if(x >= 1400 && x <= 1599)ans = 3;
	if(x >= 1600 && x <= 1799)ans = 2;
	if(x >= 1800 && x <= 1999)ans = 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
import java.util.*

data class Tuple(val cnt: Int, val kind: Int): Comparable<Tuple> {
    override fun compareTo(other: Tuple): Int =
        -cnt.compareTo(other.cnt).let {
            if (it == 0) kind.compareTo(other.kind) else it
        }
}

fun main(args: Array<String>) = IO().exec {
    val k = int()
    val t = int()
    val a = Array(t){Tuple(int(), it)}
    val heap = PriorityQueue<Tuple>()
    heap.addAll(a)
    while (true) {
        if (heap.size < 2) break
        val item = heap.poll()!!
        val item2 = heap.poll()!!
        if (item.cnt >= 2) heap.offer(item.copy(cnt = item.cnt - 1))
        if (item2.cnt >= 2) heap.offer(item2.copy(cnt = item2.cnt - 1))
    }
    println(heap.poll()?.let { tpl -> tpl.cnt-1 } ?: 0)
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 33740
#include <iostream>
#include <cmath>

using namespace std;

int A[100002];
int F[100002];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    F[1] = 0;
    F[2] = (int) abs(A[2] - A[1]);
    for (int i = 3; i <= n; ++i) {
        int min = F[i-1] + abs(A[i] - A[i-1]);
        for (int j = 2; j <= k; ++j) {
            int a = max(1, i - j);
            int x = F[a] + abs(A[i] - A[a]);
            if (x < min) {
                min = x;
            } 
        }
        F[i] = min;
    }
    cout << F[n];
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k, x;
	cin >> n >> k;
	ll ans = 0;
	rep(i,n){
		cin >> x;
		ans += min(x, k - x) * 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import *
n = int(input())
A = [*map(int, input().split())]
B = [*map(int, input().split())]
C = [*map(int, input().split())]
A.sort()
C.sort()
# B.sort()
ans = 0
for b in B:
    ia = bisect_left(A, b)
    ic = bisect_right(C, b)
    # print('b:{:3d} ia:{:2d} ic:{:2d} ia*ic={:4d}'.format(b,ia,ic,ia*ic))
    # print('b:{:3d} ia:{:2d} ic:{:2d} ia*(n-ic)={:4d}'.format(b,ia,ic,ia*(n-ic)))
    ans += ia * (n-ic)
print(ans)


Measured memory_bytes: 29516
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();

		int dx = tx-sx;
		int dy = ty-sy;

		f1(dx, dy);
		f2(dx, dy);

		System.out.print("L");
		System.out.print("U");
		f1(dx, dy);
		System.out.print("R");
		System.out.print("D");

		System.out.print("R");
		System.out.print("D");
		f2(dx, dy);
		System.out.print("L");
		System.out.print("U");

		System.out.println();
		sc.close();
	}


	private void f1(int dx, int dy) {
		for(int i=0; i<dy; i++) {
			System.out.print("U");
		}
		for(int i=0; i<dx; i++) {
			System.out.print("R");
		}
	}

	private void f2(int dx, int dy) {
		for(int i=0; i<dy; i++) {
			System.out.print("D");
		}
		for(int i=0; i<dx; i++) {
			System.out.print("L");
		}
	}
}


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

typedef long long ll;

const int Maxn = 105;
const ll Inf = 9000000000000000007ll;

int n;
vector <int> neigh[Maxn];
int mxL;
ll dp[Maxn][Maxn];
ll global[Maxn];
ll res = Inf;
ll cand;
int best = Maxn;

void Clear()
{
	mxL = 0;
	fill((ll*)dp, (ll*)dp + Maxn * Maxn, 0);
	cand = 0;
}

void Level(int v, int p, int lvl)
{
	mxL = max(mxL, lvl);
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == p) continue;
		Level(u, v, lvl + 1);
	}
}

void Solve(int v, int p, int lvl)
{
	dp[v][lvl] = 1;
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == p) continue;
		Solve(u, v, lvl + 1);
		for (int j = lvl + 1; j <= mxL; j++)
			dp[v][j] = max(dp[v][j], dp[u][j]);
	}
	int has = int(neigh[v].size()) - (p != 0);
	if (has) dp[v][lvl + 1] = has;
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == p) continue;
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		neigh[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) {
		Clear();
		Level(i, 0, 1);
		Solve(i, 0, 1);
		cand = 1;
		for (int j = 1; j <= mxL; j++)
			cand *= dp[i][j];
		if (mxL < best || mxL == best && cand < res) {
			best = mxL; res = cand;
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < neigh[i].size(); j++) {
			int u = neigh[i][j];
			if (i < u) {
				Clear();
				Level(i, u, 1); Level(u, i, 1);
				Solve(i, u, 1); Solve(u, i, 1);
				for (int k = 1; k <= mxL; k++)
					global[k] = max(dp[i][k], dp[u][k]);
				global[1] = 2;
				cand = 1;
				for (int k = 1; k <= mxL; k++)
					cand *= global[k];
				if (mxL < best || mxL == best && cand < res) {
					best = mxL; res = cand;
				}
			}
		}
	cout << best << " " << res << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
class Main{
  public static void main(String args[]){
    boolean flag = true;
    int tmp;
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int Array [] = new int[n];
    //input
    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }
    //bubblesort
    while(flag){
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    }
    for(int i = 0; i<n-1; i++)System.out.printf("%d ",Array[i]);
    System.out.println(Array[n-1]);
    System.out.println(count);
  }
}


Measured memory_bytes: 26392
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 2100000000
#define MOD 1000000007

int main(){
  vector<ll> a(7);
  for(int i=0;i<7;i++){
    cin>>a.at(i);
  }
  ll ans=0;
  ll x=a.at(0)%2+a.at(3)%2+a.at(4)%2;
  if(x==3){
    a.at(0)--;
    a.at(3)--;
    a.at(4)--;
    ans+=3;
  }else if(x==2){
    if(a.at(0)>0&&a.at(3)>0&&a.at(4)>0){
      a.at(0)--;
      a.at(3)--;
      a.at(4)--;
      ans+=3;
    }
  }
  ans+=a.at(1);
  ans+=(a.at(0)/2)*2;
  ans+=(a.at(3)/2)*2;
  ans+=(a.at(4)/2)*2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256