akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main(){
    int A, B, ans;
    char op;
    cin >> A >> op >> B;
    if(op == '+'){
        ans = A + B;
    }else {
        ans = A - B;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from math import ceil
def solve():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))

    left = 0
    right = 10 ** 9
    while (right - left) > 1:
        x = (left+right) // 2
        cnt = 0
        for a in A:
            cnt += (a-1) // x
        
        if cnt <= K:
            right = x
        else:
            left = x
    
    print(right)
    
if __name__ == '__main__':
    solve()


Measured memory_bytes: 104136
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define endl "\n"
#define oo 0x3f3f3f3f3f3f3f3fLL
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define debug(x) cout<<" LOOK "<<(#x)<<" = "<<x <<'\n'
#define NumofDigits(n)   ((long long)log10(n)+1)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};*/
inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}


int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    File();
  int n;
    cin>>n;
    ll arr[n+1];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    int cnt=0;
    for(int i=0;i<n-2;i++)
       for(int j=i+1;j<n-1;j++)
         for(int k=j+1;k<n;k++)
          if(arr[i] != arr[j] and arr[j]!=arr[k] and arr[i]!=arr[k] and arr[i] + arr[j] > arr[k])
             cnt++;
    cout<<cnt<<endl;
}


Measured memory_bytes: 3672
//sushi-J dp implementation
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
#define prDouble(x) cout<<fixed <<setprecision(10)<<x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

double dp[301][301][301];

double solve(int x,int y,int z,int n)
{

    if(x<0 || y<0 || z<0)
    return 0;
if(x==0 && y==0 && z==0)
return dp[x][y][z]=0;

//look up
if(dp[x][y][z]> -.9)
return dp[x][y][z];

double exp=n+x*solve(x-1,y,z,n)+y*solve(x+1,y-1,z,n)+z*solve(x,y+1,z-1,n);
return dp[x][y][z]=exp/(x+y+z);




}





int main()
{
    int n,x;
    cin>>n;
    memset(dp,-1,sizeof dp);
    int bucket_one=0,bucket_two=0,bucket_three=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x==1)
        bucket_one++;
        else if(x==2)
        bucket_two++;
        else if(x==3)
        bucket_three++;
    }
        prDouble(solve(bucket_one,bucket_two,bucket_three,n));

    return 0;


    }


Measured memory_bytes: 213376
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <limits.h>
#include <map>
#include <math.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;cin>>n>>k;
  int cnt=0;
  for(int i=0;i<n;i++){
    int h;cin>>h;
    if(h>=k) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <vector>


static bool check_consistency(
    std::vector<std::vector<int>> const& statements, unsigned condition
);

static void print_statements(
    std::vector<std::vector<int>> const& statements
);

static bool checkbit(unsigned bits, int i);
static int  popcount(unsigned bits);


int main()
{
    std::size_t n_people;
    std::cin >> n_people;

    std::vector<std::vector<int>> statements;

    for (std::size_t i = 0; i < n_people; i++) {
        std::size_t n_statements;
        std::cin >> n_statements;

        std::vector<int> statement(n_people);
        for (std::size_t j = 0; j < n_statements; j++) {
            std::size_t p;
            int s;
            std::cin >> p >> s;

            // Our index starts from zero.
            assert(p >= 1);
            p -= 1;

            // Input coding is 0: unkind, 1: honest. Our coding is -1: unkind,
            // 0: neutral, 1: honest.
            if (s == 0) {
                s = -1;
            }
            assert(s == -1 || s == 1);

            statement[p] = s;
        }

        statements.push_back(statement);
    }

    int max_honests = 0;
    unsigned upper_bound = 1u << n_people;
    for (unsigned condition = 0; condition < upper_bound; condition++) {
        if (check_consistency(statements, condition)) {
            max_honests = std::max(max_honests, popcount(condition));
        }
    }

    std::cout << max_honests << '\n';
}


static void print_statements(
    std::vector<std::vector<int>> const& statements
)
{
    for (auto const& statement : statements) {
        for (auto const& s : statement) {
            std::cout << s << ' ';
        }
        std::cout << '\n';
    }
}


static bool check_consistency(
    std::vector<std::vector<int>> const& statements, unsigned condition
)
{
    auto const n_people = statements.size();

    for (std::size_t i = 0; i < n_people; i++) {
        auto const& statement = statements[i];
        if (!checkbit(condition, i)) /* i is unkind; can't say anything */ {
            continue;
        }

        // Now we assume i is honest.

        for (std::size_t j = 0; j < statement.size(); j++) {
            if (checkbit(condition, j)) /* j is honest */ {
                if (statement[j] == -1) /* but i says j is unkind */ {
                    return false;
                }
            } else /* j is unkind */ {
                if (statement[j] == 1) /* but i says j is honest */ {
                    return false;
                }
            }
        }
    }
    return true;
}


static bool checkbit(unsigned bits, int i)
{
    return (bits >> i) & 1;
}


static int popcount(unsigned bits)
{
    int n = 0;
    for (int i = 0; i < 32; i++) {
        n += checkbit(bits, i);
    }
    return n;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios::sync_with_stdio(false);
#define pi 3.14159265358979323846264338327950288419716939937510
#define pb push_back
typedef long long ll;
using namespace std;
int main()
{
   fast
    ll cnt=0;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt<<endl;
return 0;
}


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

int main(){
		int temp,n, m;
		cin >> n;
		m = n;
		int sum = 0;
		vector<int> v;
		while(m--){
			cin >> temp;
			sum+=temp;
			v.push_back(temp);
		}
		int mid = round((double) sum/n);
		sum = 0;
		for (int x: v){
			sum += (x-mid)*(x-mid);
		}
		cout << sum;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

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


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

int main(){
  int n;
  cin >> n;
  vector<int64_t> a(100);
  a.at(0) = 2;
  a.at(1) = 1;
  rep(i,90){
    a.at(i+2) = a.at(i+1) + a.at(i);
  }
  cout << a.at(n) << endl;
  

        
        
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int h=s[0],w=s[1];
		long[,] dp=new long[h,w];
		string[] b=new string[h];
		for(int i=0;i<h;i++){
			b[i]=Console.ReadLine();
		}
		dp[h-1,w-1]=1;
		for(int i=h-1;i>=0;i--){
			for(int j=w-1;j>=0;j--){
				if(b[i][j]=='.'){
					dp[i,j]%=mod;
					if(i!=0){dp[i-1,j]+=dp[i,j];}
					if(j!=0){dp[i,j-1]+=dp[i,j];}
				}
			}
		}
		Console.WriteLine(dp[0,0]);
	}
}

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

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    int ans;
    bool nine;
    vector<int> n_;
    cin >> n;

    nine = true;
    int i = 0;
    while (n >= 1)
    {
        n_.push_back(n % 10);
        if (n >= 10 && n_.back() != 9)
            nine = false;
        n /= 10;
        i++;
    }

    if (nine)
        ans = n_.back() + (n_.size() - 1) * 9;
    else
        ans = (n_.back() - 1) + (n_.size() - 1) * 9;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque


def run():
    N, *A = map(int, read().split())
    buy = True
    money = 1000
    stock = 0
    for i, a in enumerate(A[:-1]):
        if buy:
            if a < A[i+1]:
                stock += money // a
                money %= a
                buy = False
        else:
            if a > A[i+1]:
                money += stock * a
                stock = 0
                buy = True
    money += stock * A[-1]
    print(money)



if __name__ == "__main__":
    run()

Measured memory_bytes: 9468
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
from collections import deque

S = input()
Q = int(input())

# Queries = []
# for _ in range(Q):
#     Queries.append(list(input().split()))
    
# for Query in Queries:
#     T = int(Query[0])
#     if T == 1:
#         S = S[::-1]
#     else:
#         F = int(Query[1])
#         C = Query[2]
#         if F == 1:
#             S = C + S
#         else:
#             S = S + C
# print(S)

swap = 1
head = deque()
tail = deque()
for _ in range(Q):
    Query = list(input().split())

    if Query[0] == "1":
        swap *= -1
    
    else:
        F, C = Query[1], Query[2]
        if F == "1":
            if swap == 1:
                head.appendleft(C)
            else:
                tail.append(C)
        else:
            if swap == -1:
                head.appendleft(C)
            else:
                tail.append(C)         


print(("".join(head) + S + "".join(tail))[::swap])



Measured memory_bytes: 68312
#include<stdio.h>

int main(){
	int X,N;
	scanf("%d %d",&X,&N);
	int p[102];
	for(int i=0;i<102;i++) p[i]=0;
	for(int i=0;i<N;i++){
		int tmp;
		scanf("%d",&tmp);
		p[tmp]++;
	}
	if(p[X]==0){
		printf("%d\n",X);
		return 0;
	}
	int l=X-1;
	int r=X+1;
	while(p[l]!=0 && p[r]!=0){
		if(l!=0) l--;
		if(r!=101) r++;
	}
	if(p[l]==0 && p[r]==0) printf("%d\n",l);
	if(p[l]!=0 && p[r]==0) printf("%d\n",r);
	if(p[l]==0 && p[r]!=0) printf("%d\n",l);
	return 0;
}

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

def main():
    N, M = list(map(int, input().split()))
    ks = [list(map(int, input().split())) for _ in range(M)]
    p = list(map(int, input().split()))
    ans = 0

    for condition in ks:
        condition[1:] = list(map(lambda x: x-1, condition[1:]))
    
    for i in range(1 << N):
        switch = [None] * N
        for j in range(N):
            switch[j] = 1 if ((i >> j) & 1) else 0
        
        flag = True
        for m in range(M):
            s = ks[m][1:]
            if sum(switch[idx] for idx in s) % 2 != p[m]:
                flag = False
                break
        if flag:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 42712
//
//  main.c
//  procon
//
//  Created by Lee, Chanyeong | Naru | MSDD on 2017. 10. 16..
//  Copyright © 2017년 Lee, Chanyeong | Naru | MSDD. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int a, b;
    int arrayInt_a[] = {1,3,5,7,8,10,12};
    int arrayInt_b[] = {4,6,9,11};
    
    int flag = 0;
    
    scanf("%d %d", &a, &b);
    
    int i = 0;
    if(a == 2 || b == 2) {
        printf("No");
        return 0;
    }

    for (i=0; i<4; i++) {
        if (a == arrayInt_b[i]) {
            flag = 1;
            break;
        }
    }
    
    if (flag == 0) {
        for (i=0; i<7; i++) {
            if (b == arrayInt_a[i]) {
                printf("Yes");
                return 0;
            }
        }
    }
    else if (flag == 1) {
        for (i=0; i<4; i++) {
            if (b == arrayInt_b[i]) {
                printf("Yes");
                return 0;
            }
        }
    }
    
    printf("No");
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main(){
  ll n; cin >> n;
  vector<ll> v(n);
  REP(i,n) cin >> v[i];
  sort(ALL(v));
  double cur = (v[0]+v[1])/2.0; 
  FOR(i,2,n){
    cur = (cur+v[i])/2.0;
  }
  cout << fixed << setprecision(10);
  cout << cur << endl;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * 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);
        ABC097_C solver = new ABC097_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC097_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int k = in.nextInt();

            ArrayList<String> sub = new ArrayList<>();

            for (int i = 0; i <= s.length(); i++) {
                for (int j = i; j <= i + k; j++) {
                    if (j <= s.length() && i != j) {
                        String subStr = s.substring(i, j);
                        if (!sub.contains(subStr)) {
                            sub.add(s.substring(i, j));
                        }
                    }
                }
            }

            Collections.sort(sub);

            out.print(sub.get(k - 1));
        }

    }
}



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

int main(){
	int a,b;
	string s,t,u;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(u==s){
		a--;
	}else{
		b--;
	}
	cout<<a<<" "<<b<<endl;	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  ll N, K; cin >> N >> K;
  vector<int> A(N);
  for(int i=0; i<N; i++)
    cin >> A[i];
  
  vector<int> B(2*N);
  for(int i=0; i<2*N; i++)
    B[i] = A[i%N];
  
  vector<vector<int>> jump(300000);
  for(int i=0; i<2*N; i++)
    jump[B[i]].push_back(i);
  
  vector<int> next(N); // Aiからjumpしたときのindex
  for(int i=0; i<N; i++){
    auto it = upper_bound(jump[A[i]].begin(), jump[A[i]].end(), i);
    next[i] = (*it) + 1;
  }
  vector<int> start; // i個目Aをまたぐjumpにおける始点のindex
  int now;
  now = 0;
  while(true){
    if(next[now] > N) {
      start.push_back(now);
    }
    if(next[now]%N == 0) {
      start.push_back(now);
      break;
    }
    now = next[now]%N;
  }
  
  K %= (int)start.size();
  
  for(int i=start[K-1]; i<N; i++){
    if(next[i] <= N) i = next[i] - 1;
    else cout << A[i] << " ";
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 18808
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios_base::sync_with_stdio(false);; cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define mt 			make_tuple
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define MOD 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define roff(i,n,f)	for(int i = n-1; i>=f; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define maxs(x,y) 	(x = max(x,y))		//max self
#define mins(x,y) 	(x = min(x,y))		//min self
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef vector< int > 		vi;
typedef vector<llu>         vlu;
typedef vector< vi >		vvi;
typedef pair<int, int> 		pii;
typedef tuple<int,int,int>  tiii;

int main()
{
	IOS;
	int n, mw;	cin >> n >> mw;
	vlu dp(100000+1, INT_MAX);
	dp[0] = 0;
	rep(i, n){
		int w, v;	cin >> w >> v;
		rof(j, 100000-v+1)
			dp[j+v] = min(dp[j+v], dp[j]+w);
	}
	llu ans = 0;
	rep(i, 100000+1)
		if(dp[i] <= mw)
			ans = i;
	cout << ans << endl;
	
    return 0;
}


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

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> h(200010);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> h[i];
    sum += h[i];
  }

  sort(h.begin(), h.end(), greater<int>());

  long long h_target_sum = 0;
  for (long long i = 0; i < k; i++) {
    h_target_sum += h[i];
  }

  cout << sum - h_target_sum << endl;
  return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<vector<ll>> A(N, vector<ll>(N));
	rep(i,N) rep(j,N) cin >> A[i][j];

	priority_queue<tuple<ll, int, int>, vector<tuple<ll, int, int>>, greater<tuple<ll, int, int>>> pq;
	rep(i,N-1) for (int j = i+1; j < N; j++) pq.emplace(A[i][j],i,j);
    
	vector<vector<ll>> G(N, vector<ll>(N,1e15));
	bool ok = true;
	rep(i,N) G[i][i] = 0;
	ll ans = 0;
	while(!pq.empty()) {
		ll l; int p,q;
		tie(l,p,q) = pq.top(); pq.pop();
		if (l > G[p][q]) {
			ok = false;
			break;
		} else if (l < G[p][q]){
			G[p][q] = G[q][p] = l;
            ans += l;
			rep(i,N) {
				rep(j,N) {
					chmin(G[i][j], G[i][p] + l + G[q][j]);
					chmin(G[i][j], G[i][q] + l + G[p][j]);
					G[j][i] = G[i][j];
				}
			}
		}
	}

	cout << (ok ? ans : -1) << endl;
}


Measured memory_bytes: 2428
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let mut s = read_as_vec::<u32>()[0];
    let mut buf = vec![0;3];
    let mut i = 1;
    if s == 1 || s == 2{
        println!("4");
        return;
    }

    while s != 4{
        if s%2 == 0{
            s /= 2;
        }else{
            s = 3*s+1;
        }
        i += 1;
    }
    println!("{}", i+3);
}


Measured memory_bytes: 4352
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] n = sc.nextLine().toCharArray();

        if(n[0]==n[2]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 21844
let m = 998244353
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let () = Scanf.scanf "%d %d\n" @@ fun n s ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let result = ref 0 in
  let dp = Array.make 3001 0 in
  for i = 0 to n - 1 do
    for j = s downto as_.(i) + 1 do
      dp.(j) <- dp.(j) +^ dp.(j - as_.(i))
    done;
    dp.(as_.(i)) <- dp.(as_.(i)) +^ (i + 1);
    result := !result +^ dp.(s) *^ (n - i);
    dp.(s) <- 0;
  done;
  Printf.printf "%d\n" @@ !result


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

int main()
{
    ll n,w;
    cin>>n>>w;
    vector<pair<ll,ll>> a(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    ll k=1e5;
    vector<vector<ll> > dp(n+1,vector<ll> (k+2,1e16));

    for(ll i=0;i<=n;i++)
        dp[i][0]=0;

    for(ll i=1;i<=n;i++)
        for(ll j=1;j<=k;j++)
        
            if(j>=a[i].second)
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-a[i].second]+a[i].first);
    
            else
                dp[i][j]=dp[i-1][j];            
        
    

    ll maxi=0;

    for(ll i=1;i<=k;i++)
        if(dp[n][i]<=w)
            maxi=i;

    cout<<maxi<<endl;

}


Measured memory_bytes: 83240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    for(int i=0; i<x; i++)cin>>a[i];
    for(int i=0; i<y; i++)cin>>b[i];
    for(int i=0; i<z; i++)cin>>c[i];
    vector<ll> xy;
    for(int i=0; i<x; i++){
        for(int j=0; j<y; j++){
            xy.push_back(a[i]+b[j]);
        }
    }
    sort(xy.rbegin(),xy.rend());
    if(xy.size()>3000)xy.resize(3000);

    vector<ll> xyz;
    for(int i=0; i<xy.size(); i++){
        for(int j=0; j<z; j++){
            xyz.push_back(xy[i]+c[j]);
        }
    }
    sort(xyz.rbegin(),xyz.rend());
    for(int i=0; i<k; i++){
        cout<<xyz[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 43240
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか
int main() {
	long long int n;
	long long int k;
	cin >> n >> k;
	vector<long long int > s;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		s.push_back(a);
	}
	sort(s.begin(), s.end());
	COMinit();
	long long int ans = 0;
	for (long long int i = 0; i < n; i++) {
		if (i >= k - 1) {
			long long int a;
			a = COM(i, k - 1);
			ans = ans + a * s[i];
			ans = ans % MOD;
		}
		if (s.size() - 1 - i >= k - 1) {
			long long int a;
			a = COM(s.size() - 1 - i, k - 1);
			ans = ans - a * s[i];
			ans = ans % MOD;
		}
	}
	cout << ans;
}

Measured memory_bytes: 17524
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a; cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()	
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000000LL;
typedef pair<int,int> P;
int main(){
	int n,m,x,y;cin>>n>>m>>x>>y;
	int xx[110],yy[110];
	for(int i=0;i<n;i++)cin>>xx[i];
	for(int i=0;i<m;i++)cin>>yy[i];
	xx[n]=x;
	yy[m]=y;
	sort(xx,xx+n+1);
	sort(yy,yy+m+1);
	if(xx[n]<yy[0]){
		cout<<"No War"<<endl;
	}else{
		cout<<"War"<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(int argc,char* argv[]){
   
  int wide;
  int n;
  int amida[31];
  int a,b;
  int tmp,tmp2;
 
  for(tmp = 0; tmp < 31; ++tmp){
    amida[tmp] = tmp;
  }
   
  scanf("%d",&wide);
  scanf("%d",&n);
   
  for(tmp2 = 0;tmp2 < n;++tmp2){
    scanf("%d,%d",&a,&b);
    tmp = amida[a];
    amida[a] = amida[b];
    amida[b] = tmp;
  }
 
  for(tmp = 1; tmp <= wide; ++tmp){
    printf("%d\n",amida[tmp]);
  }
   
  return 0;
   
}

Measured memory_bytes: 596
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()

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

using namespace std;

#define N 300000
#define LL long long

LL n,m,p,ans,a[N],fa[N];
struct edge{
	LL x,y,c;
	edge(LL x=0,LL y=0,LL c=0):x(x),y(y),c(c){}
	bool operator < (const edge &p) const{return c<p.c;}
}b[N<<5];

LL gfa(LL x){
	return x==fa[x]?x:fa[x]=gfa(fa[x]);
}

void solve(LL l,LL r){
	if (l>=r) return;
	LL mid=(l+r)>>1;
	LL t=0;
	for (LL i=l;i<=mid;++i)
		if (t==0||a[i]+(mid-i)*p<a[t]+(mid-t)*p) t=i;
	for (LL i=mid+1;i<=r;++i) b[++m]=edge(t,i,a[t]+a[i]+(i-t)*p);
	t=0;
	for (LL i=mid+1;i<=r;++i)
		if (t==0||a[i]+(i-mid-1)*p<a[t]+(t-mid-1)*p) t=i;
	for (LL i=l;i<=mid;++i) b[++m]=edge(t,i,a[t]+a[i]+(t-i)*p);
	solve(l,mid); solve(mid+1,r);
}

int main(){
	scanf("%lld%lld",&n,&p);
	for (LL i=1;i<=n;++i) scanf("%lld",a+i);
	solve(1,n);
	sort(b+1,b+m+1);
	for (int i=1;i<=n;++i) fa[i]=i;
	for (LL i=1;i<=m;++i){
		LL x=b[i].x,y=b[i].y; x=gfa(x); y=gfa(y);
		if (x!=y){ans+=b[i].c; fa[x]=y;}
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 230144
/*input 
5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int a[maxn],b[maxn];
ll pref[maxn],pref2[maxn];
int n,m,k;
bool wk(int x){
    REP(i,n+1){
        if((x-i)<=m and x-i>=0 and pref[i]+pref2[x-i]<=k){
            return true;
        }
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n>>m>>k;
    REP1(i,n) cin>>a[i],pref[i]=pref[i-1]+a[i];
    REP1(i,m) cin>>b[i],pref2[i]=pref2[i-1]+b[i];
    int l=0,r=n+m;
    while(l<r){
        int mid=(l+r+1)/2;
        if(wk(mid)) l=mid;
        else r=mid-1;
    }
    cout<<l;
} 


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

ll comb2(ll x){
  return x*(x-1)/2;
}

int main(){
  int n;
  cin >>n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> c(n);
  rep(i,n){
    --a[i];
    ++c[a[i]];
  }
  ll t=0;
  rep(i,n) t+= comb2(c[i]);
  rep(i,n){
    ll ans=t;
    ans-=comb2(c[a[i]]);
    ans+=comb2(c[a[i]]-1);
    printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 4840
x,y,z,q=map(int,input().split())
a=sorted(map(int,input().split()),reverse=True)
b=sorted(map(int,input().split()),reverse=True)
c=sorted(map(int,input().split()),reverse=True)
l=[]
for i in range(x):
  for j in range(y):
    if i*j>q:
      break
    for k in range(z):
      if i*j*k>q:
        break
      l+=[a[i]+b[j]+c[k]]
l.sort(reverse=True)
for w in l[:q]:
  print(w)

Measured memory_bytes: 112348
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    int count1 = 1;
    int count2 = 0;
    char c;
    for (int i = 1; i < 4; i++)
        if (S[0] == S[i])
            count1++;
        else if (c == S[i])
            count2++;
        else {
            c = S[i];
            count2 = 1;
        }
    
    if (count1 == 2 && count2 == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		long[] way = new long[n+1];
		boolean[] broken = new boolean[n+1];
		for(int i=0;i<m;i++) broken[sc.nextInt()]=true;
		for(int i=0;i<=n;i++) way[i]=-1;
		way[0]=1;
		if(broken[1]) way[1]=0;
		else way[1]=1;
		System.out.println(stair(n,broken,way));
	}

	static long stair(int n, boolean[] broken, long[] way) {
		final long mod = 1000000007;
		if(broken[n]) return 0;
		if(way[n]!=-1) return way[n];
		else{
			way[n] = (stair(n-1,broken,way)+stair(n-2,broken,way))%mod;
			return way[n];
		}
	}
}


Measured memory_bytes: 52792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int N;
	int T,A;
	int H[1000];

	scanf("%d",&N);
	scanf("%d %d",&T,&A);
	for(int i=0;i<N;i++){
		scanf("%d",&H[i]);
	}
	int min = 0;
	for(int i=0;i<N;i++){
		if(abs(A-(T-0.006*(double)H[i]))<abs(A-(T-0.006*(double)H[min]))){
			min = i;
		}
	}

	printf("%d\n",min+1);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

ll gcd(ll a, ll b){
    int num1, num2;
    num1 = max(a, b);
    num2 = min(a, b);
    if(num1 % num2  == 0){
        return num2;
    }
    return gcd(num1 % num2, num2);
}

int main() {
    ll A, B, ans;
    cin >> A >> B;
    ans = A * B / gcd(A, B);
    cout << ans << endl;
    
    return 0;
}


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

int main() {
    int k;  cin >> k;
    if (k%2 == 0)  cout << (k/2)*(k/2) << endl;
    else  cout << (k/2)*((k+1)/2) << endl;
}

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

int main(){
	int N,c = 1;
	cin >> N;
	vector<int> H(N);
	for(int i = 0;i <N;i++){
	    cin >> H.at(i);
    }
	bool flag;
    for(int i = 1;i < N;i++){
    	flag = false;
	    for(int j = 0;j<i;j++){
	        if(H.at(i)<H.at(j)){
	            flag = true;
	        }
	    }
	    if(flag == true){
	    	continue;
	    }
	    c += 1;
	}
    cout << c;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int n,k,a[1101];
int main()
{
  scanf ("%d %d",&n,&k);
  for (int i=0;i<n;i++) scanf ("%d",&a[i]);
  sort(a,a+n);
  int r = 0;
  for (int i=0;i<k;i++) r += a[i];
  printf ("%d\n",r);
return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common

typedef int  i32;
typedef long long i64,ll;
typedef long double ld;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(int)l;i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#define NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}
#define nextInt(n) scanf("%d",&n)
#define defInt(n) int n;nextInt(n)
#define nextLong(n) scanf("%lld",&n)
#define defLong(n) ll n;nextLong(n)
#define nextDouble(n) scanf("%lf",&n)

class Main{
public:

    template<typename T,typename S> T ceil(T a,S v){
        return (a+(v-1))/v;
    }
	int N;
	void run(){
	//	ifstream cin("in");
	//	ofstream cout( "out" );	
        vector<ll> dp(31);
        dp[0]=1;
        for(int i=1;i<=30;i++){
            if(i-1>=0)dp[i]+=dp[i-1];
            if(i-2>=0)dp[i]+=dp[i-2];
            if(i-3>=0)dp[i]+=dp[i-3];
        }
        while(true){
            nextInt(N);
			if(N==0)break;

			cout <<ceil(ceil(dp[N],10),365)<<endl;
		}
	}
};
int main(){
	cout <<fixed<<setprecision(13);	
	ios::sync_with_stdio(false);
	Main().run();
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,d,min=LONG_MAX,index=0;
    cin>>n>>m;
    vector<pair<int,int>>v,v1;
    for(int i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    for(int i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        v1.push_back(make_pair(x,y));
    }
    for(int i=0;i<n;i++)
    {
        d=0,min=LONG_MAX;
        for(int j=0;j<m;j++)
        {
            d=abs(v[i].first-v1[j].first)+abs(v[i].second-v1[j].second);
            if(d<min)
            {
                min=d;
                index=j+1;
            }
        }
        cout<<index<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
S1 = [0] * (N+1)
S2 = [0] * (N+1)
for i in range(N):
    S1[i+1] = S1[i] + A1[i]
    S2[i+1] = S2[i] + A2[i]
ans = 0
for i in range(N):
    ans = max(ans,S1[i+1] + S2[-1] - S2[i])
print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{
	static BufferedReader br;
	static int in() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        int[] ar=split();
        int a=ar[0];
        int b=ar[1];
        int c=ar[2];
        int n=in();
        while(n>0 && b<=a)
        {
        	b=b*2;
        	n--;
        }
        while(n>0 && c<=b)
        {
        	c=c*2;
        	n--;
        }
        if(c>b && b>a)
        	System.out.println("Yes");
        else
        	System.out.println("No");
    }
}


Measured memory_bytes: 32596
#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<bool> Bo(1000000, 0);
vector<vector<int>> Dir(1000000);
vector<int> Rev(1000000);
vector<vector<int>> T(1000, vector<int>(1000));

int main(){
	int N, a, f, t, p;
	cin >> N;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < N - 1;j++) {
			cin >> a;
			a--;
			f = min(a, i);
			t = max(a, i);
			p = f * N + t;
			T[i][j] = p;
			Bo[p] = 1;
			if (j) {
				Rev[p]++;
				Dir[T[i][j - 1]].push_back(p);
			}
		}
	}
	int ans = 0;
	queue<int> Q;
	Q.push(-1);
	for (int i = 0;i < 1000000;i++) {
		if (!Bo[i]) continue;
		if (!Rev[i]) {
			Q.push(i);
		}
	}

	while (Q.size() > 1) {
		a = Q.front();
		Q.pop();
		if (a < 0) {
			Q.push(-1);
			ans++;
			continue;
		}
		for (int i : Dir[a]) {
			Rev[i]--;
			if (!Rev[i]) {
				Q.push(i);
			}
		}
		Bo[a] = false;
	}
	for (auto i : Bo)
		if (i)ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 47232
/**
 *      purpose : AISing Programming Contest 2019 A
 *      author  : kyomukyomupurin
 *      created : 
**/

#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, h, w; cin >> n >> h >> w;
    print((n - h + 1) * (n - w + 1));

    
    return 0;
}

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

int f(int x) {
  int r = 0;
  while (x > 0) {
    r += x % 10;
    x /= 10;
  }
  return r;
}

int main(void) {
  int n, a, b;
  std::cin >> n >> a >> b;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = f(i);
    if (a <= x && x <= b) ans += i;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
  return a * b / gcd(a, b);
}

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;

  string s, t;
  cin >> s >> t;

  long long x = lcm(s.size(), t.size());

  map<int, char> m;
  for (int i = 0; i < s.size(); ++i) {
    long long index = i * (x / N) + 1;
    m[index] = s[i];
  }

  for (int i = 0; i < t.size(); ++i) {
    long long index = i * (x / M) + 1;
    if (m.find(index) != m.end() && m[index] != t[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << x << endl;


  return 0;
}

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = "";
		for(int i = 1; i <= n; i++){
			if(i % 3 == 0){
				s += " " + i;
			}else{
				int k = i;
				while(k != 0){
					if(k % 10 == 3){
						s += " " + i;
						break;
					}
					k /= 10;
				}
			}
		}
		System.out.println(s);
	}
}



Measured memory_bytes: 184708
def stackable(pack, tmp_p, k):
  cur_w = 0
  trucks = 1
  for i in range(len(pack)):
    if tmp_p < pack[i]:
      return False

    if cur_w + pack[i] <= tmp_p:
      cur_w += pack[i]
    else:
      cur_w = pack[i]
      trucks += 1

      if k < trucks:
        return False

  return True

n, k = map(int, input().split())
pack = []

for i in range(n):
  pack.append(int(input()))

left = int(sum(pack) / k)
right = max(pack) * n

while left < right - 1:
  tmp_p = int((left + right) / 2)
  if stackable(pack, tmp_p, k):
    right = tmp_p
  else:
    left = tmp_p

if stackable(pack, left, k):
  print(left)
else:
  print(right)


Measured memory_bytes: 9560
n=int(input())
a=list(map(int,input().split()))
a.insert(0,0)

x = [0]*(n+1)
x[1] = sum(a) - 2*sum([a[i] for i in range(n) if i%2==0])
for i in range(2,n+1):
    x[i] = 2*a[i-1] - x[i-1]
x.remove(0)
print(*x)

Measured memory_bytes: 64996
listA=[]
listB=[]
n,m,l=map(int,input().split())
result_vec=[[0]*l for n in range(n)]
for i in range(n):
    listA.append(list(map(int,input().split())))
for i in range(m):
    listB.append(list(map(int,input().split())))
for i in range(n):
    for j in range(l):
        number=0
        for k in range(m):
            number+=listA[i][k]*listB[k][j]
        result_vec[i][j]=number
for n in range(n):
    print(' '.join(map(str,result_vec[n])))



Measured memory_bytes: 6912
#include<stdio.h>
int main(void){
	int a, b, c;
  	scanf("%d %d %d", &a, &b, &c);
  	if((a < c && c < b) || (b < c && c < a)){
    	printf("Yes\n");
    }else{
    	printf("No\n");
    }
  	return 0;
}

Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split( )))
q=int(input())
k=[]
for i in range(q):
    k1=int(input())
    k.append([k1,i])

a.sort()
k.sort()

lwb = [n]*q
upb = [n]*q

i1 = 0 #k,lowwerbound
i2 = 0 #k,upper
j1 = 0 #a,lower
j2 = 0 #a,upper

while i1<q and i2<q and j1<n and j2<n:
    try:
        while k[i1][0] > a[j1]:
            j1 += 1
    except:
        pass
    try:
        while k[i1][0] >= a[j2]:
            j2 += 1
    except:
        pass

    lwb[k[i1][1]] = j1
    i1+=1
    upb[k[i2][1]] = j2
    i2+=1

for i in range(q):
    print(lwb[i],upb[i])


Measured memory_bytes: 48492
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		System.out.println(solve(n));
		in.close();
	}

	private static double solve(int n) {
		return (double)(n / 2 + n % 2) / n;
	}
}

Measured memory_bytes: 23380
program prob42
    implicit none
    character(3) :: s
    read(*,*) s
    if(len_trim(s) == 3)then
        write(*,'(a,a,a)') s(3:3), s(2:2), s(1:1) 
    else
        write(*,'(a)') s
    end if

    stop
contains
end program prob42

Measured memory_bytes: 2852
S = gets.chomp
T = gets.chomp

if S.size < T.size
  puts 'UNRESTORABLE'
  exit 0
end

ans = S.tr('?', '.')
n = T.size
k = S.size - T.size
(k + 1).times do |i|
  re = Regexp.new(ans[-(i + n), n])
  next unless re.match(T)
  ans[-(i + n), n] = T
  ans.tr!('.', 'a')
  puts ans
  exit 0
end

puts 'UNRESTORABLE'


Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>

int main() {
	char str[1001];

	while (1) {
		scanf("%s",str);
		if (str[0] == '0')break;
		int sum = 0;
		for (int i = 0; i < strlen(str); i++) {
			sum += (str[i] - '0');
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 2740