akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict

s = list(map(str, input().rstrip()))
k = int(input())
connection = False

if all([x == s[0] for x in s]):
    print(len(s) * k // 2)
    sys.exit()

cnt = 0
if s[0] == s[-1] and k != 1:
    connection = True
    cnt = 2
    start = 1
    goal = 1
    x = s[0]

    for i in s[1:]:
        if i == x:
            cnt += 1
            start += 1
        else:
            break

    for i in s[:-1][::-1]:
        if i == x:
            cnt += 1
            goal += 1
        else:
            break

d = defaultdict(int)

if connection:
    ss = s[:start]
    sg = s[-goal:]
    s = s[start:-goal]
    
prev = s[0]
tmp = 1
for i, x in enumerate(s[1:]):
    if prev == x and i == (len(s) - 2):
        tmp += 1
        d[tmp] += 1
    elif prev == x:
        tmp += 1
    else:
        d[tmp] += 1
        prev = x
        tmp = 1

if connection:
    d[cnt] += 1

ans = 0
for key, val in d.items():
    if key == 1:
        continue
    else:
        ans += key // 2 * val * k

if connection:
    ans -= cnt // 2
    ans += len(ss) // 2 + len(sg) // 2

print(ans)

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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;

    for (int i = 0; i < n -2; i++) {
        if (s.substr(i,3) == "ABC")
            ans++;
    }

    cout << ans << '\n';

    return 0;
    
}

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

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


N = int(input())

# 正の整数iに対して、iの倍数でありN以下であるものの総和をg(i)とおくと、
# 求めたい\sum_{K=1}^{N} K * f(K)は、
# \sum_{K=1}^{N} K * f(K) = \sum_{K=1}^{N} g(K)
# で与えられる。
# ここで、kをN/i以下の最大の整数とおくと、g(i)は、
# g(i) = i + 2 * i + 3 * i + ... + k * i = (1 + 2 + 3 + ... + k) * i
# = k * (k + 1) * i / 2 (等差数列の和)
# で与えられる。


def g(i):
    k = N // i
    return k * (k + 1) * i // 2


res = 0
for i in range(1, N+1):
    res += g(i)
print(res)


Measured memory_bytes: 74908
#include<iostream>
#include<string>

using namespace std;

typedef long long ll;

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int ans = 1;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != s[i - 1])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll n;cin>>n;
        n=n%1000;
        n=(1000-n)%1000;
        cout<<n;
        return 0;


}


Measured memory_bytes: 3612
# include"stdio.h"

int main(){
    char w[101];
    scanf("%s",w);
    int a[26];
    for(int i=0;i<26;i++)
        a[i]=0;
    for(int i=0;i<101;i++){
        if(w[i]=='\0')    break;
        for(int j=0;j<26;j++){
            if(w[i]=='a'+j)    a[j]++;
        }
    }

    for(int i=0;i<26;i++){
        if(a[i]%2==1){
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");


}


Measured memory_bytes: 128
package main

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

var (
	BufferSize = 100
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	r := scanInt(sc)
	ans := r * r
	fmt.Println(ans)
}


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

int main()
{
  int n; cin >> n;
  vector<int> a(n, 0);
  rep(i, n) cin >> a[i];

  int ans = 0;
  rep(i, n) {
    int minj = i;
    for (int j=i; j<n; j++) {
      if (a[j] < a[minj]) minj = j;
    }
    if (i < minj) ans++;
    swap(a[i], a[minj]);
  }
  rep(i, n) {
    if (i == 0) cout << a[i];
    else cout << " " << a[i];
  }
  cout << endl;
  cout << ans << endl;

  return 0;
}



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

#define ll long long

ll dp[101][101*1005];
int vis[101][101*1005];
int w[101],v[101];
int ii,n;
ll capacity;

ll func(int pos,int lav)
{
    if(lav<=0) return 0;

    if(pos==n) return (lav<=0)?0:1e12;

    if(vis[pos][lav]==ii)return dp[pos][lav];

    vis[pos][lav]=ii;

    return dp[pos][lav]=min(func(pos+1,lav),w[pos]+func(pos+1,lav-v[pos]));

}




int main()
{
   scanf("%d%lld",&n,&capacity);

   for(int i=0;i<n;i++)scanf("%d%d",w+i,v+i);

   int lo=0,high=100*1000,ans=0;

   while(lo<=high)
   {
       int mid=(lo+high)/2;

       ii++;

       if(func(0,mid)<=capacity)
       {
           ans=mid;
           lo=mid+1;
       }
       else high=mid-1;
       //cout<<func(0,mid)<<endl;
   }

   printf("%d\n",ans);

   return 0;
}



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

using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int j;
        j = A[i] - 1;
        if (A[j] - 1 == i) {ans++;}
    }
    cout << ans/2 << endl;



    return 0;
}


Measured memory_bytes: 640
n = int(input())
xl = []
lr = []
for _ in range(n):
    x, l = map(int, input().split())
    xl.append([x, l])
    lr.append([x-l, x+l])

lr.sort(key=lambda x: x[1])

ans = 0
r = -float("inf")
for i in range(n):
    if r <= lr[i][0]:
        ans += 1
        r = lr[i][1]

print(ans)


Measured memory_bytes: 37924
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

int main() {
    int k, x;
    cin >> k >> x;

    for (int i = x - k + 1; i < x + k; i++) {
        cout << i << endl;
    }
}


Measured memory_bytes: 256
import sys
import bisect
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ls = []
    cnt = 1
    for i in range(1, n):
        if s[i] != s[i-1]:
            ls.append(cnt)
            cnt = 0
        cnt += 1
    ls.append(cnt)

    wc = 0
    b = True if s[0] == "1" else False
    fb = True if s[0] == "1" else False
    cnt = 0
    pos = 0
    m_cnt = 0
    for i in range(len(ls)):
        if not b:
            wc += 1
        if wc > k:
            cnt -= ls[pos]
            pos += 1
            if fb:
                cnt -= ls[pos]
                pos += 1
            else:
                fb = not b
            wc -= 1
        b = not b
        cnt += ls[i]
        m_cnt = max(m_cnt, cnt)
    print(m_cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 71020
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
using namespace std;
int main()
{
	for (int i=1;i<=5;++i)
	{
		if (getchar()=='0')
		{
			putchar(i+'0');
			return 0;
		}
		getchar();
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAX 100005
int N;
int a[MAX], b[MAX];
char f[MAX];

char notPrime[MAX] = { 1,1,0,0,1 };
void sieve(int max)
{
	int i, j, b = (int)sqrt(max);
	for (i = 2; i < max; i += 2) notPrime[i] = 1;
	for (i = 3; i <= b; i += 2) {
		if (!notPrime[i]) {
			for (j = i * i; j < max; j += i) notPrime[j] = 1;
		}
	}
}

int cmp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main()
{
	int i, j, k, max;

	scanf("%d", &N);
	max = 0;  for (i = 0; i < N; i++) {
	    scanf("%d", &k);
		a[i] = b[i] = k;
		f[k] = 1;
		if (max < k) max = k;
	}
	qsort(b, N, sizeof(int), cmp);

	sieve(++max);
	for (i = N - 1; i >= 0; i--) {
		if (!notPrime[b[i]] && a[i] != b[i]) {
			for (j = b[i] << 1; j < max; j += b[i]) if (f[j]) break;
			if (j >= max) { puts("0"); return 0; }
		}
	}
	puts("1");
	return 0;
}


Measured memory_bytes: 2864
#include<iostream>
using namespace std;
int main(){
    int A[5][4][11], n;
    for(int i=1;i<=4;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=10;k++){
                A[i][j][k]=0;
            }
        }
    }
    cin>>n;
    for(int i=0;i<n;i++){
        int b,f,r,v;
        cin>>b>>f>>r>>v;
        A[b][f][r]+=v;
    }
    for(int f=1;f<=4;f++){
        if(f>1) cout<<"####################"<<endl;
        for(int b=1;b<=3;b++){
            for(int r=1;r<=10;r++){
                cout<<" "<<A[f][b][r];
            }
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
int a[500],i;char c[50];
int main(){scanf("%s",c);int l=strlen(c)+1;for(i=0;i<l-1;a[c[i++]]=1);for(i='z';i>='a';i--)if(!a[i])c[l++]=i;return std::next_permutation(c,c+l)?!printf("%s",c):!printf("-1");}


Measured memory_bytes: 256
from heapq import*
i=input
for s in[0]*int(i()):
 n,x,*y=int(i()),[]
 for _ in'_'*n:k,l,r=t=[*map(int,i().split())];x+=[t]*(l>r);y+=[[n-k,r,l]]*(l<=r)
 for x in x,y:
  h=[]
  for k,l,r in sorted(x):
   s+=l;heappush(h,l-r)
   if len(h)>k:s-=heappop(h)
 print(s)

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

using namespace std;
const static int TEAM_MAX = 100;

struct winp_data {
  int team_id;
  int point;
};
bool operator < ( const winp_data &wp1, const winp_data &wp2 ) {
  if( wp1.point == wp2.point ) {
    return wp1.team_id < wp2.team_id;
  } 
  return wp1.point < wp2.point;
}

int main() {
  int n;
  winp_data win_p [ TEAM_MAX ];
  int rank_data[ TEAM_MAX ];
  cin >> n;
  for( int i = 0; i < n; i++ ) {
    win_p[ i ].team_id = i + 1;
    win_p[ i ].point = 0;
  }
  int combinum = n * ( n - 1 ) / 2;
  for( int i = 0; i < combinum; i++ ) {
    int a, b, ap, bp;
    cin >> a >> b >> ap >> bp;
    if( ap > bp ) {
      win_p[ a - 1 ].point += 3;
    } else if( ap == bp ) {
      win_p[ a - 1 ].point += 1;
      win_p[ b - 1 ].point += 1;
    } else {
      win_p[ b - 1 ].point += 3;
    }
  }

  sort( win_p, win_p + n );
  int rank = 1;
  int frank = 1;
  int prev_p = -1;
  for( int i = n - 1; i >= 0; i-- ) {
    if( prev_p != win_p[ i ].point ) {
      rank = frank;
    }
    frank++;
    rank_data[ win_p[ i ].team_id - 1 ] = rank;
    prev_p = win_p[ i ].point;
  }

  for( int i = 0; i < n; i++ ) {
    cout << rank_data[ i ] << endl;
  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> stu(n);
    vector<pair<int, int>> vec(m);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        stu[i] = make_pair(a, b);
    }
    rep(i, m) {
        int c, d;
        cin >> c >> d;
        vec[i] = make_pair(c, d);
    }


    for (int i=0; i<n; i++){
        int mini = abs(stu[i].first - vec[0].first) + abs(stu[i].second - vec[0].second);
        int index=1;
        for(int j=0; j<m; j++){
            int num = abs(stu[i].first - vec[j].first) + abs(stu[i].second - vec[j].second);
            if(mini > num) {
                index = j+1;
                mini = num;
            }
        }
        cout << index << endl;
    }
}

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

int visited[1000001];

bool printDivisors(int n)
{
    if (visited[n] > 1)
    {
        return false;
    }

    for (int i=2; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if(visited[i] > 0 || visited[n/i] > 0)
                return false;
        }
    }

    return true;
}

int main()
{
    int n;
    cin>>n;
    int arr[n];
    int ans=0;

    for(int i=0;i<1000001;i++)
    {
        visited[i]=0;
    }

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

    if(visited[1]==1)
    {
        cout<<"1";
        return 0;
    }

    if(visited[1]>1)
    {
        cout<<"0";
        return 0;
    }

    for(int i=0;i<n;i++)
    {
        if(printDivisors(arr[i]))
        {
            ans++;
        }
    }

    cout<< ans;
    return 0;
}


Measured memory_bytes: 8308
S = list(input())
num_cnt = len(S) - 1
total = 0

for i in range(2 ** num_cnt):
    temp_sum = S[0]
    for j in range(num_cnt):
        if ((i >> j) & 1):
            temp_sum = temp_sum + '+' + str(S[j+1])
        else:
            temp_sum = temp_sum  + S[j+1]
    total += eval(temp_sum)

print(total)

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

int main(){
    int A,C,D=0;
    cin >> A;
    int B[A];
    for(int i=0;i<A;i++)cin >> B[i];
    for(int j=0;j<A;j++){
        if(B[j]%2==0){
            C++;
            if((B[j]%3==0)||(B[j]%5==0)){
                D++;
            }
        }
    }
    if(C==D){
        cout << "APPROVED" << "\n";
    }else{
        cout << "DENIED" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
def md(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


N, M = map(int, input().split())
P = [tuple(map(int, input().split())) for _ in range(N)]
C = [tuple(map(int, input().split())) for _ in range(M)]
ANS = []

for p in P:
    min_c = None
    min_d = float('inf')
    for c in C:
        d = md(p, c)
        if d < min_d:
            min_c = c
            min_d = d
    ANS.append(min_c)

print(*[C.index(c) + 1 for c in ANS], sep='\n')


Measured memory_bytes: 3064
x, n = map(int, input().split())
lst = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
lst.sort()
container = []
store = []
d = []
lst_num = list(range(0, lst[-1] + 2))


for i in lst_num:
    base = lst_num.index(x)
    if i not in lst:
        container.append(i)
for y in container:
    if y < x:
        store.append(y)
    else:
        d.append(y)
if x - max(store) <= min(d) - x:
    print(max(store))
else:
    print(min(d))

Measured memory_bytes: 9148
a,b,c,d,e,f=map(int,input().split())
l_water=set()
for i in range(f//(a*100)+1):
    for j in range(f//(b*100)+1):
        tmp=i*a*100+j*b*100
        if 0<tmp<=f:l_water.add(tmp)
l_sugar=set()
max_s=max(l_water)//100*e
for i in range(max_s//c+1):
    for j in range(max_s//d+1):
        tmp=i*c+j*d
        if 0<=tmp<=max_s:l_sugar.add(tmp)
ans=[0,a*100,0]
for i in l_water:
    for j in l_sugar:
        if j<=i//100*e and i+j<=f:
            tmp=j/(i+j)
            if tmp>ans[0]:
                ans=[tmp,i+j,j]
print(*ans[1:])

Measured memory_bytes: 3188
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
s_xy = set(xy)

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        ix, iy = xy[i]
        jx, jy = xy[j]
        p, q = jx - ix, jy - iy
        tc = sum((x-p,y-q) in xy for x, y in s_xy)

        count = max(count, tc)

print(n-count)


Measured memory_bytes: 3064
def main():
  a, v = map(int,input().split())
  b, w = map(int,input().split())
  t = int(input())
  ans = True

  if v - w < 0: 
    ans  = False
  elif (v - w) * t >= abs(a - b):
    ans = True
  else:
    ans = False
      
  if ans:
    print("YES")
  else:
    print("NO")            


main()


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

using namespace std;

bool check(int& n){
	int a = n % 10;
  	int b = (n / 10) % 10;
  	int c = (n / 100) % 10;
  	return a == b && b == c;
}

int main(){
	ios_base::sync_with_stdio (false);
    cout << fixed;
    cout.precision(10);
	int n;
  	cin >> n;
	while(true){
		if(check(n)){
			cout << n;
			break;
		}
		++n;	
    }
    return 0;
}


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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  long long seven = 0, k, cnt = 0;
  cin >> k;
  vector<int> table(k, 0);
  do {
    cnt++;
    seven = seven * 10 + 7;
    seven %= k;
    if (table[seven]) {
      cout << -1 << endl;
      return 0;
    } else {
      table[seven] = 1;
    }
  } while (seven);
  cout << cnt << endl;
}


Measured memory_bytes: 7228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin >> n;
  long long con=0;
  long long ans=0;
  for(long long a=2;a*a<=n;++a){
    if(n%a!=0) continue;
    con =0;
    while(n%a==0){
      con++;
      n/=a;
      
      }
      for(int j=1;con >= j;j++){
        con -= j;
        ans++;
      
    }
    
  }
  if(n >1) ans++;
  cout << ans << endl;
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int a[N];
set<int> s;
map<int, ll> mp, ways;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        mp[a[i]]++;
        s.insert(a[i]);
    }
    ll tot = 0;
    for (auto i : s) {
        ll x = mp[i] * (mp[i] - 1) / 2;
        ways[i] = x;
        tot += x;
    }
    for (int i = 0; i < n; i++) {
        ll x = tot - ways[a[i]];
        ll y = mp[a[i]] - 1;
        ll z = y * (y - 1) / 2;
        cout << x + z << '\n';
    }
    return 0;
}


Measured memory_bytes: 24064
require 'enumerator'

loop do
  line1 = gets.chomp
  break if line1 =="0"
  a=0
  b=0
  line1.split("").each_cons(2) do |arr|
    if arr[1]=="A"
      a+=1
    else
      b+=1
    end
  end
  line2 = gets.chomp
  if(line2.split("")[0]=="A")
    a+=1
  else
    b+=1
  end
  puts a.to_s+" "+b.to_s
  a=0
  b=0
  line2.split("").each_cons(2) do |arr|
    if arr[1]=="A"
      a+=1
    else
      b+=1
    end
  end
  line3 = gets.chomp
  if(line3.split("")[0]=="A")
    a+=1
  else
    b+=1
  end
  puts a.to_s+" "+b.to_s
  a=0
  b=0
  line3.split("").each_cons(2) do |arr|
    if arr[1]=="A"
      a+=1
    else
      b+=1
    end
  end
  if a>b
    a+=1
  elsif b>a
    b+=1
  end
  puts a.to_s+" "+b.to_s
end

Measured memory_bytes: 2380
<?php
  
while ($line = fgets(STDIN)) {
   $stdin[] = trim($line);
}
#$v2 = str_split($stdin[0]);
#$v2 = explode(" ", $stdin[0]);

#dream dreamer erase eraser

$nums = explode(" ", $stdin[1]);

$max = max($nums);

#var_dump($max);

$v = 0;
for($i = 0; $i < count($nums); $i++){
  $v = $v + ($max / $nums[$i]);
}

#var_dump($v);

$ans = $max / $v;

echo $ans . PHP_EOL;





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

int main()
{
  int n, m, l, k = 0;
  int A[101][101], B[101][101];
  long int C[101][101];
  for (int i = 0; i < 101; i++)
  {
    for (int j = 0; j < 101; j++)
    {
      C[i][j] = 0;
    }
  }
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < l; j++)
    {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < l; j++)
    {
      for (int k = 0; k < m; k++)
      {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < l; j++)
    {
      if (j == (l - 1))
      {
        cout << C[i][j] << endl;
      }
      else
      {
        cout << C[i][j] << " ";
      }
    }
  }
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int c = 0;
    for (int i = 0; i < s.length(); i++) {
        if (i + i < s.length()) {
            if (s[i] == 'p') c--;
        } else {
            if (s[i] == 'g') c++;
        }
    }
    cout << c;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<iterator>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#define lli long long int
#define mp make_pair
#define ULTRA_INSTINCT ios_base::sync_with_stdio(false); cin.tie(0)
#define PI  3.141592653589793
#define fo(i,n) for(lli i=0;i<(n);i++)
#define FO(i,x,n) for(lli i=(x);i<(n);i++)
#define pb push_back
#define FI first
#define SE second
#define vi vector<lli>
#define pi pair<lli,lli>
#define vii vector<pi >
#define Endl endl
#define ITA 200005
#define ROH 100005
using namespace std;
lli mod = 1e9 +7,test; 
lli max(lli a,lli b){return a>b?a:b;}
lli min(lli a,lli b){return a>b?b:a;}

lli gcd(lli a, lli b) { 
   if (b == 0) return a; 
   return gcd(b, a % b);  
} 
lli n,m;
vi g[ROH];
vi dp(ROH,-1);
lli dfs(lli curr){
  if(dp[curr] != -1){
    return dp[curr];
  }
  dp[curr] = 0;
  for(lli to : g[curr]){
    dp[curr] = max(dp[curr] , dfs(to));
  }
  dp[curr] +=1;
  return dp[curr];
}

void solve(){
cin>>n>>m;
lli l,r;
fo(i,m){
  cin>>l>>r; --l , --r;
  g[l].pb(r);
}
lli maxi = 0;
fo(i,n){
  if(dp[i]== -1){
      maxi = max(maxi , dfs(i));
  }
}
cout<<maxi-1<<endl;

}

int main(){
    ULTRA_INSTINCT;
    lli t =1;
    // cin>>t;
    fo(i,t){
        solve();
    }
    return 0;

}

Measured memory_bytes: 8576
// input macro
// ref: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_mut)]
fn main() {
    input!(
        n: usize,
        q: usize,
        coms: [(usize, usize, usize); q],
    );

    let mut uf = UnionFind::new(n);
    for (com, x, y) in coms {
        if com == 0 {
            uf.unite(x, y);
        } else {
            let tf = uf.same(x, y);
            if tf {println!("1")} else {println!("0")};
        }
    }
}

pub struct UnionFind {
    parent: Vec<usize>,
    rank: Vec<usize>,
    size: usize,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).map(|i| i).collect::<Vec<usize>>(),
            rank: vec![1; n],
            size: n,
        }
    }

    pub fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        }
        else {
            let px = self.parent[x];
            self.parent[x] = self.find(px);
            self.parent[x]
        }
    }

    pub fn unite(&mut self, x: usize, y:usize) -> bool {
        if self.find(x) == self.find(y) {
            return false;
        }
        else {
            let parx = self.find(x);
            let pary = self.find(y);
            if self.rank[x] < self.rank[y] {
                self.parent[parx] = pary;
            }
            else if self.rank[x] > self.rank[y] {
                self.parent[pary] = parx;
            }
            else {
                self.parent[pary] = parx;
                self.rank[x] += 1;
            }

            return true;
        }
    }

    pub fn same(&mut self, x: usize, y: usize) -> bool {
        let parx = self.find(x);
        let pary = self.find(y);
        if parx == pary {
            return true;
        } else {
            return false;
        }
    }



}


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

#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define endl "\n"
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

int main()
{
    IOS;
    ll t,k,n,d,m,u,v;
    t=1;
    //cin >> t;
    while(t--)
    {
        cin >> n;
        vector<pair<ll,ll>> v(n);
        vector<ll> b(n);
        vector<ll> a(n);
        for(int i=0;i<n;i++)
        {
            cin >> v[i].first >> v[i].second;
            b[i]=v[i].first+v[i].second;
            a[i]=v[i].first-v[i].second;
        }
        sort(all(b));
        sort(all(a));
        ll ans1 = abs(b[0]-b[n-1]);
        ll ans2 = abs(a[0]-a[n-1]);
        ll ans = max(ans1,ans2);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 9520
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

# UnionFind
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.parent[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

N, K, L = map(int, input().split())
un1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    un1.unite(p, q)
un2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    un2.unite(r, s)
dic = defaultdict(int)
for i in range(N):
    a, b = un1.root(i), un2.root(i)
    k = str(a)+":"+str(b)
    dic[k] += 1

ans = [0]*N
for i in range(N):
    a, b = un1.root(i), un2.root(i)
    k = str(a)+":"+str(b)
    ans[i] = dic[k]
print(*ans)


Measured memory_bytes: 157048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;



int main() {
  ll n,k;
  cin >> n >> k;
  while(n>k/2) {
    if(n<=k) {
      n=k-n;
    }
    else {
      ll c=n/k;
      n=n-c*k;
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

#define MAXN 100500

using namespace std;

int n,k;
int minim;
int h[MAXN];
int ans[MAXN];
int ogr;

int main(){

	cin >> n >> k; 

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

	cin >> h[i];

}	

ans[1] = 0;
ans[2] = abs(h[1] - h[2]);

for (int i = 3; i <= n; i++){
	
	if (i < k) ogr = i;
	
	else ogr = k;

	minim = ans[i - 1] + abs(h[i] - h[i - 1]);

	for (int j = 1; j <= ogr; j++){

		if (i == j) continue;

		ans[i] = ans[i - j] + abs(h[i] - h[i - j]);
		
		if (ans[i] < minim) minim = ans[i]; 	
		 
	}

	ans[i] = minim;

}

cout << ans[n];

}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int N;
    std::cin>>N;
    int a[N];
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>a[i];
        sum+=a[i];
    }
    double mean = ((double)sum)/N;

    double b[N];
    for(int i=0;i<N;i++){
        b[i]=fabs(a[i]-mean);
    }
    
    double min = b[0];
    for(int i=0;i<N;i++){
        if(min>b[i]) min = b[i];
    }

    for(int i=0;i<N;i++){
        if(min==b[i]){
            cout << i << endl;
            break;
        }
    }
}


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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int lef = a + b;
    int rig = c + d;
    if(lef > rig){
        cout << "Left" << endl;
    }
    else if(lef < rig){
        cout << "Right" << endl;
    }
    else{
        cout << "Balanced" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=1e6+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a,b,c;
  cin>>a>>b>>c;
  if(c>=a&&c<=b||c>=b&&c<=a)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $N);
$array = [];
for($i=0;$i<$N;$i++){

    fscanf(STDIN, "%s", $temp);
    if(isset($array[$temp])){
        $array[$temp]++;
    }else{
        $array[$temp] = 1;
    }
}
$max = max($array);
ksort($array);
foreach($array as $key => $value){
    if($value == $max){
        echo $key.PHP_EOL;
    }
}

Measured memory_bytes: 20728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public static void Main(string[] args)
	{
		String[] k = Console.ReadLine().Split(' ');
		int a = int.Parse(k[0]);
		int p = int.Parse(k[1]);
		int kei = a*3+p;
		
		Console.WriteLine(kei/2);
	}


	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}


}


Measured memory_bytes: 11092
from math import factorial


def main():
    S = int(input())
    print(redistribution(S))


def redistribution(S):
    count = 0
    if S < 3:
        return count
    else:
        # i: (項の数-1)
        for i in range(S // 3):
            if i == 0:
                count += 1
            else:
                s_ = S - (i + 1) * 3
                if s_ == 0:
                    count_ = 1
                else:
                    count_ = factorial(s_ + i) // (factorial(s_) * factorial(i))
                count += count_ % (10**9 + 7)
                # count %= (10**9 + 7)
                # print(f'{count=}')
        return count % (10**9 + 7)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<int> mp(n, 0);
    rep(i, k) {
        int d; cin >> d;
        rep(j, d) {
            int a; cin >> a;
            a--;
            mp[a]++;
        }
    }
    int ans = 0;
    for (auto kv : mp) {
        if (kv == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M = mi()

if N == M:
    print('Yes')
else:
    print('No')

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

using namespace std;

int main(){
		int n;
		cin >> n;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x;
			ans += x - 1;
		}
		cout << ans << endl;
		return 0;
}

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

using namespace std;
using ll = long long int;
#define long ll

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

    ll l;
    cin >> l;
    vector<ll> a(l), as(l+1);
    for(auto &e: a) cin >> e;

    partial_sum(a.begin(), a.end(), as.begin()+1);

    vector<ll> le(l+1), re(l+1);

    for(ll i=1; i<=l; i++) {
        ll x = a[i-1] > 0 ? a[i-1]&1 : 2;
        le[i] = min(le[i-1]+x, as[i]);
    }
    for(ll i=l-1; i>=0; i--) {
        ll x = a[i] > 0 ? a[i]&1 : 2;
        re[i] = min(re[i+1]+x, as[l] - as[i]);
    }
    vector<ll> rr(l+1);
    for(ll i=l-1; i>=0; i--) {
        ll x = a[i] > 0 ? ~a[i]&1 : 1;
        rr[i] = min(rr[i+1]+x, re[i]);
    }

    ll res = 1e18;
    for(ll i=0; i<=l; i++)
        res = min(res, le[i]+rr[i]);
    cout << res << endl;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem0282 : Programming Contest **/
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0282

bool comp(const P &a, const P &b) {
	if (a.first == b.first) return a.second>b.second;
	return a.first<b.first;
}

class RMQ {
	const static int MAX_N = 1 << 17;
	int n;
	P dat[2*MAX_N-1];
	
public:
	RMQ(int _n) {init(_n);}
	RMQ(){}
	
	void init(int _n) {
		n=1;
		while (n<_n) n*=2;
		for (int i=0; i<2*n-1; i++) dat[i] = P(-INF, 0);
	}
	
	void update(int k, P a) {
		k += n-1;
		dat[k] = a;
		while (k>0) {
			k = (k-1)/2;
			dat[k] = max(dat[k*2+1], dat[k*2+2], comp);
		}
	}
	
	int size() {
		return n;
	}
	
	P query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return P(-INF, 0);
		
		if (a <= l && r <= b) return dat[k];
		else {
			P vl = query(a, b, k*2+1, l, (l+r)/2);
			P vr = query(a, b, k*2+2, (l+r)/2, r);
			return max(vl, vr, comp);
		}
	}
};

int main()
{
	int N, R, L;
	while (cin>>N>>R>>L) {
		RMQ RM(N);
		int d, t, x;
		cin>>d>>t>>x; R--;
		
		vector<int> team(N);
		vector<int> sum(N);
		
		for (int i=0; i<L; i++) {
			while (i==t) {
				sum[d-1] += x;
				RM.update(d-1, P(sum[d-1], d-1));
				if (R>0) {
					cin>>d>>t>>x; R--;
				} else {
					break;
				}
			}
			team[RM.query(0, N, 0, 0, RM.size()).second]++;
		}
		
		cout << (max_element(team.begin(), team.end())-team.begin())+1 << endl;
	}
}

Measured memory_bytes: 3908
#include <stdio.h>
#include <iostream>
using namespace std;

char judge(int m, int f, int r);

int main(void)
{		
	while (1) {
		int m, f, r;
		cin >> m >> f >> r;
		
		if (m == -1 && f == -1 && r == -1) break;
		
		cout << judge(m, f, r) << endl;
	}
	
	return 0;
}

char judge(int m, int f, int r)
{
	if (m == -1 || f == -1) return 'F';
	int sum = m + f;
	if (sum >= 80) return 'A';
	if (sum >= 65) return 'B';
	if (sum >= 50) return 'C';
	if (sum >= 30) {
		if (r >= 50) return 'C';
		else return 'D';
	}
	else return 'F';
}

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

#define llint long long int

using namespace std;

int main(){
  string s;
  cin >> s;
  
  if(s[0] != 'A'){
    cout << "WA";
    return 0;
  }
  else{
    int l = s.length();
    int num = 0;
    for(int i = 2; i < l-1; i++){
      if(s[i] == 'C')
        num++;
    }
    if(num != 1){
      cout << "WA";
      return 0;
    }
    else{
      num = 0;
      for(int i = 0; i < l; i++){
        if(s[i] >= 'A' && s[i] <= 'Z')
          num++;
      }
      if(num != 2){
        cout << "WA";
        return 0;
      }
    }
    cout << "AC";
  }
  return 0;
}

Measured memory_bytes: 256
//3/4/20 20:45
//nifty 8083.80

#include <bits/stdc++.h>
using namespace std;

#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))




void solve(){
    ll n;cin>>n;
    if(n==2){
        cout<<1<<endl;
        return;
    }
    ll ans=2;
    for(ll i=2;i*i<=n;i++){
        //cout<<i<<endl;
        ll m=n;
        while(m%i==0){
            m/=i;
            if(m%i==1){
                ans++;
                break;
            }
            //cout<<"ONE"<<endl;
        }
        m=n;
        if(m%i==0 && m/i!=i){
            ll j=m/i;
            while(m%j==0){
                m/=j;
                if(m%j==1){
                    ans++;
                    break;
                }
                //cout<<"two"<<endl;
           }

        }
    }
    ll m=n-1;
    for(ll i=2;i*i<=m;i++){
        if(m%i==0){
            ans++;
            if(i!=m/i)ans++;
        }
    }
    cout<<ans<<endl;

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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


public class D
{
	public static void Main()
	{
		int N = GetInt();
		long[] a = new long[3 * N];
		for(int i = 0; i < 3 * N; i++)
			a[i] = GetLong();

		long[] maxFirst = new long[N+1];
		var pqFirst = new PriorityQueue<long>(N + 1, 0);
		for(int i = 0; i < N; i++)
		{
			maxFirst[0] += a[i];
			pqFirst.Push(a[i]);
		}

		for(int i = 0; i < N; i++)
		{
			maxFirst[i + 1] = maxFirst[i] + a[N + i];
			pqFirst.Push(a[N + i]);
			maxFirst[i + 1] -= pqFirst.Pop();
		}

		long[] minLast = new long[N+1];
		var pqLast = new PriorityQueue<long>(N + 1, 1);
		for(int i = 0; i < N; i++)
		{
			minLast[0] += a[3 * N - 1 - i];
			pqLast.Push(a[3 * N - 1 - i]);
		}

		for(int i = 0; i < N; i++)
		{
			minLast[i + 1] = minLast[i] + a[2 * N - 1 - i];
			pqLast.Push(a[2 * N - 1 - i]);
			minLast[i + 1] -= pqLast.Pop();
		}

		long ans = long.MinValue;
		for(int i = 0; i <= N; i++)
			ans = Math.Max(ans, maxFirst[i] - minLast[N - i]);
		Console.WriteLine(ans);
	}
}


public class PriorityQueue<T> where T:IComparable<T>
{
	public long Size { get; private set; } = 0;
	public long MaxSize { get; private set; } = 0;
	private T[] m_heap;
	public int Type { get; private set; } = 0;  // 0: ascending
	
	public PriorityQueue(long maxSize, int type)
	{
		if(maxSize <= 0)
			throw new Exception();
		MaxSize = maxSize;
		m_heap = new T[maxSize];
		
		Type = type;
	}
	
	private int Compare(T x, T y)
	{
		return (Type == 0) ? x.CompareTo(y) : y.CompareTo(x);
	}
	
	public void Push(T x)
	{
		if(Size == MaxSize)
			throw new Exception("Queue is full.");
		
		long i = Size++;
		while(i > 0)
		{
			long p = (i - 1)/2;
			if(Compare(m_heap[p],x) <= 0)
				break;
			m_heap[i] = m_heap[p];
			i = p;			
		}
		m_heap[i] = x;		
	}
	
	public T Pop()
	{
		if(Size == 0)
			throw new Exception("Queue is empty.");
		
		T result = m_heap[0];
		T x = m_heap[--Size];
		long i = 0;
		while(i * 2 + 1 < Size)
		{
			long c1 = i * 2 + 1, c2 = i * 2 + 2;
			if(c2 < Size && Compare(m_heap[c2], m_heap[c1]) < 0)
				c1 = c2;
			if(Compare(m_heap[c1], x) >= 0)
				break;
			m_heap[i] = m_heap[c1];
			i = c1;
		}
		m_heap[i] = x;
		
		return result;		
	}	
}


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

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

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

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

int main()
{
    int s;
    bool n[1000000] = {false};

    cin >> s;
    n[s] = true;
    int ans = 1;
    while (1)
    {
        if(s % 2 == 0)
        {
            s /= 2;
        }
        else
        {
            s = 3 * s + 1;
        }
        ans++;
        if(n[s] == true)break;
        else n[s] = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
<?php
  
fscanf(STDIN, "%s", $S);

$l = 0;
$r = strlen($S) - 1;
$ans = 0;

while ($l < $r) {
  if ($S[$l] != $S[$r]) {
    $ans += 1;
  }
  $l++;
  $r--;
}

echo $ans;
  

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

const int MAX = 1000000;
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 Factorial(long long int k){
    long long int fact = 1;
    for(long long int i=1; i<=k; i++){
        fact *= i;
    }
    return fact;
}


int main()
{
    long long int x;
    long long int y;
    
    cin >> x;
    cin >> y;
    
    long long int a = 2*x-y;
    long long int b = 2*y-x;
    if( (a<0) || (b<0) || (a%3!=0) || (b%3!=0)){
        cout << 0 << endl;
        return 0;
    }
    else{
        // 前処理
        COMinit();

        // 計算例
        cout << COM((a+b)/3, a/3) << endl;
        
    }
    return 0;
}


Measured memory_bytes: 23680
k,n=list(map(int,input().split()))
a=list(map(int,input().split()))
dist=[0]*(n)

for i in range(n-1):
    dist[i]=a[i+1]-a[i]
dist[n-1]=k-a[n-1]+a[0]
ret=10**7
for i in range(n):
    ret=min(ret,k-dist[i])

print(ret)

Measured memory_bytes: 26444
#include<iostream>
#include<cstdio>
#define maxn 500010
#define ll long long
using namespace std;

int n, m;
const int p = 998244353;

ll pow_mod(ll x, ll n){
	ll s = 1;
	for(; n; n >>= 1){
		if(n & 1) s = (s * x) % p;
		x = (x * x) % p;
	}
	return s;
}

ll fac[maxn * 2], inv[maxn * 2];
ll C(ll n, ll m){
	if(n < m || m < 0) return 0;
	return fac[n] * inv[n - m] % p * inv[m] % p;
}

int main(){
	cin >> n >> m; fac[0] = 1; if(n < m) swap(n, m);
	for(int i = 1; i <= 2 * n; ++i) fac[i] = fac[i - 1] * i % p;
	inv[2 * n] = pow_mod(fac[2 * n], p - 2);
	for(int i = 2 * n - 1; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % p;
	ll ans = 0;
	for(int i = 1; i <= m; ++i)	
		ans = (ans + C(2 * i, i) % p * C(n + m - 2 * i, n - i) % p) % p;
	ans = ans * pow_mod(2 * C(n + m, n), p - 2) % p;
	ans = (ans + n) % p;
	cout << ans;
}

Measured memory_bytes: 16000
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll x[200200],y[200200];
    rep(i,0,N) cin >> x[i] >> y[i];

    ll f1[200200],f2[200200];
    rep(i,0,N){
        f1[i] = x[i] - y[i];
        f2[i] = x[i] + y[i];
    }

    sort(f1,f1+N);
    sort(f2,f2+N);

    ll ans = max(f1[N-1] - f1[0], f2[N-1] - f2[0]);

    cout << ans << ednl;
}

Measured memory_bytes: 9912
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
bool is(string s)
{
    int n=s.size();
    for(int i=0;i<n;i++)
        if(s[i]!=s[n-1-i])
            return false;
    return true;
}

main()
{
    string s;
    cin>>s;

    string ss='?'+s;
    int n=s.size();
    string b,c;
    for(int i=1;i<=(n-1)/2;i++)
        b+=ss[i];
    for(int i=(n+3)/2;i<=n;i++)
        c+=ss[i];
    if(is(s)&&is(b)&&is(c))
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 256