akhauriyash/Code-Regression huggingface dataset:
H, W= map(int, input().split())
minpath = [[float("inf")]*10 for _ in range(10)]
path = [list(map(int, input().split())) for i in range(10)]
for i in range(10):
    for j in range(10):
        for k in range(10):
            path[j][k] = min(path[j][k], path[j][i]+path[i][k])
ans = 0
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        if A[j] == -1 or A[j] == 1:
            continue
        else:
            ans += path[A[j]][1]
print(ans)
            




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

int main() {
	int n, k, r, s, p; cin >> n >> k >> r >> s >> p;
	string t; cin >> t;
	int res = 0;
	int win[n] = {};
	for (int i = 0; i < k; i++)
	{
		if(t[i] == 'r') {
			res += p;
			win[i] = 1;
		}
		else if(t[i] == 's'){
			res += r;
			win[i] = 1;
		}
		else {
			res += s;
			win[i] = 1;
		}
	}
	for (int i = k; i < n; i++)
	{
		if(win[i-k] && t[i] == t[i-k]) continue;
		if(t[i] == 'r') {
			res += p;
			win[i] = 1;
		}
		else if(t[i] == 's'){
			res += r;
			win[i] = 1;
		}
		else {
			res += s;
			win[i] = 1;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<climits>
using namespace std;
int main()
{
	int n, a;
	int min = INT_MAX, max = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(a < min) min = a;
		if(a > max) max = a;
	}
	cout << max - min << endl;
	return 0;
}

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


int main(void)
{
	int A, B, C;
	cin >> A >> B >> C;
	for (int i = 1; i <= B; i++) {
		if ((A*i%B)==C) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

int main(){
int k,a,b;
cin>>k;
cin>>a;
cin>>b;
 int x=b/k;
 int y=x*k;
 if(y>=a && y<=b)
    cout<<"OK";
 else
    cout<<"NG";

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  cout<<fixed<<setprecision(10);
  int ans=0;
  int N;
  cin >> N;
  vector<int> H(N);
  vector<int> high;
  high.push_back(0);
  cin >> H[0];
  for(int i=1; i<N; ++i){
    cin >> H[i];
    if(H[i-1]<H[i]) high.push_back(i-1);
  }
  high.push_back(N-1);
  for(int i=1; i<high.size(); ++i){
    if(ans < high[i]-high[i-1]-1) ans=high[i]-high[i-1]-1;
  }
  if(high.size()==2) ans=N-1;
  cout << ans << endl;
}


Measured memory_bytes: 1276
// GoodDistance.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <cmath>
using namespace std;
int n, m;
int arr[100][100];
double distBetween(int l1, int l2) {
	int sum = 0;
	int k = 0;
	for (int i = 0; i < m; i++) {
		k = pow(arr[l1][i] - arr[l2][i],2);
		sum += k;
	}
	return sqrt(sum);
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> arr[i][j];
			//cout << arr[i][j] << " ";
		}
		//cout << endl;
	}
	int counter = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			double m = distBetween(i, j);
			//cout << m << endl;
			if (floor(m) == ceil(m)) {
				counter++;
			}
		}
	}
	cout << counter << endl;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

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

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

  string s;
  cin >> s;
  string a = "AKIHABARA";
  int dx[] = {0, 4, 6, 8};
  rep(i, 0, 1 << 4) {
    string t = a;
    int cnt(0);
    rep(j, 0, 4) {
      if (i >> j & 1) {
        t.erase(dx[j] - cnt, 1);
        cnt++;
      }
    }
    if (s == t) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
using namespace std;
#define MAX_N 100100

class union_find{
private:
	int parents[MAX_N];
	int rank[MAX_N];
	int weight[MAX_N];
public:
	union_find(){
		for(int i=0;i<MAX_N;i++){
			parents[i]=i;
			rank[i]=0;
			weight[i]=0;
		}
	}
	union_find(int n){
		for(int i=0;i<n;i++){
			parents[i]=i;
			rank[i]=0;
			weight[i]=0;
		}
	}
	int find(int x){
		if(parents[x]==x){
			return x;
		}else{
			int tmp=find(parents[x]);
			weight[x]=weight[x]+weight[parents[x]];
			return parents[x]=tmp;
		}
	}
	void unite(int x,int y,int w){
		int tmpx=find(x);
		int tmpy=find(y);
		if(tmpx==tmpy)return;
		//cout<<"weight list"<<weight[x]<<" "<<weight[y]<<" "<<w<<endl;
		if(rank[tmpx]<rank[tmpy]){
			weight[tmpx]=w-weight[x]+weight[y];
			parents[tmpx]=tmpy;
		}else{
			weight[tmpy]=-w-weight[y]+weight[x];
			parents[tmpy]=tmpx;
			if(rank[tmpx]==rank[tmpy])rank[tmpx]++;
		}
	}
	bool same(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_weight(int x,int y){
		if(find(x)==find(y)){
			//cout<<"get weight "<<weight[x]<<" "<<weight[y]<<endl;
			return weight[x]-weight[y];
		}else{
			return -2000000;
		}
	}
};
int main(){
	char c;
	int a,b,w;
	int n,m;
	while(cin>>n>>m,n!=0||m!=0){
		union_find uf(n+1);
		for(int i=0;i<m;i++){
			cin>>c;
			if(c=='!'){
				cin>>a>>b>>w;
				uf.unite(a,b,w);
			}else if(c=='?'){
				cin>>a>>b;
				if(uf.same(a,b)){
					int tmp=uf.get_weight(a,b);
					if(tmp!=-2000000){
						cout<<tmp<<endl;
					}else{
						return 0;
					}
				}else{
					cout<<"UNKNOWN"<<endl;
				}
			}else{
				cout<<"???"<<endl;
			}
		}
	}
}

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

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    long long ans = numeric_limits<long long>::min();
    ans = max(ans, 1LL * a * c);
    ans = max(ans, 1LL * a * d);
    ans = max(ans, 1LL * b * c);
    ans = max(ans, 1LL * b * d);
    cout << ans;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
int M=998244353,N,K,ans,cnt[303],dp[303][303][303]={1};
int main(){
	string S;cin>>S>>K;K=min((int)S.size(),K);
	for(auto c:S)c=='0'?++N:++cnt[N];
    f(i,0,N) f(j,0,K) f(k,0,j) f(l,-min(k,cnt[i]),K-j) (dp[i+1][j+max(l,0)][k+l]+=dp[i][j][k])%=M;
    f(i,0,K) (ans+=dp[N+1][i][0])%=M;
    cout<<ans;
}

Measured memory_bytes: 58088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int num[] = new int[3];

		num[0] = Integer.parseInt(str[0]);
		num[1] = Integer.parseInt(str[1]);
		num[2] = Integer.parseInt(str[2]);

		Arrays.sort(num);

		int diff = num[2] - num[0] + num[2] - num[1];
		int ans = diff / 2;
		if (diff % 2 == 1)
			ans += 2;

		System.out.println(ans);
	}
}

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll powmod(ll x, ll n) {
  ll result = 1;
  loop(0, n, i) {
    result *= x;
    result %= 1000000007;
  }
  return result;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N; 
  cin >> N;
  ll result = powmod(10, N) - powmod(9, N) - powmod(9, N) + powmod(8, N);
  result %= 1000000007;
  result=(result+DIV)%DIV;
  print(result);
}


Measured memory_bytes: 3648
#include <iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<cmath>

#define LL	long long
using namespace std;
const int MAXN = 2010;
const int MAXA = 1e9;

pair<int, int> A[MAXN];
LL dp[MAXN][MAXN];
int N;
LL ans;

int main() {
	cin >> N;
	memset(dp, 0, sizeof(dp));
	for(int i=1; i<=N; i++) {
		cin >> A[i].first;
		A[i].second = i;
	}
	
	sort(A+1, A+N+1, greater<pair<int,int>>());

	ans = 0;
	for(int k=1; k<=N; k++) {
		int len = N-k+1;
		//printf("len = %d\n", len);
		for(int i=1; i+len-1<=N; i++) {
			int j = i+len-1;
			if(len == 1) {
				ans = max(ans, dp[k-1][i] + 1LL*A[k].first*abs(A[k].second -i));
				continue;
			}
			// left
			dp[k][i+1] = max(dp[k][i+1], dp[k-1][i] + 1LL*A[k].first*abs(A[k].second -i));
			// right
			dp[k][i] = max(dp[k][i], dp[k-1][i] + 1LL*A[k].first*abs(A[k].second-j));
			//printf("f[%d][%d]=%d, f[%d][%d]=%d\n", k, i+1, dp[k][i+1], k, i, dp[k][i]);

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

Measured memory_bytes: 35172
N = int(input())
W = input().split()
abs_min = 100000
for i in range(N):
    W[i] = int(W[i])
for i in range(1,N):
    S_1 = sum(W[0:i])
    S_2 = sum(W[i:N])
    x = abs(S_1 - S_2)
    if abs_min > x:
        abs_min = x
print(abs_min)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
    using namespace std;
     
    #define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl '\n'
     
    int main()
    {
     fastIO();
     long long n , fizbuzsum=0;
    // bool fizbuz = false;
     cin>>n;
     for(int i=1; i<=n; i++)
     {
     	if( (i%3 != 0) && (i%5 != 0) )
     	{
     	//	fizbuz = true;
     		fizbuzsum+=i;
    	 }
     }
    cout<<fizbuzsum<<endl;
    return 0;
    }

Measured memory_bytes: 3624
def main():
    H,W,M = map(int,input().split())
    dict_gyo = {key: 0 for key in range(H)}
    dict_retu = {key: 0 for key in range(W)}
    dict_ichi = {}
    for i in range(M):
        h,w = map(int,input().split())
        dict_gyo[h-1] += 1
        dict_retu[w-1] += 1
        dict_ichi[(h-1,w-1)] = 1

    #print(dict_gyo,dict_ichi)

    maxgyo = max(dict_gyo.values())
    maxretu = max(dict_retu.values())
    #maxgyo_k = max(dict_gyo, key = dict_gyo.get)
    #maxretu_k = max(dict_retu, key = dict_gyo.get)
    #print(maxgyo_k,maxretu_k)
    result = maxgyo + maxretu - 1
    wi = [i for i in range(W) if dict_retu[i] == maxretu]
    for h in [i for i in range(H) if dict_gyo[i] == maxgyo]:
        for w in wi:
            if (h,w) not in dict_ichi:
                result = maxgyo + maxretu
                return result

    return result




print(main())


Measured memory_bytes: 125932
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;
vector<int> p, q, r;

int main() {
    int X, Y, A, B, C, value;
    LL sum = 0;
    cin >> X >> Y >> A >> B >> C;
    for (int i = 0; i < A; i++) {
        cin >> value;
        p.push_back(value);
    }
    for (int i = 0; i < B; i++) {
        cin >> value;
        q.push_back(value);
    }
    for (int i = 0; i < C; i++) {
        cin >> value;
        r.push_back(value);
    }
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    for (int i = 0; i < X; i++) {
        r.push_back(p[i]);
    }
    for (int i = 0; i < Y; i++) {
        r.push_back(q[i]);
    }
    sort(r.begin(), r.end(), greater<int>());
    for (int i = 0; i < X + Y; i++) {
        sum += r[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int n,d,x; cin >> n >> d >> x;
    int count,ans=0;
    rep(i,n){
        int a; cin >> a;
        count = 1;
        REP(j,1,100){
            if(a*j+1<=d) count += 1;
        }
        ans += count;
    }
    cout << ans + x << endl;

    return 0;
}

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

int main(){
  vector<int> v;
  int ans = 0;

  for(int i = 0;i<3;i++){
    int x;
    cin >>x;
    v.push_back(x);
  }

  sort(v.begin(), v.end(),greater<int>());
  cout <<v[0]*10+v[1]+v[2]<<endl;
  return 0;

  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
const int max_n = 1e5;
const ll mod = 1e9+7;
int main(){
  string s; cin >> s;
  bool ok = true;
  int n = s.size();
  int k = (n-1)/2;  k--;
  int t = (n+3)/2;  t--;
  if(n==3){
    if(s[0]!=s[2]) ok = false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  for(int i=0 ; i<n ; i++){
    if(s[i]!=s[n-i-1]) ok = false;
  }
  for(int i=0 ; i<(k)/2 ; i++){
    if(s[i] != s[k-i]) ok = false;
  }
  for(int i=t ; i<n ; i++){
    if(s[i] != s[n-1-(i-t)]) ok = false;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  int ans = 0;
  for(int i = 0;i < a.length();i++){
    ans += a[i] - '0';
  }
  if(ans % 9 == 0){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

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

using namespace std;

int solve(int n, const vector<int> & h)
{
    vector<int> ans(n+1);
    ans[1] = 0;
    ans[2] = abs(h[2] - h[1]);
    
    for (int i = 3; i <= n; i++)
        ans[i] = min(ans[i-1] + abs(h[i] - h[i-1]), ans[i-2] + abs(h[i] - h[i-2]));
    
    return ans[n];
}

int main() {
    int n; cin >> n;
    vector<int> h(n+1);
    for (int i = 1; i <= n; i++)
        cin >> h[i];
        
    int ans = solve(n, h);
    
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;

int n;

int main(){
   scanf("%d",&n);
   printf("%d\n",n/3);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	while(1){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		if(!a) break;
		cout<<max(0,b*c-a+d-1)/d<<endl;
	}
}


Measured memory_bytes: 3112
#include<stdio.h>
int prime[100000];
int c;
int isPrime(int n){
	int i;
	if(n==2)return 1;
	if(n==1)return 0;
	if(!(n%2))return 0;
	for(i=1;i<c;i++){
		if(n==prime[i])return 1;
		if(!(n%prime[i]))return 0;
	}
	for(i=prime[c-1];i<n/2;i+=2)if(!(n%i))return 0;
	return 1;
}
int main(){
	int i,n,count;
	prime[0]=2;
	prime[1]=3;
	prime[2]=5;
	prime[3]=7;
	prime[4]=11;
	c=5;
	for(i=13;i<17000;i+=2){
		if(isPrime(i)){
			prime[c]=i;
			c++;
		}
	}
	for(;scanf("%d",&n)&&n;){
		count=0;
		for(i=0;i<c&&prime[i]<=n/2;i++){
			if(isPrime(n-prime[i]))count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 412
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> a(n);
	vector<int> att(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		att.at(a.at(i) - 1) = i + 1;
	}
	for (int i = 0; i < n; i++) cout << att.at(i) << " ";
	cout << endl;
}

Measured memory_bytes: 4032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] values = ReadInts();
            int X = values[0];
            int Y = values[1];
            Console.WriteLine((X % Y) != 0 ? X : -1);
        }
    }
}


Measured memory_bytes: 11092
n,y=map(int,input().split())
t=0
for i in range(n+1):
    if t==1:
        break
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j) !=y:
            continue
        else:
            print(i,j,n-i-j)
            t +=1
            break
if t==0:
    print(-1,-1,-1)
    

Measured memory_bytes: 40684
A,B = list(map(int,input().split()))

answer = 0
X = A - 1
Y = B
answer = 0
for i in range(1,41):
    cycle = 2 ** i
    qX = X // cycle
    qY = Y // cycle
    rX = X % cycle
    rY = Y % cycle
    oneX = qX * cycle // 2
    oneY = qY * cycle // 2
    if rX >= cycle // 2:
        oneX += rX - cycle // 2 + 1
    if rY >= cycle // 2:
        oneY += rY - cycle // 2 + 1
    one = oneY - oneX

    if one % 2 == 1 :
        answer += 2 ** (i - 1)
    
print(answer)

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

string S;
int K;

int main() {
    cin >> S >> K;

    for(int i = 0; i < S.size(); i++) {
        if(('a' + 26 - S[i]) % 26 <= K) {
            K -= ('a' + 26 - S[i]) % 26;
            S[i] = 'a';
        }
        if(i == S.size() - 1 && K) {
            K %= 26;
            S[i] = (S[i] - 'a' + K) % 26 + 'a';
        }
    }
    cout << S;
}


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

int main()
{
  vector<int> v;
  bool flag = true;
  while(flag)
  {
    int a;
    cin >> a;
    if(a == 0) flag = false;
    else v.push_back(a);
  }
  int i = 1;
  for(auto x: v)
  {
    cout << "Case " << i << ": " << x << endl;
    i++;
  }

  return 0;
}



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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[2][100];
    cin >> n;
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];

    int arr1[101] = {}, arr2[101] = {};
    for (int i = 0; i < n; i++)
    {
        arr1[i + 1] = arr1[i];
        arr1[i + 1] += a[0][i];
        // cout << arr1[i] << " ";
    }
    // cout << arr1[n] << endl;
    for (int i = 0; i < n; i++)
    {
        arr2[i + 1] = arr2[i];
        arr2[i + 1] += a[1][i];
        // cout << arr2[i] << " ";
    }
    // cout << arr2[n] << endl;

    int mx = -1;
    for (int i = 1; i <= n; i++)
    {
        int a1 = arr1[i];
        int a2 = arr2[n] - arr2[i - 1];
        mx = max(a1 + a2, mx);
        // cout << i << " " << a1 + a2 << endl;
    }
    cout << mx << endl;
}


Measured memory_bytes: 256
while True:
    n, l, r = map(int, input().split())
    if n == l == r == 0:
        break
    A = [int(input()) for i in range(n)]
    ans = 0
    for x in range(l, r+1):
        for i in range(n):
            if x % A[i] == 0:
                if i % 2 == 0:
                    ans += 1
                break
            elif i == (n-1):
                if n % 2 == 0:
                    ans += 1
    print(ans)


Measured memory_bytes: 5604
n = int(input())
a = list(input())

l = 0
r = n-1

c = 0

while l < r:
    while l < r and a[l] == 'R': l += 1
    while l < r and a[r] == 'W': r -= 1
    
    if a[l] == 'W' and a[r] == 'R':
        c += 1
        a[l] = 'R'
        a[r] = 'W'

print(c)

Measured memory_bytes: 77428
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>

#include<queue>

using namespace std;

int main() {

	int N, M;
	cin >> N >> M;

	vector<int> vNum(M, 0);

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

	vector<int> vDiff(M - 1, 0);

	sort(vNum.begin(), vNum.end());
	//reverse(vNum.begin(), vNum.end());

	for (int i = 1; i < M; i++)
	{
		vDiff[i - 1] = abs(vNum[i - 1] - vNum[i]);
	}

	sort(vDiff.begin(), vDiff.end());

	int result = 0;
	if (N < M)
	{
		for (int i = 0; i < M - N; i++)
		{
			result += vDiff[i];
		}
	}

	cout << result << endl;

	return 0;
}




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

#define ld			long double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl
#define M_PIl       3.141592653589793238462643383279502884
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);	
   
}

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int N = 2e5+5;
int arr[N], h[N], bit[N];
int n, k;

void solve()
{
	int r;
	cin >> r;
	ld ans = 2*(M_PIl)*r;

	cout << fixed << setprecision(15) << ans << endl;
}			 	

int32_t main(){
	fast();
    int t = 1;
    // cin>> t;
    while(t--){
    	solve();
    }
	starboy1299();
}




Measured memory_bytes: 3800
// AOJ NTL_1_B
#include<cstdio>

typedef long long ll;
const ll mod = 1000000007;

ll powMod( ll m, ll n, ll mod )
{
	ll ret = 1;

	while( n > 0 )
	{
		if( n&1 )
			ret = (ret*m)%mod;

		m = m*m%mod;
		n >>= 1;
	}

	return ret;
}

int main()
{
	ll m, n;
	scanf( "%lld%lld", &m, &n );

	printf( "%lld\n", powMod( m, n, mod ) );

	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>

int min(int x, int y) {
  if (x <= y) return x;
  else return y;
}
int main(void) {
  int H, N, i, j, magic[1010][2], dp[10010];
  if(scanf("%d%d", &H, &N)){};
  for (i = 0; i < 10010; i++) {
    dp[i] = 100000000;
  }
  for (i = 0; i < N; i++) {
    if(scanf("%d%d", &magic[i][0], &magic[i][1])){};
  }
  dp[0] = 0;
  for (i = 1; i < H + 1; i++) {
    for (j = 0; j < N; j++) {
      if (i >= magic[j][0]) dp[i] = min(dp[i - magic[j][0]] + magic[j][1], dp[i]);
      else dp[i] = min(magic[j][1], dp[i]);
    }
  }
  printf("%d", dp[H]);
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n;
int cnt[2][100020];
int fl[100020];
int fr[100020];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        cnt[i % 2][x]++;
    }
    int B = 1e5; int ans = n;
    for (int j = 1; j <= B; j++) fl[j] = max(fl[j - 1], cnt[0][j]);
    for (int j = B; j >= 1; j--) fr[j] = max(fr[j + 1], cnt[0][j]);
    for (int j = 1; j <= B; j++) ans = min(ans, n - max(fl[j - 1], fr[j + 1]) - cnt[1][j]);
    cout << ans << "\n";
    return 0;
}

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

int main() {
    int n, d, cnt = 0;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> x[i][j];
        }
        
    }
    
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int sum = 0;
            for (int k = 0; k < d; k++)
            {
                sum += pow(x[i][k] - x[j][k], 2);
            }
            double ans = sqrt(sum);
            //cout << ans << endl;
            if (ceil(ans) == floor(ans))
                cnt++;
        }
        
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int ret, N, D;
  int num, range;

  ret = scanf("%d %d", &N, &D);
  range = D*2+1;
  num = N / range;
  if ( N%range != 0 )
    num++;
  printf("%d\n", num);

  return 0;
}




Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            WriteLine(s.Where(c => c == '2').Count());
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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

int main (){
        ios_base::sync_with_stdio(0); cin.tie(0);
        //freopen("a.txt", "r", stdin);

        int a,b,c;

        cin>>a>>b>>c;
      //  cout <<a<<b<<c;
        string ans = "No";
        if (a==b && a != c) ans = "Yes";
        if (a==c && a != b) ans = "Yes";
        if (c==b && a != c) ans =  "Yes";

        cout <<ans<< endl;
        return 0;

    }




Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[1001],b,c,d,e,f,i,x=0;
for(i=0;i<1000;i++){
a[i]=0;
}
scanf("%d %d\n",&b,&c);
scanf("%d\n",&d);
for(i=0;i<d;i++){
scanf("%d %d\n",&e,&f);
while(e<f){
a[e]=1;
e++;
}
}
while(b<c){
if(a[b]==1){
x=1;
break;
}
b++;
}
printf("%d\n",x);
return 0;
}


Measured memory_bytes: 1996
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;

int main(){
    string s,t;
    cin >> s >> t;
    G st(26,vector<int>(0));
    vector<int> num(26,0);
    int n=s.size();
    rp(i,n){
        st[s[i]-'a'].push_back(i);
        num[s[i]-'a']++;
    }
    int m=t.size();
    int pos=-1;
    int strs=0;
    rp(i,m){
        int ch=t[i]-'a';
        if(num[ch]==0){
            cout << -1 << endl;
            return 0;
        }
        if(st[ch].back()<=pos){
            pos=st[ch][0];
            strs++;
            continue;
        }
        auto it=upper_bound(st[ch].begin(),st[ch].end(),pos);
        pos=*it;
    }
    cout << (ll)n*(ll)strs+(ll)pos+(ll)1 << endl;
    return 0; 
}

Measured memory_bytes: 1216
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	// 2018/05/29
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		String s[] = new String[N];
		for (int i=0; i<N; i++) {
			s[i] = sc.next(); 
		}
		Arrays.sort(s);
		for (int i=0; i<N; i++) {
			System.out.print(s[i]); 
		}
	}
}


Measured memory_bytes: 21972
#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;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll val,val1,val2,val3;
    val=a*d;
    val1=a*c;
    val2=b*c;
    val3=b*d;
    cout<<max({val,val1,val2,val3})<<endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define ppll pair<ll, pll>
#define pii pair<int, int> 
#define mod 998244353
#define pb push_back
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
bool cmp(pll a,pll b){
    return a.se<b.se;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    string str;
    cin>>str;
    if(n%2!=0){
        cout<<"No";
        return 0;
    }
    ll len=n/2;
    for(int i=0;i<n/2;i++){
        if(str[i]!=str[i+len]) {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
constexpr int mod = 100000;
constexpr int MAX_N = 50;
constexpr int MAX_S = 3010;
constexpr int MAX_M = 2010;
typedef long long LL;
int main(){
int N[5],M[5],S[5];
int ret[5];
LL dp[MAX_S][MAX_N];
vector<int> query[MAX_M];
int q=0;
for(q=0;;q++){
scanf("%d%d%d",N+q,M+q,S+q);if(N[q]+M[q]+S[q]==0)break;
query[M[q]].push_back(q);
}
for(int i=0;i<MAX_S;i++)for(int j=0;j<MAX_N;j++)dp[i][j]=0;
dp[0][0]=1;
for(int i=1;i<MAX_M;i++){
for(int j=MAX_S-1;j>=i;j--)for(int k=1;k<MAX_N;k++){
  dp[j][k]+=dp[j-i][k-1];
  if(dp[j][k]>=mod)dp[j][k]-=mod;
}
for(auto &id:query[i])ret[id] = (int)dp[S[id]][N[id]*N[id]];
}
for(int i=0;i<q;i++)printf("%d\n",ret[i]);
return 0;
}


Measured memory_bytes: 4412
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI as(n);
  FOR(a,as) {
    cin >> a;
  }
  vector<VI> include(20);
  REP(i,0,n) {
    REP(b,0,20) {
      if(((as[i] >> b) & 1) != 0) {
        include[b].push_back(i);
      }
    }
  }
  ll ans = 0;
  int first = -1;
  REP(i,0,n) {
    REP(b,0,20) {
      if(((as[i] >> b) & 1) != 0) {
        auto lb = lower_bound(include[b].begin(), include[b].end(), i);
        if(lb != include[b].begin()) {
          first = max(first, *(lb-1));
        }
      }
    }
    ans += i - first;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 9032
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
string find_ans(int n,vector<int>& v,string s)
{
    if(n==1)
    {
        if(v[0]%2==0)
        {
            return s;
        }
        else{
            if(s=="First")
            return "Second";
            else
                return "First";
        }
    }
    int e=0;
    int o=0;
    for(auto c:v)
    {
        if(c%2==0)
            e++;
        else
            o++;
    }
    if(e==1 || e%2!=0)
    {
        return s;
    }
    else if(e%2==0 && o>1){
        if(s=="First")
            return "Second";
        else
            return "First";
    }
    else{
        int g=v[0];
        for(auto &c:v)
        {
            if(c&1)
                c-=1;
        }
        for(auto c:v)
        {
            g=gcd(g,c);
        }
        for(auto &c:v)
        {
            c=c/g;
        }
        if(s=="First")
            s="Second";
        else
            s="First";
        return find_ans(n,v,s);
    }
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    cout<<find_ans(n,v,"First")<<endl;
    return 0;
}

Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define inf 1e9
int solve(vector<int> v,int n)
{
    vector<int> dp(n+1);
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        int op1=abs(v[i]-v[i-1])+dp[i-1];
        int op2=(i==2)?inf:abs(v[i]-v[i-2])+dp[i-2];
        dp[i]=min(op1,op2);
    }
    return dp[n];
}
signed main()
{
    int n;
    cin>>n;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++)
        cin>>v[i];
    cout<<solve(v,n)<<endl;
}

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

const int sq = 30000;
int ans = 0, n;

int sg(int x, int k) {
	if (x % k == 0)return x / k;
	if (x / k > sq)return sg(x - x / k - 1, k);
	else {
		int m1 = x % k;
		return sg(x - max(x / k + 1, m1 - m1 % (x / k + 1)), k);
	}
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, k;
		scanf("%d%d", &x, &k);
		ans ^= sg(x, k);
	}
	cout << (ans ? "Takahashi" : "Aoki") << endl;

	return 0;
}


Measured memory_bytes: 256
class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True


N, M = map(int, input().split())
uf = UnionFindEx(N)

for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    uf.connect(x, y)

print(len(set([uf.getRootID(i) for i in range(N)])))
    



Measured memory_bytes: 13992
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vvl c(n, vl(3));
    rep(i, n) {
        rep(j, 3) {
            cin >> c[i][j];
        }
    }
    
    ll ans = -INF;
    rep(b, 1<<3) {
        vl v(n);
        rep(i, n) {
            rep(j, 3) {
                if(b & (1<<j)) {
                    v[i] += c[i][j];
                }
                else {
                    v[i] += -c[i][j];
                }
            }
        }
        sort(rall(v));
        ll now = 0;
        rep(i, m) {
            now += v[i];
        }
        chmax(ans, now);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
 
/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 
 
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
 
/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;
 
/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
/* func */
int gcd(int a,int b){return b?gcd(b,a%b):a;}
 
/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
 
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
 
//#define int ll
//#define int long long
 
signed main()
{
 int a, b, k; cin >> a >> b >> k;
  int cnt = 0;
  vi v1(0);
  int whi = max(a,b);
  for(int i =1; i <= whi; ++i){
    if((a%i == 0)&&(b%i == 0)){
     v1.PB(i);
      ++cnt;
    }
  }
/*for(int i = 1; i <= whi; ++i){
  cout << a%i;
  cout << b%i << endl;
}*/
  

  reverse(ALL(v1));
//    REP(i, cnt){cout << v1[i] << endl;}
  
  cout << v1[k-1];
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 998244353 ;
const ld pi=3.1415926535897932384626433;
const ll inf = 1e18;
bool isprime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}

ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll sol=a>b?a:b;return sol;}
ll min(ll a,ll b){ll sol=a<b?a:b;return sol;}
int main ()
{
   bolt;
   ll n,m;
   cin>>n>>m;
   ll ans=n*(n-1)/2;
   ans+=m*(m-1)/2;
   cout<<ans;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();

        if(D==25) System.out.println("Christmas");
        else if(D==24) System.out.println("Christmas Eve");
        else if(D==23) System.out.println("Christmas Eve Eve");
        else if(D==22) System.out.println("Christmas Eve Eve Eve");
        
    }
}

Measured memory_bytes: 20692
import numpy as np

from numba import njit


@njit("i8[:](i8, i8[:], i8[:])", cache=True)
def cumsum(K, L, cL):
    for i, a in enumerate(L):
        cL[i] = cL[i - 1] + L[i]
        if cL[i] > K:
            cL[i] = 0
            break

    cL = cL[cL != 0]
    cL = np.append(0, cL)
    return cL


@njit("i8(i8, i8[:], i8[:])", cache=True)
def solve(K, A, cB):
    ans_max = 0
    for i, a in enumerate(A):
        ans = 0
        K -= a
        ind = np.searchsorted(cB, K, side="right") - 1
        ans = i + ind

        if ans > ans_max:
            ans_max = ans

        if ind == 0 or K < 0:
            break

    return ans_max


N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)

cA = np.zeros(N, dtype=np.int64)
cB = np.zeros(M, dtype=np.int64)

# np.cumsumだとoverflowする
cA = cumsum(K, A, cA)
cB = cumsum(K, B, cB)

A = np.append(0, A)
ans = solve(K, A, cB)
print(max(ans, len(cA) - 1, len(cB) - 1))


Measured memory_bytes: 133372
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int l[2010][2010], r[2010][2010], u[2010][2010], d[2010][2010];

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto &e : s)
    cin >> e;

  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if (s[i][j] == '#')
        l[i][j] = 0;
      else
      {
        if (j == 0)
          l[i][j] = 1;
        else
          l[i][j] = l[i][j - 1] + 1;
      }
    }
  }

  for (int i = 0; i < h; ++i)
  {
    for (int j = w - 1; j >= 0; --j)
    {
      if (s[i][j] == '#')
        r[i][j] = 0;
      else
      {
        if (j == w - 1)
          r[i][j] = 1;
        else
          r[i][j] = r[i][j + 1] + 1;
      }
    }
  }

  for (int j = 0; j < w; ++j)
  {
    for (int i = 0; i < h; ++i)
    {
      if (s[i][j] == '#')
        d[i][j] = 0;
      else
      {
        if (i == 0)
          d[i][j] = 1;
        else
          d[i][j] = d[i - 1][j] + 1;
      }
    }
  }

  for (int j = 0; j < w; ++j)
  {
    for (int i = h - 1; i >= 0; --i)
    {
      if (s[i][j] == '#')
        u[i][j] = 0;
      else
      {
        if (i == h - 1)
          u[i][j] = 1;
        else
          u[i][j] = u[i + 1][j] + 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 67456