akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
//typedef __int128_t Int;
#define DBG 1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define loop(n) rep(loop,(0),(n))
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int f(int x){
  int ret=0;
  while(x){
    ret+=x%10;
    x/=10;
  }
  return ret;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(12);

  int N; cin >> N;
  
  int ans=INF;
  rep(i,1,N){
    chmin(ans,f(i)+f(N-i));
  }
  cout<<ans<<endl;

    return 0;
}


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

using namespace std;

using ll = long long;

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

    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b)) cout << "A\n";
    else cout << "B\n";

    return 0;
}


Measured memory_bytes: 256
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

S = list(input())
T = list(input())

S.sort()
T.sort(reverse=True)
for s, t in zip(S, T):
    if ord(s) < ord(t):
        # print(ord(s), ord(t))
        print("Yes")
        exit()
    elif ord(s) > ord(t):
        # print(ord(s), ord(t))
        print("No")
        exit()
else:
    if len(S) < len(T):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 65424
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int Q; scanf("%d\n", &Q);
    long X = 0;
    foreach (i; 0 .. Q) {
        char C; int N; scanf("%*d %c %d\n", &C, &N);
        X += (C == '(' ? 1 : -1) * N;
        writeln(X == 0 ? "Yes" : "No");
    }
}

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

using namespace std;
const int MXN = 1e5 + 5;

int h[MXN];
int dp[MXN];

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i++){
        scanf("%d",&h[i]);
    }
    fill(dp , dp + MXN , (int)1e9 + 7);
    dp[1] = 0;
    for(int i = 2 ; i <= n ; i++){
        for(int j = i - 1 ; j >= i - 2 ; j--){
            dp[i] = min(dp[i] , dp[j] + abs(h[i] - h[j]));
        }
    }
    // for(int i = 1 ; i <= n ; i++){
    //     printf("%d ",dp[i]);
    // }
    printf("%d",dp[n]);
}

Measured memory_bytes: 1024
import math
a, b, c = map(int, input().split())
c = math.radians(c)
S = 1 / 2 * (a * b * math.sin(c))
c2 = math.sqrt(a*a + b*b - 2*a*b*math.cos(c))
H = a + b + c2
h = b * math.sin(c)
print(S,H,h)



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

typedef long long LL;

int main(void){
    int n;
    cin >> n;
    int cnt = 0,ans = 0;
    for(int i = 1;i <= n;i+=2){
        cnt = 0;
        for(int j = i;j >= 1;j-=2){
            if(i%j==0)cnt++;
        }
        if(cnt == 8)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(map(int,input().split())))

res = []
for i in range(h):
    for j in range(w-1):
        if a[i][j] % 2 == 1:
            a[i][j+1] += 1
            res.append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))

for i in range(h-1):
    if a[i][w-1] % 2 == 1:
        a[i+1][w-1] += 1
        res.append(str(i+1)+" "+str(w)+" "+str(i+2)+" "+str(w))

print(len(res))
print("\n".join(res))

Measured memory_bytes: 20120
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;

char ans[30];
int main(){
    //input
    char s[30];
    scanf("%s", s);

    //solve
    int n = strlen(s);
    bool ch[30] = {0};
    rep(i, n) ch[s[i] - 'a'] = true;
    if(n == 26){
        if(strcmp(s, "zyxwvutsrqponmlkjihgfedcba") == 0){
                puts("-1");
                return 0;
        }else{
                int tmp = n-1;
                for(; tmp > 0; tmp--) 
                    if(s[tmp-1] < s[tmp]) break;
                char c = 'z'+1;
                for(int i = tmp; i < n; i++){
                    if(s[tmp-1] < s[i]) c = min(c, s[i]);
                }
                strncpy(ans, s, tmp-1);
                ans[tmp-1] = c;
        }
    }else{
        strcpy(ans, s);
        rep(i, 26){
            if(!ch[i]) {
                ans[n] = 'a' + i;
                break;
            }
        }
    }

    //output
    printf("%s\n", ans);
}

Measured memory_bytes: 1664
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
#include <cctype>

using namespace std;

int main()
{
	char a[100], b[100];
	int A = 0, B = 0;
	int n;


	cin >> n;
	for (int j = 0; j < n; j++) {
		cin >> a >> b;
		if (strcmp(a, b) == 0) {
			A++;
			B++;
		} else if (strcmp(a, b) < 0) {
			B += 3;
		} else {
			A += 3;
		}
	}
	cout << A << " " << B <<endl;
	return (0);
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;
const ll MOD=998244353;
const double pi=3.1415926;
ll n,a[MAXN],dp[MAXN][2],sum;
void solve()
{
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<n;i++)
    {
        dp[i][0]=dp[i-1][0];
        dp[i][1]=dp[i-1][0]-(2*a[i]+2*a[i+1]);
        if(i>1)
        {
            dp[i][0]=max(dp[i][0],dp[i-1][1]);
            dp[i][1]=max(dp[i][1],dp[i-1][1]-(-2*a[i]+2*a[i+1]));
        }

    }
    printf("%lld\n",sum+max(dp[n-1][0],dp[n-1][1]));
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);

    while(~scanf("%lld",&n))
    {
        sum=0;
//        string str;
//        cin>>str;
//        cout<<str<<endl;
        for(ll i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
        }
        solve();
    }
}
/*
100
3
1 1
1
4
1 1 1
1 1
1
*/


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,k;
int a[25],b[25];

int main(){
  scanf("%d%d%d",&n,&m,&k);
  REP(i,n)scanf("%d",a+i);
  REP(i,n)scanf("%d",b+i);
  int ans = 0;
  REP(msk,1<<n){
    int cnt = __builtin_popcount(msk);
    if(cnt > k)continue;
    vector<pii> cand;
    REP(i,n)if((msk>>i)&1)cand.push_back(pii(a[i],b[i]));
    sort(ALL(cand));
    reverse(ALL(cand));
    int tmp = 0;
    int rest = m;
    REP(i,cand.size()){
      int use = min(rest,cand[i].second);
      rest -= use;
      tmp += use*cand[i].first;
    }
    CHMAX(ans,tmp+rest);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long l = in.nextLong();
        long r = in.nextLong();
        long min = Long.MAX_VALUE;
        long r1 = Math.min(r, l+2019);
        for(long i=l; i<=r1; i++) {
            long r2 = Math.min(r, i+2019);
            for(long j=i+1; j<=r2; j++) {
                long mod = (i*j)%2019;
                min = Math.min(min, mod);
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 22740
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

primes = sieve(50000)
ret = [0] * 50001
for i in xrange(len(primes)):
    for j in xrange(i, len(primes)):
        tmp = primes[i] + primes[j]
        if tmp > 50000:
            break
        ret[tmp] += 1
while 1:
    n = int(raw_input())
    if n == 0:
        break
    print ret[n]

Measured memory_bytes: 4984
import numpy

N = int(input())

a = list(map(int, input().split()))

b = [0 for i in range(N)]

ans = []

# print(a)

l = N//2

for i in range(l+1, N+1):
    b[i-1] = a[i-1]
    if a[i-1] == 1:
        ans.append(i)

ind = l
for _ in range(l):
    # print("ind" , str(ind))
    # print("b")
    # print(b)
    ai = a[ind - 1]
    iter = N // ind - 1
    s = 0
    for j in range(1, iter+1):
        s += b[ind + j * ind - 1]
    # print("s = " + str(s))
    if (s % 2) == ai:
        b[ind - 1] = 0
    else:
        b[ind - 1] = 1
        ans.append(ind)

    if ind == 1:
        break
    else:
        ind -= 1
# print("b")
# print(b)
m = sum(b)
# print("m")
print(m)

if m != 0:
    for c in ans:
        print(c, end =" ")


Measured memory_bytes: 21020
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>

using namespace std;

typedef long long ll;

int a[1005];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 2 * n; ++i) {
		cin >> a[i];
	}
	sort(a + 1, a + 2 * n + 1);
	int ans = 0;
	for (int i = 1; i <= 2 * n; i += 2) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int n, a, b;
  cin >> n >> a >> b;
  if(n*a<b){cout<< n*a <<endl;}
  //else if(a==c){cout<< b <<endl;}
  else{cout << b << endl;}
 
  return 0;
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int D[100000];

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

  int N;
  cin >> N;
  REP(i, N) { cin >> D[i]; }

  sort(D, D + N);
  int idx = N / 2;
  int ans = D[idx] - D[idx - 1];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s, max_x, LEN):
  if LEN == n:
    print(s)
  else:
    for c in a[:a.index(max_x)+2]:
      dfs(s+c, max(max_x,c), LEN+1)
dfs("a", "a", 1)

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

vector<ll> to[200005];
vector<ll> ans;

void dfs(ll v, ll p=-1) {
    for (ll u : to[v]) {
        if (u == p) {
            continue;
        }
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, Q;
    cin >> N >> Q;

    rep (i, N-1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;

        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans.resize(N);

    rep (i, Q) {
        ll p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);

    rep (i, N) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t>>x>>y;
        if(!(x+y<=t&&(t-x-y)%2==0)){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

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

int main(){
  double h,a;
  cin >> h >> a;
  cout << ceil(h/a) << endl;
}

Measured memory_bytes: 3788
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

ll H, W;



int main(int argc, char* argv[])
{
  ll N;
  std::cin >> W >> H >> N;

  ll min_x = 0;
  ll max_x = W;
  ll min_y = 0;
  ll max_y = H;
  for (ll i = 0; i < N; i++) {
    ll x, y, a;
    std::cin >> x >> y >> a;
    if (a == 1) {
      min_x = std::max(min_x, x);
    } else if (a == 2) {
      max_x = std::min(max_x, x);
    } else if (a == 3) {
      min_y = std::max(min_y, y);
    } else {
      max_y = std::min(max_y, y);
    }
  }

  // Result
  ll ans = std::max(0LL, (max_x - min_x)) * std::max(0LL, (max_y - min_y));
  std::cout << ans << std::endl;

  return 0;
}


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

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

  vector<pair<int, int>> s_c(m);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s_c[i] = make_pair(s, c);
  }

  int num = 0;
  while (num < 1000) {
    string str_num = to_string(num);
    if (str_num.length() != n) {
      num++;
      continue;
    }

    bool okay = true;
    for (int i = 0; i < m; i++) {
      int digit = str_num[s_c[i].first - 1] - 0x30;
      if (digit != s_c[i].second) okay = false;
    }

    if (okay) {
      cout << num << endl;
      return 0;
    }

    num ++;
  }

  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  if (N % 2 != 0)
  {
    cout << "No" << endl;
    return 0;
  }
  if (S.substr(0, N / 2) == S.substr(N / 2, N / 2))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3016
import java.util.Comparator;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Arrays;
	/* static int java.util.Arrays.binarySearch(int[] a, int key); */
import java.math.BigDecimal;
	
 
 
class Main {
	Scanner sc = new Scanner(System.in);
	int a, b;
	public void run(){
		a = sc.nextInt();
		b = sc.nextInt();
		solve();
	}
	public void solve(){
		int sabun = b - a;
		int ans = 0;
		for(int i = 0; i < sabun; i++){
			ans += i;
		}

		ans -= a;

		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }
	static class Edge{
		int to, cost;
		public Edge(int a, int b){
			this.to = a;
			this.cost = b;
		}
	}
	class MyComparator implements Comparator {
		@Override
		public int compare (Object arg0, Object arg1) {
			int x = ((Pair)arg0).first;
			int y = ((Pair)arg1).first;
			
			if (x < y) {
				return 1;
			} else if (x > y) {
				return -1;
			} else{
				return 0;
			}
		}
	}
	static class UnionFind{
		int par[];
		int rank[];
		
		//n要素で初期化
		public UnionFind(int maxn){
			par = new int[maxn];
			rank = new int[maxn];
			
			for(int i = 0; i < maxn; i++){
				par[i] = i;
				rank[i] = 0;
			}
		}
		
		//木の根を求める
		int find(int x){
			if(par[x] == x){
				return x;
			}
			else {
				return par[x] = find(par[x]);
			}
		}
		
		// xとyの属する集合を併合
		void unite (int x, int y){
			x = find(x);
			y = find(y);
			if(x == y){
				return;
			}
			
			if(rank[x] < rank[y]){
				par[x] = y;
			}
			else{
				par[y] = x;
				if(rank[x] == rank[y]) rank[x]++;
			}
		}
		
		// xとyが同じ集合に属するか否か
		boolean same(int x, int y){
			return find(x) == find(y);
		}
	}
}

Measured memory_bytes: 22868
a, b, c = list(map(int, input().split()))
from math import pi, sin, cos
print(a*b*0.5*sin(c*pi/180))
print(a+b+(a**2+b**2-2*a*b*cos(c*pi/180))**0.5)
print(b*sin(c*pi/180))


Measured memory_bytes: 5716
w, h, n = map(int, input().split())
x = w
y = h
xx = 0
yy = 0
for i in range(n):
    xxx, yyy, a = map(int, input().split())
    if a == 1:
        xx = max(xx, xxx)
    elif a == 2:
        x = min(x, xxx)
    elif a == 3:
        yy = max(yy, yyy)
    elif a == 4:
        y = min(y, yyy)
w = x - xx
h = y - yy
print(0 if w <= 0 or h <= 0 else w * h)


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int K = in.nextInt();
            int H[] = CPUtils.readIntArray(N, in);
            Map<Integer, Integer> memo = new HashMap<>();
            out.print(solve(0, H, K, memo));
        }

        static int solve(int stone, int H[], int K, Map<Integer, Integer> memo)
        {
            if (stone + 1 >= H.length) return 0;
            if (memo.containsKey(stone)) return memo.get(stone);
            int cost = Math.abs(H[stone] - H[stone + 1]) + solve(stone + 1, H, K, memo);
            for (int jumpLen = 2; jumpLen <= K && stone + jumpLen < H.length; jumpLen++)
            {
                cost = Math.min(cost, Math.abs(H[stone] - H[stone + jumpLen]) + solve(stone + jumpLen, H, K, memo));
            }
            memo.put(stone, cost);
            return cost;
        }

    }

    static class CPUtils
    {
        public static int[] readIntArray(int size, Scanner in)
        {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = in.nextInt();
            }
            return array;
        }

    }
}



Measured memory_bytes: 176156
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>
#include<cmath>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define lint long long

vector<int> to[200001];
bool seen[200001];
int ans;

void dfs(int s){
    if(seen[s]) return;
    seen[s] = true;
    for(auto& x : to[s]){
        dfs(x);
    }
}

int main(){
    int n, k; cin >> n >> k;
    vector<int> p;
    vector<int> index(200001);
    rep(i, n) {int x; cin>>x; p.push_back(x); index[x] = i; }

    vector<int> sorted;
    int j = 1;
    rep(i, n-1){
        if(p[i] < p[i+1]){
            j++;
        }
        else{
            j = 1;
        }
        if(j >= k){
            if(!sorted.empty()){
                to[sorted.back()].push_back(i-k+2);
                to[i-k+2].push_back(sorted.back());
            }
            sorted.push_back(i-k+2);
        }
    }

    set<int> first, last;
    rep(i, k){
        first.insert(p[i]);
        last.insert(-p[i]);
    }
    rep(i, n-k){
        last.insert(-p[i+k]);
        while(true){
            if(index[-(*last.begin())] <= i){
                last.erase(last.begin());
            }
            else break;
        }

        if(*first.begin() == p[i] && *last.begin() == -p[i+k]){
            to[i].push_back(i+1);
            to[i+1].push_back(i);
        }
        
        first.insert(p[i+k]);
        while(true){
            if(index[*first.begin()] <= i){
                first.erase(first.begin());
            }
            else break;
        }
    }

    rep(i,n-k+1){
        if(!seen[i]){
            ans += 1;
            dfs(i);
        }
    }
    cout<<ans<<endl;
}

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

#define int long long
#define INF 1e18+5

vector<int> w(1009);
vector<int> s(1009);
vector<int> v(1009);

vector< int > dp(20009);

bool comp(int a, int b){
    return s[a] + w[a] > s[b] + w[b];
}

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

    vector<int> elements(n);

    for(int i = 0; i < n; i++){
        elements[i] = i;
        cin >> w[i] >> s[i] >> v[i];
    }

    sort(elements.begin(), elements.end(), comp);

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

        int i = elements[j];

        for(int k = w[i]; k < 20009; k++){

            dp[min(k-w[i],s[i])] = max(dp[min(k-w[i], s[i])], dp[k]+v[i]);

        }
    }

    int ans = 0;

    for(int i = 0; i < 10009; i++){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
# 169A
#　1．入力をちゃんと受け取ること
# ex:「2 5」=>a=2,b=5と変数を作成する
# スペース区切りの入力を整数として受け取る例
a, b = map(int, input().split())
# print(a)
# print(b)

# 2．目的通りの計算をする
# ex:2つの整数AとBの掛け算をやる
answer = a * b

# 3.計算結果を出力する
print(answer)

Measured memory_bytes: 9028
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100007];
int n,ans;
struct pp
{
	int num,tot;
};
pp b1[100009],b2[100009];
bool cmp(pp a,pp b)
{
	return a.tot>b.tot;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n-1;i+=2) b1[a[i]].tot++;
	for(int i=2;i<=n;i+=2) b2[a[i]].tot++;
	for(int i=1;i<=100003;i++) b1[i].num=b2[i].num=i;
	sort(b1+1,b1+100003,cmp);
	sort(b2+1,b2+100003,cmp);
	if(b1[1].num!=b2[1].num) ans=n-b1[1].tot-b2[1].tot;
	else ans=min(n-b1[1].tot-b2[2].tot,n-b2[1].tot-b1[2].tot);
	//cout<<b1[1].tot<<' '<<b1[2].tot<<' '<<b1[1].num<<' '<<b1[2].num;
	//cout<<max11<<' '<<max12<<' '<<max21<<' '<<max22;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2176
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			// solveB();
			// solveC();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int alice = nextInt();
		int bob = nextInt();

		if (alice == bob) {
			out.println("Draw");
		} else if (alice == 1) {
			out.println("Alice");
		} else if (bob == 1) {
			out.println("Bob");
		} else if (alice != bob) {
			out.println(alice > bob ? "Alice" : "Bob");
		}

		out.println("");
	}

	private void solveB() {
		int numN = nextInt();

		out.println("");
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21204
n = int(input())
L,R = [0]*n,[0]*n
for i in range(n):
    L[i],R[i] = map(int,input().split())
    R[i] += 1

M = L.index(max(L))
m = R.index(min(R))

d = [R[i] - L[i] if M != i != m else 0 for i in range(n)]
ans = max(d) + max(R[m] - L[M], 0)
d[m] = R[m] - L[m]
d[M] = R[M] - L[M]
if m == M:
    print(ans)
    exit()
if n == 2:
    print(d[m] + d[M])
    exit()
a,b = [0]*(n-2),[0]*(n-2)
j = 0
for i in range(n):
    if m != i != M:
        a[j],b[j] = max(R[i]-L[M],0) , max(R[m]-L[i],0)
        j += 1
ab = sorted(list(zip(a,b)),reverse = True)
mb = [0]*len(a)
for i in range(len(a))[::-1]:
    if i == len(a)-1:
        mb[i] = ab[i][1]
    else:
        mb[i] = min(ab[i][1], mb[i+1])
for i in range(len(a) - 1):
    ans = max(ans,min(ab[i][0],d[M]) + min(mb[i + 1],d[m]))
ans = max(ans , d[M] + min(mb[0], d[m]), min(ab[len(a)-1][0],d[M]) + d[m])

print(ans)


Measured memory_bytes: 59480
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int w, h;

  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    int mp[55][55];
    bool used[55][55];

    queue<pair<int, int>> que;
    rep(y, h) {
      rep(x, w) {
        cin >> mp[y][x];
        if (mp[y][x] == 0)
          used[y][x] = false;
        else
          used[y][x] = true;
      }
    }

    int ans = 0;

    rep(y, h) {
      rep(x, w) {
        if (used[y][x]) {
          ans++;
          que.push(make_pair(x, y));
          while (!que.empty()) {
            pair<int, int> p = que.front();
            que.pop();

            rep(i, 8) {
              int nx = p.first + ddx[i];
              int ny = p.second + ddy[i];
              if (0 <= nx && nx < w && 0 <= ny && ny < h && used[ny][nx]) {
                used[ny][nx] = false;
                que.push(make_pair(nx, ny));
              }
            }
          }
        }
      }
    }

    cout << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(c<=a+b){
        cout<<"Yes"<<endl;
    } else{
        cout<<"No"<<endl;
    }
    return 0;
    
}


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

#ifdef LOCAL
  #include <contest/local.hpp>
#else
  #define LOG(...) do {} while (false)
#endif

#define REP(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) (x).begin (), (x).end ()

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int n;
  cin >> n;

  vector <int> v;

  REP (i, n)
  {
    int a;
    cin >> a;
    v.push_back (move (a));
  }

  auto max_i = max_element (ALL (v));
  auto max_v = * max_i;
  auto semi = 0;

  if (max_i == v.begin ())
  {
    semi = * max_element (v.begin () + 1, v.end ());
  }
  else if (max_i == v.end ())
  {
    semi = * max_element (v.begin (), v.end () - 1);
  }
  else
  {
    semi = max (* max_element (v.begin (), max_i), * max_element (max_i + 1, v.end ()));
  }

  for (auto ite = v.begin (); ite != v.end (); ++ ite)
  {
    cout << (ite == max_i ? semi : max_v) << endl;
  }
}



Measured memory_bytes: 2548
#include <iostream>
using namespace std;
int a[1000000];
int main(){
    int b,c,d=0;
    cin>>a[0];
    for(b=1;b<1000000;b++){
        if(a[b-1]%2==0){
            a[b]=a[b-1]/2;
        }
        else{
            a[b]=3*a[b-1]+1;
        }
        for(c=0;c<b;c++){
            if(a[c]==a[b]){
                cout<<b+1;
                d=1;
                break;
            }
        }
        if(d==1){
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 205000;

int n;
int a[MAXN], b[MAXN];
vector<int> v;
long long ans;

int main() { 

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

  int diff = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      diff++;
    }
    if (a[i] <= b[i]) {
      ans += b[i];
    } else {
      v.push_back(b[i]);
    }
  }

  sort(all(v));
  reverse(all(v));
  for (int i = 0; i + 1 < sz(v); i++) {
    ans += v[i];
  }

  if (diff == 0) {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int suml[2020][2020];
int sumr[2020][2020];
int sumu[2020][2020];
int sumd[2020][2020];
int main(){
	int h, w;
	cin >> h >> w;
	vector<string>mp(h);
	rep(i, 0, h)cin >> mp[i];

	rep(i, 0, h)rep(j, 0, w) {
		if (j == 0) {
			suml[i][j] = (mp[i][j] == '#') ? 0 : 1;
		}
		else {
			if (mp[i][j] == '#') {
				suml[i][j] = 0;
			}
			else {
				suml[i][j] = suml[i][j-1] + 1;
			}
		}
	}
	rep(j, 0, w)rep(i, 0, h) {
		if (i == 0) {
			sumu[i][j] = (mp[i][j] == '#') ? 0 : 1;
		}
		else {
			if (mp[i][j] == '#') {
				sumu[i][j] = 0;
			}
			else {
				sumu[i][j] = sumu[i-1][j] + 1;
			}
		}
	}

	rep(i, 0, h)rrep(j, w - 1, 0) {
		if (j == w-1) {
			sumr[i][j] = (mp[i][j] == '#') ? 0 : 1;
		}
		else {
			if (mp[i][j] == '#') {
				sumr[i][j] = 0;
			}
			else {
				sumr[i][j] = sumr[i][j+1] + 1;
			}
		}
	}
	rep(j, 0, w)rrep(i,h-1,0) {
		if (i == h - 1) {
			sumd[i][j] = (mp[i][j] == '#') ? 0 : 1;
		}
		else {
			if (mp[i][j] == '#') {
				sumd[i][j] = 0;
			}
			else {
				sumd[i][j] = sumd[i+1][j] + 1;
			}
		}
	}

	

	int ans = 0;
	rep(i, 0, h)rep(j, 0, w) {
		if (mp[i][j] != '#') {
			int n1 = (i == 0) ? 0 : sumu[i - 1][j];
			int n2 = (j == 0) ? 0 : suml[i][j - 1];
			int n3 = (i == h - 1) ? 0 : sumd[i + 1][j];
			int n4 = (j == w - 1) ? 0 : sumr[i][j + 1];
			ans = max(ans, n1 + n2 + n3 + n4 + 1);
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 67968
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
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
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, m := scanInt(), scanInt()
	g := make([][]int, n)
	for i := 0; i < m; i++ {
		s, t := scanInt()-1, scanInt()-1
		g[s] = append(g[s], t)
	}

	memo := make([]float64, n)
	var p int
	var dfs func(v int) float64
	dfs = func(v int) float64 {
		if v == n-1 || memo[v] > 0 {
			return memo[v]
		}

		t := 0.0
		for _, nv := range g[v] {
			a := dfs(nv)
			if p == v {
				t = math.Max(a, t)
			}
			memo[v] += a
		}

		e := len(g[v])
		if p == v {
			memo[v] -= t
			e--
		}

		memo[v] /= float64(e)
		memo[v] += 1.0

		return memo[v]
	}

	ans := math.MaxFloat64
	for p = 0; p < n; p++ {
		if len(g[p]) == 1 {
			continue
		}
		memo = make([]float64, n)
		ans = math.Min(ans, dfs(0))
	}

	fmt.Fprintln(wr, ans)

}


Measured memory_bytes: 5504
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x+r<=W){
        if(x-r>=0){
            if(y+r<=H){
                if(y-r>=0){
                    cout<<"Yes"<<endl;
                }else{
                    cout<<"No"<<endl;
                }
                
            }else{
                cout<<"No"<<endl;
                }
        }else{
                cout<<"No"<<endl;
            }
    }else{
            cout<<"No"<<endl;
    }
    return 0;
}


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

struct Puddle{
	int start, end, area;
};

int main(){
	string str;
	cin >> str;
	int n = str.size(), overall = 0;
	stack<Puddle> S;
	stack<int> slope;

	for(int i = 0; i < n; i++){
		if(str[i] == '\\'){
			slope.push(i);
		} else if(str[i] == '/'){
			if(!slope.empty()){
				Puddle temp;
				temp.start = slope.top();
				slope.pop();
				temp.end = i;
				temp.area = (temp.end - temp.start);
				overall += temp.area;
				while( !S.empty() ){
					if(temp.start < S.top().start){
						temp.area += S.top().area;
						S.pop();
					} else {
						break;
					}
				}
				S.push(temp);
			}
		}
	}
	cout << overall << endl;
	int m = S.size(), A[m];
	cout << m;
	for(int i = 0; i < m; i++){
		A[m - i - 1] = S.top().area;
		S.pop();
	}
	for(int i = 0; i < m; i++)
		cout << " " << A[i];
	cout << endl;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll MOD = 1e9+7;
vector < P > pairs;
 
#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)
#define ALL(c) (c).begin(), (c).end()
 
// pair (降順, 降順)
bool compare_pair(P a, P b) {
    if (a.first > b.first) return true;//firstが先に書いてあるからfirst基準ソート
    if (a.first < b.first) return false;
    if (a.second > b.second) return true;//今は降順、true falseひっくり返せば降順、昇順切り替え
    if (a.second < b.second) return false;
    return false;
}
int main(){
    int day ,ans;
    string s;
    string days[7]={ "SUN","MON","TUE","WED","THU","FRI","SAT" };
    cin >> s;
    rep(i,0,7){

        if(days[i] == s){
            day = i;
            break;
        }
    }
    ans = 7 - day ;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

main = do
    [n, m] <- getPairs 
    ab_s <- replicateM m getPairs
    let points = mconcat ab_s
    mapM_ print $ map (\z -> length $ filter (== z) points) [1 .. n]

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

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

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    
    if(A >= 13){
        cout << B << endl;
    }
    else if(A >= 6){
        cout << B / 2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

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

int main(){
  int N, K;
  cin >> N >> K;
  double prob=0;
  for(int i=1; i<=N; i++){
    double p = 1.0/N;
    int score = i;
    while(score<K){
      score *= 2;
      p *= 0.5;
    }
    prob+=p;
  }
  printf("%0.9lf\n",prob);
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))


ans_list = []
for k in range (0,N+1):
    A1_sum = 0
    A2_sum = 0
    for i in range(0,N):
        if i <= k-1:
            A1_sum += A1[i]
    for i in range(0,N):
        if i >= k-1:
            A2_sum += A2[i]
    ans = A1_sum + A2_sum
    ans_list.append(ans)

print(max(ans_list))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define pb push_back
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define all(s) s.begin(),s.end()
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define _max(v) *max_element(v.begin(), v.end())
#define _min(v) *min_element(v.begin(), v.end())
#define ms(s, n) memset(s, n, sizeof(s))
ll raised(ll x,  ll y){ll res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
ll raisedmod(ll x, ll y, ll p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a % b);} 
ll fact(ll n){ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; } 
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r));} 


int main() 
{
    io;
    ll t; //cin >> t;
    t=1;
    while(t--)
    {
        ll n, a, b, count=0, f=0;
        cin>>n;
      rep(i, 0, n)
      {
          cin >> a>> b; if(a==b) {count++; if(count>=3) {f=1;}} else {count=0;}
          //cout<< count<< endl;
      }
      if(f==1) cout<< "Yes\n";
      else cout<< "No\n";
    }
	return 0;
}


Measured memory_bytes: 3688
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include "bitset"
#include "cmath"
#include "list"
#include "complex"
#include <cassert>
#include "deque"
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++) 
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
//#define mp make_pair
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vc visit(sze, false);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

int dp[2][sze];

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

	cin >> n >> m;
	int f = 0, s = 1;

	for (int j = 0; j < sze; j++)
	{
		dp[f][j] = oo;
		dp[s][j] = oo;
	}

	dp[0][0] = 0;

	for (int i = 0; i < n; i++)
	{
		int w, c;
		cin >> w >> c;

		for (int j = 0; j < sze; j++)
		{
			mini(dp[s][j], dp[f][j]);
			if (j >= c)
			{
				mini(dp[s][j], dp[f][j - c] + w);
			}
		}

		for (int j = 0; j < sze; j++)
		{
			dp[f][j] = oo;
		}

		swap(f, s);
	}
	
	int ans = 0;

	for (int i = sze-1; i >= 0; i--)
	{
		if (dp[f][i] <= m)
		{
			cout << i;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 14976
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort(reverse=True)

if n % 2 == 0:
    res = 0
    for i in range(n // 2 - 1):
        res += a[i] * 2
    res += a[n // 2 - 1]
    res -= a[n // 2]
    for i in range(n // 2 + 1, n):
        res -= a[i] * 2
    print(res)
else:
    res1 = 0
    for i in range(n // 2 - 1):
        res1 += a[i] * 2
    res1 += a[n // 2 - 1] + a[n // 2]
    for i in range(n // 2 + 1, n):
        res1 -= a[i] * 2

    res2 = 0
    for i in range(n // 2):
        res2 += a[i] * 2
    res2 -= a[n // 2] + a[n // 2 + 1]
    for i in range(n // 2 + 2, n):
        res2 -= a[i] * 2
    print(max(res1, res2))

Measured memory_bytes: 7492
#!usr/bin/env python3

import sys
from math import pi


def area_of_circle(radius):
    return pi * radius**2


def circumference_of_circle(radius):
    return 2*pi*radius


def main():
    # NOTE Tried sys.stdin.readline() instead of input()
    r = float(sys.stdin.readline())
    print('%f %f' % (area_of_circle(r), circumference_of_circle(r)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
const int N=15;
int n,m,tot_v,sval[1<<N],fir[N],val[N][N],lg2[1<<N];
int dp[1<<N][N];

namespace utils{
	inline int nxi(FILE *fd=stdin){
		int x=0;
		char c;
		while(((c=fgetc(fd))>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=fgetc(fd));
		while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
		return f?-x:x;
	}
	template <class T> inline void apx(T &x,const T y){
		x<y?x=y:0;
	}
	template <class T> inline void apn(T &x,const T y){
		x>y?x=y:0;
	}
}
using namespace utils;

int main(){
	memset(dp,-63,sizeof(dp));
	n=nxi(),m=nxi();
	for(int i=0; i<n; ++i){
		lg2[1<<i]=i;
	}
	for(int i=1; i<=m; ++i){
		const int a=nxi()-1,b=nxi()-1;
		tot_v+=(val[a][b]=val[b][a]=nxi());
	}
	for(int i=1; i<1<<n; ++i){
		int lbit=i&-i,prev=i^lbit;
		sval[i]=sval[prev];
		int x=lg2[lbit];
		for(int j=0; j<n; ++j){
			if(i>>j&1) sval[i]+=val[x][j];
		}
	}
	for(int i=1; i<1<<n; i+=2){
		dp[i][0]=sval[i];
	}
	for(int i=1; i<1<<n; ++i){
		for(int j=0; j<n; ++j){
			if((i>>j&1)==0||dp[i][j]<-1e9) continue;
			for(int k=(i+1)|i; k<1<<n; k=(k+1)|i){
				assert((k|i)==k);
				const int res=dp[i][j]+sval[k^i];
				for(int l=k^i,t=l&-l; l; l^=t,t=l&-l){
					const int v=val[j][lg2[t]];
					if(v) apx(dp[k][lg2[t]],res+v);
				}
			}
		}
	}
	printf("%d\n",tot_v-dp[(1<<n)-1][n-1]);
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <string.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15


int main(){

 int n;
 cin>>n;

 string a,b;
 cin>>a>>b;

 long long ans=0;

 if(a == b){
    cout<<n<<endl;
   return 0;
}
else{

    int cnt=0;

    for(int i=0;i<n;i++){
        if(a.substr(n-1-i) == b.substr(0,i+1))
            cnt = i+1;
    }

    ans = n*2 - cnt;
     cout<<ans<<endl;
}


 return 0;
}


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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  n %= 10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
    cout << "hon" << endl;
  }
  else if(n == 0 || n == 1 || n == 6 || n == 8){
    cout << "pon" << endl;
  }
  else if(n == 3){
    cout << "bon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3652