akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define y1 aklsdja
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define pb push_back
#define t top()
#define fr front()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , x) for(int i = 0 ; i < x ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define oo 1e17 + 5
#define ll long long
#define int long long
#define pow poww

const int N = 1e5 + 5;
int n , m , res;
int dp[N];
bool visit[N];
vector < int > g[N];

void DFS(int u)
{
    visit[u] = true;
    REP(s , g[u].size())
    {
        int v = g[u][s];
        if(!visit[v])
            DFS(v);
        dp[u] = max(dp[u] , dp[v] + 1);
    }
    res = max(res , dp[u]);
}

main()
{
    //freopen("G.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    FOR(i , 1 , m)
    {
        int u , v;
        cin >> u >> v;
        g[u].pb(v);
    }
    FOR(i , 1 , n)
        if(!visit[i])
            DFS(i);
    cout << res;
}


Measured memory_bytes: 8704
import bisect
N = int(input())
l = list(map(int, input().split()))
ans = 0
tmp = 0
l.sort()
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        tmp = bisect.bisect_left(l, l[i] + l[j])
        ans += tmp - j - 1

print(ans)


Measured memory_bytes: 3188
# encoding: utf-8

def bubble_sort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in xrange(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
    return A, count

def main():
    N = input()
    A = map(int, raw_input().split())
    A, count = bubble_sort(A, N)
    print " ".join(map(str,A))
    print count

main()

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

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < m; i++) {
    int K;
    cin >> K;
    while (K--) {
      int v;
      cin >> v;
      a[v - 1][i] = 1;
    }
  }
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < 1 << n; i++) {
    vector<int> c(m);
    for (int j = 0; j < n; j++) {
      if ((1 << j) & i) {
        for (int k = 0; k < m; k++) {
          c[k] = (c[k] + a[j][k]) % 2;
        }
      }
    }
    ans += b == c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;


int32_t main(){
	int n , k , s ; cin >> n >> k >> s ;
	int arr[n] ; 
	for(int i=0;i<n;i++){
		if(k){
			arr[i] = s ;
			k--;
		}else{
			if(s!=1000000000) arr[i] = s+1;
			else arr[i] = s-1;
		}
	}
	for(int i : arr) cout << i << ' ';
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
#include <bits/stdc++.h>
int main() {
    int W , H , N;
    cin >> W >> H >> N;
    int l = 0 , r = W , u = H , d = 0;
    rep(i , N){
        int x , y , a;
        cin >> x >> y >> a;
        if(a == 1){
            l = max(l , x);
        }
        if(a == 2){
            r = min(r , x);
        }
        if(a == 3){
            d = max(d , y);
        }
        if(a == 4){
            u = min(u , y);
        }   
    }
    cout << max(0 , r - l) * max(0 , u - d) << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
char a[3][100005];
int main(){
	int n,ans=0;
	scanf("%d%s%s%s",&n,a[0],a[1],a[2]);
	for (int i=0;i<n;i++)
		if (a[0][i]==a[1][i]&&a[1][i]==a[2][i]) ans+=0;
		else if (a[0][i]==a[1][i]||a[0][i]==a[2][i]||a[1][i]==a[2][i]) ans+=1;
		else ans+=2;
	printf("%d\n",ans);
}

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

int main(){
  string S,t;
  long Q;
  cin >> S;
  cin >> Q;
  for(int i=1; i<=Q; i++){
    int T;
    cin >> T;
    if(T==1){
      swap(t,S);
    }
    if(T==2){
      int F;
      string C;
      cin >> F >> C;
      if(F==1){
          t+=C;
      }
      if(F==2){
          S+=C;;
      }
    }
  }
  reverse(t.begin(), t.end());
  t+=S;
  cout << t << endl;
  return 0;
}

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

using namespace std;

const int INF = 1 << 30;

struct Dinic
{
  struct edge
  {
    int to, cap, rev;
    bool alive;
  };

  vector< vector< edge > > graph;
  vector< int > used;

  Dinic(int n)
  {
    graph.resize(n);
  }

  void add_edge(int from, int to, int cap)
  {
    graph[from].push_back((edge) {to, cap, (int) graph[to].size(), true});
    graph[to].push_back((edge) {from, cap, (int) graph[from].size() - 1, true});
  }

  int dfs(int idx, const int t, int flow)
  {
    if(idx == t) return (flow);
    used[idx] = true;
    for(int i = 0; i < graph[idx].size(); i++) {
      edge &e = graph[idx][i];
      if(!e.alive) continue;
      if(e.cap > 0 && !used[e.to]) {
        int d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return (d);
        }
      }
    }
    return (0);
  }

  int max_flow(int s, int t, int lim)
  {
    int flow = 0;
    while(lim > 0) {
      used.assign(graph.size(), 0);
      int f = dfs(s, t, lim);
      if(f == 0) break;
      flow += f;
      lim -= f;
    }
    return (flow);
  }

  bool back_edge(int from, int to)
  {
    for(edge &e : graph[from]) {
      if(e.to == to && e.alive) {
        e.alive = false;
        if(e.cap == 0 && max_flow(from, to, 1) == 0) {
          max_flow(graph.size() - 1, to, 1);
          max_flow(from, 0, 1);
          return (true);
        } else {
          return (false);
        }
      }
    }
  }

};


int main()
{
  int N, E, Q;
  cin >> N >> E >> Q;
  Dinic graph(N);
  while(E--) {
    int F, T;
    cin >> F >> T;
    --F, --T;
    graph.add_edge(F, T, 1);
  }
  int flow = graph.max_flow(0, N - 1, INF);
  while(Q--) {
    int M, A, B;
    cin >> M >> A >> B;
    --A, --B;
    if(M == 1) {
      graph.add_edge(A, B, 1);
      flow += graph.max_flow(0, N - 1, 1);
    } else {
      flow -= graph.back_edge(A, B);
      flow -= graph.back_edge(B, A);
    }
    cout << flow << endl;
  }
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


ll n,w, a[100009], b[100009];
ll dp[109][100009];

// map<int, map<ll, ll> > dp;
 
ll solve(int r, int idx) {
    if(idx == n)
        return r == 0 ? 0 : INT_MAX;

    if(dp[idx][r] != -1)
    	return dp[idx][r];

    ll ans = solve(r, idx + 1);
    if(b[idx] <= r)
    	ans = min(ans, a[idx] + solve(r - b[idx], idx + 1));
     
    return dp[idx][r] = ans;
}

int s(int v_max) {

	for(int i = v_max; i >= 0; i--) {
		if(solve(i, 0) <= w)
			return i;
	}
	return 0;
}
 
int main() {
 
    // int t;
    // cin>>t;
    // while(t--) {
        cin>>n>>w;
        memset(dp, -1, sizeof(dp));

        int v_max = 0;

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

        cout<<s(v_max)<<endl;

}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5+6;
const int M = 998244353;
const int inf = 1e9;
ll iv[N],f1[N],f2[N];
ll nck(int n, int k) {
	return f1[n]*f2[k]%M*f2[n-k]%M;
}
void solve(){
    iv[1]=1;
    for(int i=2; i<N; ++i)
		iv[i]=M-M/i*iv[M%i]%M;
	f1[0]=f2[0]=1;
	for(int i=1; i<N; ++i) {
		f1[i]=f1[i-1]*i%M;
		f2[i]=f2[i-1]*iv[i]%M;
	}
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    ll ans = 0;
    for(ll i=0;i<=n;i++){
        ll kk = k-i*a;
        if(kk<0)continue;
        if(kk%b)continue;
        int j = kk/b;
        if(j>n)continue;
        ans+=nck(n,i)*nck(n,j);
        ans%=M;
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 7296
n = int(input())
a = input()
b = input()
c = input()

count = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        continue
    elif a[i] != b[i]:
        if a[i] == c[i] or b[i] == c[i]:
            count += 1
        else:
            count += 2
    elif b[i] != c[i]:
        if b[i] == a[i] or c[i] == a[i]:
            count += 1
        else:
            count += 2
    elif c[i] != a[i]:
        if c[i] == b[i] or a[i] == b[i]:
            count += 1
        else:
            count += 2
print(count)

Measured memory_bytes: 3064
N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(N)]
 
ab.sort(key = lambda x: x[1], reverse=True)
cd.sort()
 
x = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d:
            x += 1
            ab.remove([a, b])
            break
 
print(x)

Measured memory_bytes: 9212
#include<iostream>
using namespace std;
typedef struct{
  char mark;
  int value;
  int order;
}t;
  
int main(){
  int N,minj,f=0;
  t C1[36],C2[36],a;
  cin>>N;
 
  if(N>0 && N<37){
    for(int i=0;i<=N-1;i++){
      while(1){
      cin>>C1[i].mark;
      if(C1[i].mark!='D'&&C1[i].mark!='C'&&C1[i].mark!='S'&&C1[i].mark!='H')continue;	
      cin>>C1[i].value;
      break;
      }
      C1[i].order=i+1;
      C2[i]=C1[i];
    }
  
    for(int i=0;i<=N-1;i++)
      for(int j=N-1;j>=i+1;j--)
	if(C1[j].value < C1[j-1].value){
	  a=C1[j];
	  C1[j]=C1[j-1];
	  C1[j-1]=a;
	}	
  
    for(int i=0;i<N-1;i++) cout<<C1[i].mark<<C1[i].value<<' ';
    cout<<C1[N-1].mark<<C1[N-1].value<<endl;
  
    for(int i=0;i<=N-1;i++)
      if(C1[i].value==C1[i-1].value && C1[i].order-C1[i-1].order<0)f=1;
  
  if(f==0) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  f=0;
  
  for(int i=0;i<=N-1;i++){
    minj=i;
    for(int j=i;j<=N-1;j++)
      if(C2[j].value < C2[minj].value)minj=j;
    a=C2[i];
    C2[i]=C2[minj];
    C2[minj]=a;
  }
  for(int i=0;i<N-1;i++)cout<<C2[i].mark<<C2[i].value<<' ';
  cout<<C2[N-1].mark<<C2[N-1].value<<endl;
  for(int i=1;i<N;i++)
    if(C2[i].value==C2[i-1].value && C2[i].order-C2[i-1].order<0)f=1;
  if(f==0)cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])
	

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

int main()
{
	int W,H,i,j;
	while(1){
		cin >> W >> H;
		
		if(W == 0 && H == 0) break;
		
		for(i=0 ;i<W ;i++){
			for(j=0 ;j<H ;j++){
			cout << "#";
		}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}
		
		
	

Measured memory_bytes: 1152
n = int((input()))
U, R, D, L = [], [], [], []
for _ in range(n):
    x, y, d = input().split()
    x = int(x)
    y = int(y)
    (U if d == 'U' else R if d == 'R' else D if d == 'D' else L).append((x, y))
INF = 1001001001
ans = INF
def front_crash(u, d):
    global ans
    u.sort()
    d.sort()
    i = 0
    j = 0
    while i < len(u) and j < len(d):
        ut = [u[i][1]]
        while i + 1 < len(u) and u[i][0] == u[i+1][0]:
            i += 1
            ut.append(u[i][1])
        dt = []
        while j < len(d) and d[j][0] < u[i][0]:
            j += 1
        while j < len(d) and d[j][0] == u[i][0]:
            dt.append(d[j][1])
            j += 1
        q = 0
        for y1 in ut:
            while q < len(dt) and dt[q] < y1:
                q += 1
            if q == len(dt):
                break
            y2 = dt[q]
            ans = min(ans, (y2 - y1) * 5)
        i += 1
front_crash(U, D)
front_crash(*(list(map(lambda p: (p[1], p[0]), t)) for t in [R, L]))
from collections import defaultdict
from bisect import bisect_left
def side_crash(u, r):
    global ans
    d = defaultdict(list)
    u.sort()
    for x, y in u:
        d[x+y].append(x)
    for x, y in r:
        dxy = d[x+y]
        i = bisect_left(dxy, x)
        if i < len(dxy):
            ans = min(ans, (dxy[i] - x) * 10)
side_crash(U, R)
side_crash(*([(y, 200000 - x) for x, y in t] for t in [L, U]))
side_crash(*([(200000 - x, 200000 - y) for x, y in t] for t in [D, L]))
side_crash(*([(200000 - y, x) for x, y in t] for t in [R, D]))

print(ans if ans < INF else 'SAFE')

Measured memory_bytes: 166112
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
def main():
    n,k=map(int,input().split())
    h = list(map(int,input().split()))
    h=sorted(h,reverse=True)
    if k > n:
        k=n
    for i in range(k):
        h[i]=0
    print(sum(h))

if __name__ == "__main__":
    main()

Measured memory_bytes: 26820
def C_Candies():
    N=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    count=0
    for i in range(N):
        if count < sum(a[0:i+1])+sum(b[i:N+1]):
            count =sum(a[0:i+1])+sum(b[i:N+1])
    print(count)
C_Candies()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.length()%2==1) {
			System.out.println("No");
			return ;
		}
		for (int i=0;i<s.length();i=i+2) {
			if (!"hi".equals(s.substring(i, i+2))) {
				System.out.println("No");
				return ;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 21716
#include <iostream>
using namespace std;
int main() {
    int a,b,c,d = 0;
    cin >> a>>b >> c >> d;
    for(;;){
        c = c - b;
        if(c <= 0){
            break;
        }
        a = a - d;
        if(a <= 0){
            break;
        }
    }
    if(a > c){
        cout << "Yes";
    } else{
        cout << "No";
    }
    return 0;
}


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

int N;
int coin[12]={59049,46656,7776,6561,1296,729,216,81,36,9,6,1};
int mai[100001];

int main(){
  cin >> N;
  mai[0]=0;
  for(int i=1; i<=N; i++){
    mai[i]=100000;
    for(int j=0; j<12; j++){
      if(i-coin[j]>=0){
        mai[i]=min(mai[i],mai[i-coin[j]]+1);
      }
    }
  }
  cout << mai[N] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, D;
  std::cin >> N >> D;
  vvi data=vv(N, D, 0, int);
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++) std::cin >> data[i][j];
  }
  int dis, count=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      dis=0;
      for(int k=0;k<D;k++){
        dis+=(data[i][k]-data[j][k])*(data[i][k]-data[j][k]);
      }
      for(int k=1;k*k<=dis;k++){
        if(k*k==dis){
          count++;
          break;
        }
      }
    }
  }
  std::cout << count << '\n';
  return 0;
}


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

using namespace std;

int n;
pair< int, int > p[55];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i].first);
		p[i].second = i;
	}
	sort(p, p + n);
	printf("%d\n", n * 2 - 2);
	if (abs(p[n - 1].first) > abs(p[0].first)) {
		for (int i = 0; i < n; i++)
			if (i != p[n - 1].second)
				printf("%d %d\n", p[n - 1].second + 1, i + 1);
		for (int i = 1; i < n; i++)
			printf("%d %d\n", i, i + 1);
	} else {
		for (int i = 0; i < n; i++)
			if (i != p[0].second)
				printf("%d %d\n", p[0].second + 1, i + 1);
		for (int i = n - 2; i >= 0; i--)
			printf("%d %d\n", i + 2, i + 1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int MAX_N = 100;

int n;
int a[MAX_N];
int d;
int x;

int main(){
    scanf("%d", &n);
    scanf("%d%d", &d, &x);
    for(int i = 0; i < n; ++i){
        scanf("%d", a + i);
    }
    int ans = x;
    for(int i = 0; i < n; ++i){
        int tmp = (d - 1) / a[i] + 1;
        ans += tmp;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
	int Alice, Bob;
	cin >> Alice >> Bob;
	if (Alice == 1) Alice = 14;
	if (Bob == 1) Bob = 14;
	if (Alice == Bob) cout << "Draw" << endl;
	else if (Alice > Bob) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	//while (1);
	return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

// https://atcoder.jp/contests/abc167/tasks/abc167_d
public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] array = new int[n + 1];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		sc.close();

		int end = 0;

		array[n] = 1;
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		int tmp = 1;
		map.put(tmp, 0);
		for (int i = 1; i <= n + 1; i++) {
			tmp = array[tmp - 1];
			if (map.containsKey(tmp)) {
				end = i;
				break;
			} else {
				map.put(tmp, i);
			}
		}

		long start = 0L;

		int tmp1 = 1;
		for (int i = 0; i <= n + 1; i++) {
			if (i == 0) {
				tmp1 = array[n];
			} else {
				tmp1 = array[tmp1 - 1];
			}
			if (tmp1 == tmp) {
				start = i;
				break;
			}
		}
		long rep = end - start;

		int ans = 1;

		if (k - start >= 0) {
			long aa = k - start;
			for (int i = 1; i <= start + aa % rep; i++) {
				ans = array[ans - 1];
			}
			System.out.println(ans);
		}else {
			for (int i = 1; i <= k; i++) {
				ans = array[ans - 1];
			}
			System.out.println(ans);
		}
		//		long aa = k - start;
		//		for (int i = 1; i <= start + aa % rep; i++) {
		//			ans = array[ans - 1];
		//		}
		//		System.out.println(ans);
	}
}

Measured memory_bytes: 56388
// https://atcoder.jp/contests/abc128/tasks/abc128_d

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 50;
const int K_MAX = 100;
const int V_I_MAX = 1e7;
const int INF = 1e9;

int N, K;
int V[N_MAX];

int x[N_MAX];

void solve() {
  int R = min(N, K);
  int ans = -INF;
  FOR(a, 0, N) FOR(b, 0, N) {
    int ab = a + b;
    if (ab > R) continue;
    copy(V, V + a, x);
    copy(V + N - b, V + N, x + a);
    sort(x, x + ab, greater<int>());
    // DUMP(x, ab);
    int sum = 0;
    REP(i, ab) {
      if (i >= ab * 2 - K && x[i] < 0) break;
      sum += x[i];
    }
    // printf("sum:%d\n", sum);
    ans = max(ans, sum);
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) scanf("%d", V + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
///Let us start the game
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define pb push_back
using ll = long long;
using ii = pair<int, int>;
using db = long double;
using ull = unsigned long long;
const int N = 2e3 + 5, M = 1e7 + 5, MOD = 1e9+7;
const db EPS = 1e-7;
int get(int x){
  bool f =  false;
  while(x){
    x/=10;
    f^=1;
  }
  return f;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);

  int n;
  cin >> n;
  
  int asn= 0;
  for(int i = 1; i <= n; i++){
    asn+=get(i);
  }
  
  cout << asn << '\n';


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200100;
const int INF=1e9+7;
int f[maxn],g[maxn];
int a[maxn];
void chkmin(int &x,int y){
	x=x<y?x:y;
}
int updata0(int x,int y,int v){
	if(x<=v){
		if(y>=v-x) return x;
		else return v-y;
	}
	else return v;
}
int updata1(int x,int y,int v){
	int res=v;
	if(x<=v) chkmin(res,x);
	if(y<=v) chkmin(res,v-y);
	else res=0;
	return res;
}
int main(){
//	freopen("E.in","r",stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int ans=0;
	for(int i=1;i<=n+1;i++){
		if(f[i-1]>a[i]){
			ans++;
			f[i]=a[i],g[i]=0;
			chkmin(f[i],updata1(f[i-1],a[i-1]-f[i-1],a[i]));
			chkmin(f[i],updata0(g[i-1],a[i-1]-g[i-1],a[i]));
		}
		else{
			f[i]=g[i]=a[i];
			chkmin(f[i],updata0(f[i-1],a[i-1]-f[i-1],a[i]));
			chkmin(g[i],updata1(f[i-1],a[i-1]-f[i-1],a[i]));
			chkmin(g[i],updata0(g[i-1],a[i-1]-g[i-1],a[i]));
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2560
import queue
h,w = map(int,input().split())
mas = []
black_num = 0
inf = 10 ** 7
for i in range(h):
    row = list(input())
    mas.append(row)
for i in range(h):
    for j in range(w):
        if mas[i][j] == "#":
            black_num += 1
dx = [0,0,1,-1]
dy = [1,-1,0,0]
def bfs():
    q = []
    q.append([0,0])
    step = []
    for i in range(h):
        step.append([-1] * w)
    for i in range(h):
        for j in range(w):
            step[i][j] = inf
    step[0][0] = 0
    while not len(q) == 0:
        s = q[0]
        q = q[1:]
        if s[0] == h-1 and s[1] == w-1:
            break
        for i in range(4):
            nx = s[0] + dx[i]
            ny = s[1] + dy[i]
            if(0 <= nx < h and 0 <= ny < w and mas[nx][ny] != '#' and step[nx][ny] == inf):
                q.append([nx,ny])
                step[nx][ny] = step[s[0]][s[1]] + 1
    
    if(step[h-1][w-1] == inf):
        return -1
    else:
        return step[h-1][w-1]

least = bfs()
if(least == -1):
    print(-1)
else:
    print(h * w - black_num - least - 1)

Measured memory_bytes: 3952
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    vector<ll> x(5);
    REP(i,5)cin>>x[i];
    REP(i,5){
        if(x[i]==0)cout<<i+1;
    }
    cout<<"\n";
}

Measured memory_bytes: 3632
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
using namespace std;

int main() {

	long long X;
	long long ans=100;
	int i = 0;
	cin >> X;

	while (ans< X) {
		ans += ans/100;
		i++;
	}

	cout << i;
}

Measured memory_bytes: 3620
function main()
    (N,A,B) = map(x -> parse(Int,x),split(readline()))
    
    sum = 0
    total = 0
    
    for n in 1:N
        m = n
        num = n
        check = 0
        total = 0
        while  num != 0
            num = div(num,10)
            check += 1
        end
        
        for i in 1:check
            total += m % 10
            m = div(m,10)
        end 

        if A <= total <= B
            sum += n
        end
    end
    
    println(sum)
end

main()

Measured memory_bytes: 120556
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), p(n);
    for(int i=0; i<n; ++i)
        cin >> a[i] >> b[i] >> p[i];

    vector<int> dp(393+1, -1);
    dp[0] = 0;
    for(int i=0; i<393; ++i){
        if(dp[i] == -1)
            continue;
        for(int j=0; j<n; ++j){
            for(int k=a[j]; k<=b[j]; ++k){
                int t = i + k;
                if(t <= 393)
                    dp[t] = max(dp[t], dp[i] + p[j]);
            }
        }
    }

    int m;
    cin >> m;
    vector<int> ret(m);
    for(int i=0; i<m; ++i){
        int w;
        cin >> w;
        if(dp[w] == -1){
            cout << -1 << endl;
            return 0;
        }
        ret[i] = dp[w];
    }

    for(int i=0; i<m; ++i)
        cout << ret[i] << endl;

    return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>

int main(void)
{
    char A[101], B[101], C[101];
    int N, i,cnt_eq,cnt_ans;
    scanf("%d", &N);
    scanf("%s", &A);
    scanf("%s", &B);
    scanf("%s", &C);
    cnt_ans == 0;
    for ( i = 0; i < N; i++ )
    {
        cnt_eq = 0;
        if ( A[i] == B[i] ) cnt_eq++;
        if ( B[i] == C[i] ) cnt_eq++;
        if ( C[i] == A[i] ) cnt_eq++;
        if ( cnt_eq == 3) cnt_ans += 0;
        if ( cnt_eq == 1) cnt_ans += 1;
        if ( cnt_eq == 0) cnt_ans += 2;

    }
    printf( "%d", cnt_ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
    #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define ll long long
    const ll maxn=2e5+10;
     
     
    int main() {
    	int t,j,k,m,s=0;
    	int n,i;
	cin>>n>>m;
	int a[n];
	
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	//cout<<s<<endl;
	double tt=(double)(s)/(4*m);
	//cout<<tt<<endl;
	int cnt=0;
	for(i=0;i<n;i++)
	{
		if(a[i]>=tt) 
			++cnt;
	}
	if(cnt>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int n,a;
LL d;
struct data{
	LL h,x;
}w[200005];
LL ans;
queue<data>Q;
bool cmp(data a,data b){
	return a.x<b.x;
}
int main(){
	scanf("%d%d",&n,&d);
	printf("%d\n",n/d+(n%d!=0));
	return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    vector<int> a, b;
    int ina, inb;
    for (int i = 0; i < N; i++)
    {
        cin >> ina >> inb;
        a.emplace_back(ina);
        b.emplace_back(inb);
    }
    int inc, ind;
    vector<int> c, d;
    for (int i = 0; i < M; i++)
    {
        cin >> inc >> ind;
        c.emplace_back(inc);
        d.emplace_back(ind);
    }
    
    int man;
    int min;
    int ans;
    for (int i = 0; i < N; i++)
    {
        min = INT_MAX;

        for (int j = 0; j < M; j++)
        {
            man = (abs(a[i] - c[j]) + abs(b[i] - d[j]));
            if (man < min) min = man, ans = j + 1; 
        }
        cout << ans << endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>

int main(){
  int b[15][15],i,n,x,y;
  while(scanf("%d",&n)){
    if(n==0) break;
    for(y=0;y<n;y++) for(x=0;x<n;x++) b[x][y]=0;
    x=(n-1)/2; y=(n+1)/2; b[x][y]=1;
    for(i=2;i<=n*n;i++){
      if(++x>=n) x=0;
      if(++y>=n) y=0;
      while(b[x][y]!=0){
        if(--x<0) x=n-1;
        if(++y>=n) y=0;
      }
      b[x][y]=i;
    }
    for(y=0;y<n;y++){
      for(x=0;x<n;x++) printf("%4d",b[x][y]);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
//AUTHOR: *Akash Shrivastva*
//Birla Institute of Technology,Mesra,India
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define M 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector< pair <ll,ll> >
#define F first
#define S second
#define PII pair <ll,ll>
ll a[100000][3],dp[100000][3],n;
ll f(ll i,ll j)
{
	if (i>=n)	return 0;
	if (dp[i][j]!=-1)	return dp[i][j];
	if (j==0)
		dp[i][j]=max(f(i+1,1),f(i+1,2))+a[i][j];
	else if (j==1)	dp[i][j]=max(f(i+1,0),f(i+1,2))+a[i][j];
	else	dp[i][j]=max(f(i+1,0),f(i+1,1))+a[i][j];
	return dp[i][j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
 
    cin>>n;
    ll i,j;
    a[n][3],dp[n][3];
    for (i=0;i<n;i++)
    	for (j=0;j<3;j++)
    		cin>>a[i][j];
    memset(dp,-1,sizeof(dp));
    ll ans=max(f(0,0),max(f(0,1),f(0,2)));
    cout<<ans<<endl;
}

Measured memory_bytes: 9600
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
   
int32_t N, M, P[1123];
std::vector<int32_t>list;
int32_t ans;
   
int main()
{
    while (true)
    {
        using std::begin;using std::end;

        N = M = 0;
        memset(P, 0, sizeof(P));
        list.clear();
        ans = 0;
   
        in >> N >> M;
        if (N == 0 && M == 0) { break; }
        rep(i, N) { in >> P[i]; }
   
        P[N] = 0;
        N++;
        //std::sort(P, P + N);
        rep(i, N)
        {
            rep(j, N) { list.push_back(P[i] + P[j]); }
        }
        std::sort(begin(list), end(list));
        for (auto& i : list)
        {
            if (i > M) { break; }
            auto iter = upper_bound(begin(list), end(list), M - i);
            --iter;
            ans = std::max(ans, i + *iter);
        }
   
        out << ans << std::endl;
    }
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 x,n, tmp, ans = inf; cin >> x >> n;
    vi p(1000);
    rep(i,n) {
        cin >> tmp;
        p[tmp] = 1;
    }
    tmp = inf;
    rrep(i, 1000) {
        if(tmp >= abs(i-x)) if(!p[i]) {
            tmp = abs(i-x);
            chmin(ans, i);
        }
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,time,cost,sum=100000000;
  int out=0;
  cin>>n>>t;
  for(int i=0;i<n;i++){
    cin>>cost>>time;
    if(time<=t){
      out++;
      sum=min(sum,cost);
    }
  }
  if(out==0) cout<<"TLE"<<'\n';
  else cout<<sum<<'\n';
  return 0;
}

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

int dist(int i, int j)
{
 	return abs(i - j); 
}

bool good = true;
int a[6],k;
int main()
{
	for(int i = 0; i < 5; i++)
      	cin >> a[i];
  	cin >> k;
  	
  	for(int i = 0; i < 5 && good; i++)
      	for(int j = 0; j < 5 && good; j++)
          	good = (good && dist(a[i], a[j]) <= k);
  	cout << (good ? "Yay!" : ":(") << endl;
  	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

long long a,b,c[10];

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



cin >> a >> b;

c[a] = 1;
c[b] = 1;

for (int i = 1;i<=3;i++)
	if (c[i] == 0)
		cout << i;




return 0;
}



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

template<typename T> void add_self(T& a, T b) {
    a += b;
}

int main()
{
    int n;
    cin >> n;
    vector<double> heads(n+1);
    heads[0] = 1;
    for(int i = 0; i < n; i++) {
        double p;
        cin >> p;
        for(int j = i; j >= 0; j--) {
            heads[j+1] += heads[j]*p;
            heads[j] = heads[j]*(1-p);
        }
    }
    double headsmore = 0;
    for(int i = n/2+1; i <= n; i++) {
        headsmore += heads[i];
    }
    cout << fixed << setprecision(10) << headsmore << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string yes = "Yes", no = "No";
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    rep(i, a) if(s[i] < '0' || s[i] > '9') {
        cout << no << endl;
        return 0;
    }
    if(s[a] != '-') {
        cout << no << endl;
        return 0;
    }
    REP(i, a+1, a+b+1) if(s[i] < '0' || s[i] > '9'){
        cout << no << endl;
        return 0;
    }
    cout << yes << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int A = GetInt();
		int B = GetInt();
		List<long> v = new List<long>(N);
		for(int i = 0; i < N; i++)
			v.Add(GetLong());
		v.Sort();
		v.Reverse();

		double average = 0;
		for(int i = 0; i < A; i++)
			average += (double)v[i];
		average /= (double)A;

		long numComb = 0;
		bool hasSingleV = (v[0] == v[A-1]);
		if(hasSingleV)
		{
			long singleV = v[0];
			long numSingleV = 1;
			for(int i = 1; i < N; i++)
			{
				if(v[i] != singleV)
					break;
				numSingleV++;
			}
			
			for(int k = A; k <= Math.Min(B, numSingleV); k++)
				numComb += combination(numSingleV, k);
		}
		else
		{
			long vMin = v[A-1];
			long numInA = 1;
			for(int i = A - 2; i >= 0; i--)
			{
				if(v[i] != vMin)
					break;
				numInA++;
			}
			long numInN = numInA;
			for(int i = A; i < N; i++)
			{
				if(v[i] != vMin)
					break;
				numInN++;
			}
			numComb = combination(numInN, numInA);
		}

		Console.WriteLine(average.ToString("F6"));
		Console.WriteLine(numComb);
	}

	private static long combination(long n, long k) 
	{
		long r = 1;
		for(long d = 1; d <= k; d++) 
		{
			r *= n--;
			r /= d;
		}
		return r;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

int main() {
  int N, a, b;
  cin >> N;
  a = N % 1000, b = N % 1110;
  if ((a % 111 == 0) || (b <= 9))
      cout << "Yes" << endl;
  else 
      cout << "No" << endl;
}
    

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

S = input()
ABCD = [int(S[0])]
ABCD.append(int(S[1]))
ABCD.append(int(S[2]))
ABCD.append(int(S[3]))

item = ["+","-"]

for i in range(2**3):

    ans = ABCD[0]
    op = []

    for j in range(0,3):
        if ((i >> j) & 1):
            ans += ABCD[j+1]
            op.append("+")
        else:
            ans -= ABCD[j+1]
            op.append("-")

    if ans == 7:
        print(str(ABCD[0])+op[0]+str(ABCD[1])+op[1]+str(ABCD[2])+op[2]+str(ABCD[3])+"=7")
        break


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

int main(){
  int n,i;
  cin>>n;
  int sum=0;
  for(i=0;i<10;i++){
    sum+=((int)(n/pow(10,i)))%10;
  }
  if(n%sum==0)cout<<"Yes";
  else cout<<"No";
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];

    vll dp(n + 1, vl(2, 0));
    dp[0][1] = -INF;
    rep(i, n) {
        dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
    }

    out(dp[n][0]);
    return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    long[] A=new long[N];
	    
	    long m=1;
	    for (int i=0; i<N; i++) {
	    	A[i]=gl();
	    	if(A[i]==0) {
	    		System.out.print("0");
	    		return;
	    	}
	    }
	    
	    for (int i=0; i<N; i++) {
	    	if (Math.floorDiv(1000000000000000000l, m)<A[i]) {
	    		System.out.print("-1");
	    		return;
	    	}
	    	m*=A[i];
	    }

	    	System.out.print(m);

//        if (flg) {
//        	System.out.print("YES");
//        }else {
//        	System.out.print("NO");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 60836
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 500
#define INF 1<<28
typedef pair<int,int> P;
struct edge{
  int to,cap,cost,rev;
  edge(){}
  edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
};

int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back(edge(to,cap,cost,G[to].size()));
  G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
      P p=que.top();que.pop();
      int v=p.second;
      if(dist[v]<p.first) continue;
      for(int i=0;i<(int)G[v].size();i++){
	edge &e=G[v][i];
	if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
	  dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to]=v;
	  preve[e.to]=i;
	  que.push(P(dist[e.to],e.to));
	}
      }
    }
    if(dist[t]==INF){
      return -1;
    }
    for(int v=0;v<V;v++) h[v]+=dist[v];

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}

struct ope{
  int x,y,d;
  ope(){}
  ope(int x,int y,int d):x(x),y(y),d(d){}
};

int main(){
  int n;
  cin>>n;
  int c[2][n][n];
  for(int k=0;k<2;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	cin>>c[k][i][j];
  
  string str[n];
  for(int i=0;i<n;i++) cin>>str[i];

  V=n*2+2;
  int s=n*2,t=n*2+1;
  for(int i=0;i<n;i++){
    add_edge(s,i,1,0);
    add_edge(n+i,t,1,0);
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int r=0;
      for(int k=0;k<n;k++){
	if(k==j){
	  if(str[i][k]=='.') r+=c[0][i][k];
	}else{
	  if(str[i][k]=='o') r+=c[1][i][k];
	}
      }
      add_edge(i,n+j,1,r);
    }
  }
  cout<<min_cost_flow(s,t,n)<<endl;
  vector<ope> v;
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)G[i].size();j++){
      if(G[i][j].cap) continue;
      for(int k=0;k<n;k++){
	if(n+k==G[i][j].to){
	  if(str[i][k]=='.') v.push_back(ope(i+1,k+1,0));
	}else{
	  if(str[i][k]=='o') v.push_back(ope(i+1,k+1,1));
	}
      }
    }
  }
  cout<<v.size()<<endl;
  for(int i=0;i<(int)v.size();i++)
    cout<<v[i].x<<" "<<v[i].y<<" "<<(v[i].d?"erase":"write")<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>


long long  INF=1000000000000000000;
using namespace std;
int seki(int day){
    
    int d1=day%10;
    day-=d1;
    int d10=day/10;
    if(d10<2 || d1<2){
        return 1;
    }
    return  d10*d1;
}

int main(){

int M,D;

cin>>M>>D;
long long ans=0;
for(int i=4;i<=M;i++){
    for(int k=1;k<=D;k++){
        if(i==seki(k)){
            ans++;
        }
    }
}
cout<<ans<<endl;
 return 0;
}

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

int main() {
  int k, s; cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int n = s - i - j;
      if (0 <= n && n <= k) ans++;
    }
  }
  cout << ans << endl;
}

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

template<typename T, typename Monoid>
struct SegmentTree {
private:
  int n;
  std::vector<T> node;

public:
  constexpr SegmentTree(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    node.resize(2*n-1, Monoid::unit());
    for (int i = 0; i < n_; ++i) node[i+n-1] = Monoid::unit();
    for (int i = n-2; i >= 0; --i) node[i] = Monoid::operate(node[2*i+1], node[2*i+2]);
  }
  void update(int i, T x) {
    node[i+n-1] = x;
    for (i = (i+n)/2; i > 0; i /= 2) {
      node[i-1] = Monoid::operate(node[2*i-1], node[2*i]);
    }
  }
  T get(int l, int r) const { // [l, r)
    assert(0 <= l and l <= r and r <= n);
    T lacc = Monoid::unit();
    T racc = Monoid::unit();
    for (l += n, r += n; l < r; l /= 2, r /= 2) {
      if (l % 2 == 1) lacc = Monoid::operate(lacc, node[(l++) - 1]);
      if (r % 2 == 1) racc = Monoid::operate(node[(--r) - 1], racc);
    }
    return Monoid::operate(lacc, racc);
  }
};

template<typename T>
struct PlusMonoid {
  static constexpr T unit() { return 0; }
  static constexpr T operate(T a, T b) { return a + b; }
};

template<typename T>
struct MaxMonoid {
  static constexpr T unit() { return std::numeric_limits<T>::min(); }
  static constexpr T operate(T a, T b) { return std::max(a, b); }
};

template<typename T>
struct MinMonoid {
  static constexpr T unit() { return std::numeric_limits<T>::max(); }
  static constexpr T operate(T a, T b) { return std::min(a, b); }
};

int main() {
  int n, q;
  cin>>n>>q;
  SegmentTree<int, MinMonoid<int>> sg(n);

  for (int i = 0; i < q; ++i) {
    int com, x, y;
    cin>>com>>x>>y;
    if (com == 0) sg.update(x, y);
    else cout << sg.get(x, y+1) << endl;
  }
}


Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

int main()
{
    string s;
    bool backspace = false;
    cin >> s;

    stack<char> answer;

    for (size_t i = 0; i < s.size(); i++)
    {
        if(s[i] == 'B')
        {
            if(!answer.empty()) answer.pop();
        }
        else
        {
            answer.push(s[i]);
        }
    }

    string result = "";
    while(!answer.empty())
    {
        result = answer.top() + result;
        answer.pop();
    }
    
    cout << result << endl;
    return 0;
    
}

Measured memory_bytes: 256
import math

N = int(input())
s = [list(input()) for i in range(N)]
S = []

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(N):
  s[i].sort()
  string = ''.join(s[i])
  S.append(string)
  
a = {}
answer = 0
for i in range(N):
  if S[i] not in a.keys():
    a[S[i]] = 1
  else:
    a[S[i]] += 1
else:
  for j in a.values():
    if j != 1:
      answer += comb(j, 2)
  else:
    print(answer)

Measured memory_bytes: 40684
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define N 3
#define mo 1000000007
#define ll long long
using namespace std;
int n,m;
struct node{
	ll a[N][N];
	node friend operator *(node a,node b)
	{
		node c;memset(c.a,0,sizeof(c.a));
		fo(i,0,2) fo(j,0,2) fo(k,0,2) c.a[i][k]=(c.a[i][k]+a.a[i][j]*b.a[j][k])%mo;
		return c;
	}
}a,b,c,ans;
void calc(int x)
{
	if(x<1) return;
	node q=a;
	for(;x;x/=2,q=q*q) if(x%2==1) ans=ans*q;
}
int main()
{
	scanf("%d%d",&n,&m);
	int las=1;
	a.a[1][0]=a.a[0][2]=a.a[1][1]=a.a[1][2]=a.a[2][0]=a.a[2][2]=1;
	a.a[0][0]=a.a[0][1]=2;
	b=a;
	b.a[0][0]=1;
	b.a[1][0]=b.a[2][0]=0;
	ans.a[0][0]=1;
	c.a[0][0]=c.a[1][0]=c.a[2][0]=1;
	while(m--)
	{
		int x;scanf("%d",&x);
		calc(x-las);las=x+1;
		ans=ans*b;
	}
	calc(n-las);
	ans=ans*c;
	printf("%lld\n",ans.a[0][0]);
}

Measured memory_bytes: 128