akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  1 21:17:39 2020

@author: naoki
"""
import sys
N, M = map(int, input().split())
sc = [list(map(int,input().split())) for _ in range(M)]

if N == 1 and M == 0:
    print(0)
    sys.exit()

for num in range(10**(N-1),10**(N)):
    switch = True
    for condition in sc:
        if len(list(str(num))) >= condition[0]:
            if list(str(num))[condition[0]-1] == str(condition[1]):
                continue
            else:
                switch = False
        else:
            switch = False
    if switch == True:
        print(num)
        sys.exit()

switch = True
if N == 1:
    for condition in sc:
        if condition[0] == 1 and condition[1] == 0:
            continue
        else:
            switch = False
    if switch == True:
        print(0)
        sys.exit()

print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using namespace std;

const int MSIZE = 16;

int g[MSIZE][MSIZE];
long long Precalc[1 << MSIZE];
long long dp[1 << MSIZE];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> g[i][j];
    }
  }
  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n && ((mask >> i) & 1); j++) {
        if ((mask >> j) & 1) {
          Precalc[mask] += g[i][j];
        }
      }
    }
  }
  for (int i = 1; i < (1 << n); i++) {
    int mask = i;
    for (int mask2 = mask; mask2 > 0; mask2 = (mask2 - 1) & mask) {
      dp[mask] = max(dp[mask ^ mask2] + Precalc[mask2], dp[mask]);
    }
  }
  cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 1408
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

void main() {
    int n = read();
    int[] a = reads();
    int ans = -114514810;
    foreach (i; 0..n) foreach (j; 0..n) {
        if (i == j) continue;
        ans = max(ans, abs(a[i] - a[j]));
    }
    writeln(ans);
}

Measured memory_bytes: 256
N = int(input())
S = input()
e = [0]*(N+1)
w = [0]*(N+1)
int_s = [0]*N
cum_sum_w = [0]*(N+1)
cum_sum_e = [0]*(N+1)
answers = [0]*N
for i in range(N):
  if S[i] == "W":
    int_s[i] = 1
  else:
    int_s[i] = 0
  cum_sum_w[i+1] = cum_sum_w[i] + int_s[i]
  
for i in range(N):
  if S[i] == "E":
    int_s[i] = 1
  else:
    int_s[i] = 0
  cum_sum_e[i+1] = cum_sum_e[i] + int_s[i]

for i in range(N):
  answers[i] = cum_sum_w[i] + (cum_sum_e[N] - cum_sum_e[i+1])

print(min(answers))

Measured memory_bytes: 45864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
    ll arr[1000009];
int main()
{
    ll n,p,q,r,t,x,y,flag,ct;
    cin>>n;
    r=0;
    for(int i=0;i<n;i++)
    {
      cin>>arr[i];
      arr[i]-=(i+1);
    }
    sort(arr,arr+n);
    p=arr[n/2];
    for(int i=0;i<n;i++)
    {
      r+=abs(arr[i]-p);
    }
    cout<<r<<endl;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'

void run(){
    int l, r, d, ans = 0;
    cin >> l >> r >> d;
    for(int i = l; i <= r; i++)
        ans += i % d == 0;
    cout << ans;
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
//    ios::sync_with_stdio(false);

   run(); return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string dog;
	cin >> dog;
	int a=0, b = 0;
	for (int i = 0; i < 3; i++)
	{
		if (dog[i] =='A')
		{
			a = 1;
			 
		}
		else if (dog[i] =='B')
		{
			b = 1;
		 
		}
	}
	if (a==1&&b==1)cout << "Yes";
	else cout << "No";

    return 0;
}



Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#define int long long
using namespace std;
signed main() {
	int m, n, a, ans = 0, b = 0, c = 0; cin >> m >> n;
	int sum = 0, num = 0;
	if (m == 2) {
		for (int h = 0; h < n; h++) {
			cin >> a;
			if (h % 2 == 0) {
				if (a == 2) { sum++; }
				if (a == 1) { num++; }
			}
			else {
				if (a == 1) { sum++; }
				if (a == 2) { num++; }
			}
		}
		cout << min(sum, num) << endl;
	}
	else {
		for (int h = 1; h <= n; h++) {
			cin >> a;
			if (ans == a) { b++; }
			else { c += (b + 1) / 2; b = 0; }
			ans = a;
		}
		c += (b + 1) / 2;
		cout << c << endl;
	}
}


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


int main() {
  long long n; cin >> n;
  vector<long long> kusi(2*n);
  
  for(int i=0; i < 2*n; i++){
    long long x; cin >> x;
    kusi.at(i) = x;
  }
  
  sort(kusi.begin(),kusi.end());
  
  long long sum; sum = 0;
  
  for(int i=0; i < n; i++){
    sum += min(kusi.at(2*i),kusi.at(2*i+1));
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

main()
{
    int n,k; scanf("%d%d",&n,&k);
    int ary[1<<18];
    int que[1<<18];
    int que2[1<<18];
    int *beg=que,*end=que;
    int *beg2=que2,*end2=que2;
    int sorted=0;
    int ans=0;

    for(int i=0; i<n; ++i)
    {
        scanf("%d",ary+i);
        int flag=0;

        if(i>=k)
        {
            if(*beg==i-k) ++beg;
            else flag=1;

            if(*beg2==i-k) ++beg2;
        }

        while(beg!=end && ary[*(end-1)]>ary[i])
        {
            --end;
        }
        *end++=i;

        while(beg2!=end2 && ary[*(end2-1)]<ary[i]) --end2;
        if(beg2!=end2) flag=1;
        *end2++=i;

        if(i==k-1) flag=1;
        else if(i<k-1) flag=0;

        if(end-beg==k)
        {
            flag=0;
            sorted=1;
        }

        if(flag)
        {
            ans++;
            // printf("%d\n",i);
        }
    }

    ans+=sorted;
    printf("%d\n",ans);
}

Measured memory_bytes: 2944
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    auto s = readln().chomp();
    string t;
    foreach(si; s) {
        if(t.empty || t.back != si) {
            t ~= si;
        }
    }
    writeln(t.length - 1);
}



Measured memory_bytes: 536
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int max = Integer.parseInt(sc.next());
        int target = Integer.parseInt(sc.next());
        int cnt = 0;
        for (int i = 0; i <= max; i++) {
            for (int j = 0; j <= max; j++) {
                int total = i + j;
                if (target - total <= max && target - total >= 0) {
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> c(n), d(n + 1);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a--;
        c[a]++;
    }
    for (int i = 0; i < n; i++) {
        d[c[i]]++;
    }
    vector<int> s(n + 1), f(n + 1);
    for (int i = 0; i <= n; i++) {
        s[i] = d[i] + (i != 0 ? s[i - 1] : 0);
    }
    ll y = 0;
    for (int i = 1; i <= n; i++) {
        y += i * d[i];
        f[i] = y + (s[n] - s[i]) * i;
        f[i] /= i;
    }
    f[0] = 1e9;
    vector<int> ans(n + 1);
    int id = 1;
    for (int i = n; i >= 0; i--) {
        for (; id <= n && id <= f[i]; id++) {
            ans[id] = i;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	UL dp[101][4] = {};
	UL dp2[101][4] = {};

	void Solve() {
		vector<UL> N; {
			string S; cin >> S;
			rep(i, S.size()) N.push_back(S[i] - '0');
		}
		UL K; cin >> K;
		reverse(N.begin(), N.end());
		dp[0][0] = dp2[0][0] = 1;
		rep(i, N.size()) {
			rep(j, 4) { dp2[i + 1][j] = dp2[i][j]; }
			rep(j, 3) { dp2[i + 1][j + 1] += 9 * dp2[i][j]; }
			if (N[i] == 0) {
				rep(j, 4) { dp[i + 1][j] = dp[i][j]; }
			}
			else {
				rep(j, 3) { dp[i + 1][j + 1] = dp[i][j]; }
				rep(j, 4) { dp[i + 1][j] += dp2[i][j]; }
				rep(j, 3) { dp[i + 1][j + 1] += (N[i] - 1) * dp2[i][j]; }
			}
		}
		cout << dp[N.size()][K] << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
n, x, m  = map(int, input().split())
a = [x]
found = {x}
while True:
    y = (a[-1] ** 2) % m
    a.append(y)
    if y in found:
        break
    found.add(y)
if n <= len(a):
    print(sum(a[:n]))
else:
    z = a.index(a[-1])
    a.pop()
    n -= z
    res = sum(a[:z])
    res += sum(a[z:]) * (n // (len(a) - z))
    res += sum(a[z:z + (n % (len(a) - z))])
    print(res)


Measured memory_bytes: 77192
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main() 
{
    int n, k;
    cin >> n >> k;
    int a[2010] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    ll cntl[2010] = {};
    ll cntr[2010] = {};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if (a[i] < a[j]) cntl[i]++;
        }
        for (int j = i+1; j < n; j++)
        {
            if (a[i] < a[j]) cntr[i]++;
        }
        
    }

    ll ans = 0;
   for (int i = 0; i < n; i++)
        {
            //ans = (ans + k%mod*(2*cntl[i]+(k-1)%mod*(cntl[i]+cntr[i]))/2%mod) % mod;
            //ans = (ans + k%mod*(((k-1)%mod*(cntl[i]+cntr[i]))/2+cntl[i])%mod) % mod;
            ans = (ans + k * cntl[i] % mod  + ((ll)k*((ll)k-1)/2) % mod * (cntl[i]+cntr[i]))%mod;
        }
    
    
    cout << ans << "\n";
    
    
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n;
    cin>>n;
    vector<tuple<int,int,ll>> data;
    rep(i,0,n){
        int a,b; ll c;
        cin>>a>>b>>c;
        data.emplace_back(a,b,c);
    }
    ll xans=0;
    ll yans=0;
    ll hans=0;
    rep(i,0,101){
        rep(j,0,101){
            ll temp_h=0;
            rep(k,0,n){
                if(get<2>(data[k])!=0){
                    temp_h = get<2>(data[k]) + abs(i-get<0>(data[k])) + abs(j-get<1>(data[k]));
                    break;
                }
            }
            bool can=true;
            rep(k,0,n){
                if(max(temp_h - abs(get<0>(data[k])-i) - abs(get<1>(data[k])-j),0LL)!=get<2>(data[k])){
                    can=false;
                    break;
                }
            }
            if(can==true){
                xans=i; yans=j; hans=temp_h;
                goto END;
            }
        }
    }
    END:
    cout<<xans<<" "<<yans<<" "<<hans<<endl;
}

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

int main() {
  long n, m;
  cin >> n >> m;
  long h[n];
  for (long i = 0; i < n; i++) {
    cin >> h[i];
  }
  long a[m], b[m];
  unordered_map<long, vector<long>> connections;
  for (long i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (find(connections[a[i] - 1].begin(),
             connections[a[i] - 1].end(),
             b[i] - 1) == connections[a[i] - 1].end())
      connections[a[i] - 1].push_back(b[i] - 1);
    if (find(connections[b[i] - 1].begin(),
             connections[b[i] - 1].end(),
             a[i] - 1) == connections[b[i] - 1].end())
      connections[b[i] - 1].push_back(a[i] - 1);
  }
  
  long count = 0;
  for (long i = 0; i < n; i++) {
    bool flag = false;
    for (auto j : connections[i]) {
      if (h[j] >= h[i]) {
        flag = true;
        break;
      }
    }
    if (flag) continue;
    count++;
  }
  
  cout << count;
  
  return 0;
}

Measured memory_bytes: 14796
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<complex>

#define llong long long;
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 55

//const int INF = 1e9 + 7;


typedef complex<int> cpi;
int n;
int m[ARRAY_MAX];


int main() {


	cpi mp[55][15];
	while (cin >> n, n)
	{
		for (int i = 0; i <= n; i++) {
			cin >> m[i];
			for (int j = 0; j < m[i]; j++) {
				int a, b;
				cin >> a >> b;
				mp[i][j] = cpi(a, b);
			}
		}

		//入力終了

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

			if (m[0] != m[i]) {
				//座標の数が違う
				continue;
			}


			for (int tm = 0; tm < 4; tm++) {
				//4回回転させる
				for (int j = 0; j < m[0]; j++) {
					mp[0][j] *= cpi(0, 1);//元の折れ線を回転させる
				}

				bool flag = true;

				//そのまま比較
				for (int index = 1; index < m[0]; index++)
				{
					flag &= (((mp[i][index].real() - mp[i][index - 1].real()) == (mp[0][index].real() - mp[0][index - 1].real()))
						&& ((mp[i][index].imag() - mp[i][index - 1].imag()) == (mp[0][index].imag() - mp[0][index - 1].imag())));

				}

				if (flag == true) {
					cout << i << endl;
					break;
				}
				//逆順比較
				flag = true;
				for (int index = 1; index < m[0]; index++)
				{
					flag &= (((mp[i][index].real() - mp[i][index - 1].real()) == (mp[0][m[0] - 1 - index].real() - mp[0][m[0] - index].real()))
						&& ((mp[i][index].imag() - mp[i][index - 1].imag()) == (mp[0][m[0] - 1 - index].imag() - mp[0][m[0] - index].imag())));

				}

				if (flag == true) {
					cout << i << endl;
					break;
				}
			}
		}
		cout << "+++++" << endl;
	}

	return 0;
}


Measured memory_bytes: 3116
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	n := int(math.Sqrt(float64(x)))
	for i := 2; i <= n; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func sum(a ...int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()

	a := make([]int, n)
	for i, x := 0, 11; i < n; x += 5 {
		if !isPrime(x) {
			continue
		}
		a[i] = x
		i++
	}

	for i := range a {
		if i < n-1 {
			putf("%d ", a[i])
		} else {
			putf("%d\n", a[i])
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int old_t=0, old_x=0, old_y=0;
    bool res=true;
    for(int i=0; i<n; ++i){
        int t, x, y;
        cin >> t >> x >> y;
        if(!res) continue;
        int d=abs(x-old_x)+abs(y-old_y);
        if(d>t-old_t) res=false;
        if(d%2!=(t-old_t)%2) res=false;
    }
    cout << (res ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
string x,y;
int r;
int main()
{
	cin >>x>>y;
	for (int i=0;i<3;i++) r+=(x[i]==y[i] ? 1 : 0);
	cout <<r;
	return 0;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;
typedef long long LL;
const LL ninf=0xc0c0c0c0c0c0c0c0LL;
const int MX=5011,MXM=205;
int n,m;
int a[MX],b[MXM][MX];
int st[MXM][15][MX],lg2[MX];
LL ans,p[MX];

inline int que(int k,int l,int r){
	static int lg;
	lg=lg2[r-l+1];
	return max(st[k][lg][l],st[k][lg][r-(1<<lg)+1]);
}
void wk(int l,int r,int tl,int tr){
	if(l>r)return;
	int mid=(l+r)>>1;
	int pos=-1;LL ans=ninf;
	for(int i=max(tl,mid);i<=tr;i++){
		LL s=0;
		for(int j=1;j<=m;j++)s+=que(j,mid,i);
		s-=p[i]-p[mid];
		if(s>ans)ans=s,pos=i;
	}
	::ans=max(::ans,ans);
	wk(l,mid-1,tl,pos);
	wk(mid+1,r,pos,tr);
}
void buildST(){
	lg2[1]=0;
	for(int i=2;i<=n;i++)lg2[i]=lg2[i>>1]+1;
	for(int i=1;i<=m;i++){
		memcpy(st[i][0]+1,b[i]+1,sizeof(int)*n);
		for(int j=1;(1<<j)<=n;j++)
			for(int k=1;k<=n-(1<<j)+1;k++)
				st[i][j][k]=max(st[i][j-1][k],st[i][j-1][k+(1<<(j-1))]);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&b[j][i]);
	ans=ninf;
	for(int i=2;i<=n;i++)p[i]=p[i-1]+a[i-1];
	buildST();
	wk(1,n,1,n);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 63744
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());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var cnt = new int[4];
            for (int i = 0; i < n; i++)
            {
                var s = ReadLine();
                if (s == "AC")
                    cnt[0]++;
                else if (s == "WA")
                    cnt[1]++;
                else if (s == "TLE")
                    cnt[2]++;
                else
                    cnt[3]++;
            }
            WriteLine("AC x " + cnt[0]);
            WriteLine("WA x " + cnt[1]);
            WriteLine("TLE x " + cnt[2]);
            WriteLine("RE x " + cnt[3]);
        }
    }

    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: 20924
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int rem = 0;
    for(int i = 1; i < n; i++){
        if(a[i] - a[i-1] > rem) rem = a[i] - a[i-1];
    }
    if(k-a[n-1]+a[0] > rem) rem = k-a[n-1]+a[0];
    cout << k-rem << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <limits>
#include <numeric>
#include <type_traits>

typedef long long ll;
using namespace std;

int gcd(int a, int b)
{
	if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
	return (b);
}

int main()
{
	int n,X;
	cin >> n >> X;
	vector <int> x(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}
	sort(x.begin(),x.end());
	for(int i = 0; i < n; i++)
	{
		x[i] = abs(x[i] - X);
	}
	int ans = x[0];
	for (int i = 0; i < n; i++)
	{
		ans = gcd(ans,x[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
//
// main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

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

int main() {
	ll H, W, K;
	cin >> H >> W >> K;
	auto is_white = make_vec_nd(false, W, H);
	rep(y,0,H) {
		string s;
		cin >> s;
		rep(x,0,W) {
			is_white[x][y] = (bool)(s[x] - '0');
		}
	}
	ll ans = numeric_limits<ll>::max();
	rep(flag,0,1<<(H-1)) {
		vector<ll> y_to_grp(H);
		ll grp = 0;
		rep(y,0,H) {
			y_to_grp[y] = grp;
			if (y < H-1) {
				if (flag & (1 << y)) {
					grp++;
			 	}
			}
		}
		ll grp_cnt = grp + 1;
		vector<ll> white_cnt(grp_cnt);
		ll ans_loc = 0;
		rep(i,0,H-1) {
			if (flag & (1 << i)) {
				// cout << "i = " << i << endl;
				ans_loc++;
			}
		}
		bool fail = false;
		rep(x,0,W) {
			vector<ll> white_cnt_loc(grp_cnt);
			rep(y,0,H) {
				if (is_white[x][y]) {
					white_cnt_loc[y_to_grp[y]]++;
				}
			}
			rep(i,0,grp_cnt) {
				// cout << "white_cnt[" << i << "] = " <<white_cnt[i]<< endl;
				// cout << "white_cnt_loc[" << i << "] = " <<white_cnt_loc[i]<< endl;
				if (white_cnt_loc[i] > K) {
					fail = true;
					break;
				}
			}
			if (fail) {
				break;
			}
			if (x > 0) {
				bool need_cut = false;
				rep(i,0,grp_cnt) {
					if (white_cnt[i] + white_cnt_loc[i] > K) {
						need_cut = true;
						break;
					}
				}
				if (need_cut) {
					ans_loc++;
					// cout << "j = " << x-1 << endl;
					rep(i,0,grp_cnt) {
						white_cnt[i] = 0;
					}
				}
			}
			rep(i,0,grp_cnt) {
				white_cnt[i] += white_cnt_loc[i];
			}
		}
		if (fail) {
			continue;
		}
		ans = min(ans, ans_loc);
		// cout << "ans_loc = " << ans_loc << endl;
	}
	cout << ans << endl;
}



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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int a, b; cin >> a >> b;
  int tmp = max(a, b) - min(a, b);
  int ans = 0;
  for(int i=1;i<tmp;++i) {
    ans += i;
  }
  cout << ans - a << endl;

}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N = Cin.Ni();
        int K = Cin.Ni();
        int[] l = new int[N];
        int total = 0;

        for (int i = 0; i < N; i++) {
            l[i] = Cin.Ni();
        }
        Array.Sort(l);
        l = l.Reverse().ToArray();

        for (int i = 0; i < K; i++) {
            total += l[i];
        }

        Console.WriteLine(total);
    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)

using namespace std;

typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;


const  int MAXn= 3e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;


int main(){
       int n;
       cin >> n;
       vector<pair<ld,ld> > v;
       forn(i, n) {
		   ld a, b;
		   cin >> a >> b;
		   v.pb({a,b});
	   }
	   ld sum = 0;
	   
	   for(int i = 0; i < n - 1; i++) {
		   for(int j = i + 1; j < n; j++) {
			   sum += (ld)sqrt( ((v[i].fi - v[j].fi) * (v[i].fi - v[j].fi)) + ((v[i].se - v[j].se) * (v[i].se - v[j].se)));
		   }
		}
		sum *= 2;
		sum /= n;
		cout << fixed << setprecision(10) << sum;
		
}
		   
       
       
       
       
       
       
       
       
       
       
       
       
       
        
    


Measured memory_bytes: 256
<?php
  
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);
 
$S = str_split($S);
$T = str_split($T);

$r = 0;
for ($i=0;$i < count($S);$i++) {
  if ($S[$i] != $T[$i]) $r++;
}

echo $r;

Measured memory_bytes: 41128
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


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

	long long s, c;
	cin >> s >> c;
	long long x = min(s, c / 2);
	long long ans = x + (c - x * 2) / 4;
	cout << ans << endl;


	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	for(int i = 0;i<n;i++){
		cin >> s[i];
	}
	sort(s.begin(),s.end());
	int max = 0;
	vector<pair<string,int>> s1(n);
	int count = 1;
	for(int i = 0;i<n-1;i++){
		if(s[i] == s[i+1]){
			count++;
			continue;
		}else{
			s1.push_back(make_pair(s[i],count));
			count = 1;
		}
	}
  	s1.push_back(make_pair(s[n-1],count));
	sort(s1.begin(),s1.end(),[](const pair<string,int> &a,const pair<string,int> &b){
        return a.second > b.second;
    });
	max = s1[0].second;
	vector<string> ans;
	for(int i = 0;i<s1.size();i++){
		if(s1[i].second == max)
			ans.push_back(s1[i].first);
      	else
          break;
	}
	sort(ans.begin(),ans.end());
	for(int i = 0;i<ans.size();i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 24136
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    if(d<=a || b<=c) ans = 0;
    else if(c<=a && d<=b) ans = d-a;
    else if(a<=c && b<=d) ans = b-c;
    else if(a<=c && d<=b) ans = d-c;
    else if(c<=a && b<=d) ans = b-a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, v[200005], x;

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


Measured memory_bytes: 4348
import java.util.Scanner ;

class Main {
  public static void main(String[] args) {   
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt() ;
    String m[] = new String[n];
    String str[] = new String[n];
    double sum = 0 ; 
    for(int i=0 ; i< n ; i++){
      m[i] = scan.next();
      str[i] = scan.next();
      if(str[i].equals("BTC")){
        sum +=Double.parseDouble(m[i])*380000.0;
      }else{
        sum+=Double.parseDouble(m[i]);
      }
    }
    System.out.println(sum);
    
    
  }
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B;
  cin>>A>>B;
  if(A%2!=B%2){
    cout << "IMPOSSIBLE" << endl;
    }else{
    cout << (A + B) / 2 << endl;
    }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());

int main() {
	int h,w,tmp=0;

	string ans;
	cin>>h>>w;
	vi flag_y(w,0),flag_x(h,0);
	vs a(h);
	rep(i,h){
		cin>>a[i];
	}

	rep(i,h) {
		rep(k, w) {
			if (a[i][k] == '#') {
				flag_x[i] = 1;
				flag_y[k] = 1;
			}
		}
	}

	rep(i,h){
		rep(k,w) {
			if(flag_x[i]==1 &&flag_y[k]==1 ){
				cout<<a[i][k];
			}

		}
		if(flag_x[i]==1)
			cout << "\n";

	}

	/*
	rep(i,w) {
		rep(k, h) {
			cout << flag_x[i] + flag_y[k];
		}
		cout << "\n";
	}
	 */
	return 0;


}


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

using namespace std;

int main()
{
    const long long mod=1000000007;
    long long n;
    cin >> n;
    vector<long long> v(60,0);
    for(int i=0;i<n;i++)
    {
        long long a;
        cin >> a;
        for(long long j=0;j<60;j++) v[j]+=((a>>j)&1);
    }
    long long res=0;
    for(long long i=0;i<60;i++)
    {
        res=(res+(((1ll<<i)%mod)*((v[i]*(n-v[i]))%mod))%mod)%mod;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

#define MOD 1000000007

int main(int argc, char **argv)
{
    int N;
    string S;
    cin >> N >> S;

    int count[26];
    REP(i, 26) count[i] = 0;
    REP(i, N) {
        count[(int)(S[i] - 'a')]++;
    }
    ll ans = 1;
    REP(i, 26) {
        ans = (ans * (count[i] + 1)) % MOD;
    }
    cout << ans - 1 << endl;
    return 0;
}


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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int N, cnt = 0;
    cin >> N;
    vector <int> a(N, 0);
    rep(i, 0, N) {
        cin >> a[i];
        if (i+1 != a[i]) cnt++;
    }
    if (cnt > 2) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int[] counts = new int[2];
        for (int i = 0; i < s.length(); i++) {
            int c = s.charAt(i) - '0';
            counts[(i + c) % 2]++;
        }

        System.out.println(Math.min(counts[0], counts[1]));
    }
}


Measured memory_bytes: 24924
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 998244353
#define INF 1000000000

ll one;
ll zero;
bool nibu;

void dfs(Graph &G,int v,vector<int> &color){
  for(auto nv:G.at(v)){
    if(color.at(nv)==-1){
      color.at(nv)=1-color.at(v);
      if(color.at(nv)==1){
        one++;
      }else{
        zero++;
      }
      dfs(G,nv,color);
    }else{
      if(1-color.at(v)!=color.at(nv)){
        nibu=true;
      }
    }
  }
}

int main(){
  int N,M;
  cin>>N>>M;
  Graph G(N);
  for(int i=0;i<M;i++){
    int A,B;
    cin>>A>>B;
    A--;B--;
    G.at(A).push_back(B);
    G.at(B).push_back(A);
  }

  ll ans=0;
  vector<int> color(N,-1);
  for(int i=0;i<N;i++){
    if(color.at(i)!=-1){
      continue;
    }
    color.at(i)=0;
    zero=1;
    one=0;
    nibu=false;
    dfs(G,i,color);
    if(nibu){
      ans+=(zero+one)*(zero+one-1)/2;
    }else{
      ans+=one*zero;
    }
  }

  ans-=(ll)M;

  cout<<ans<<endl;
}


Measured memory_bytes: 7424
import java.util.*;
import java.io.*; 

public class Main {
	
	public static void main(String... string) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(); 
		int y = sc.nextInt();
		for(int i = 0; i<2000; i++) {
			if((int)(i*0.08) == x && (int)(i * 0.1) == y) {
				System.out.println(i);
				return; 
			}
		}
		System.out.println(-1); 
	}
}

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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

ll make_from_plus(vector<ll> &A){
    ll L = A.size();
    if(L==0) return 0;
    if(L==1) return A[0];
    if(L==2) return A[1]-A[0];
    ll internal = 0;
    FOR(i, 1, L-1){
        internal += A[i];
    }
    internal -= A[0];
    return internal + A.back();
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> A; // plus
    vector<ll> B; // minus
    FOR(i, 0, N){
        ll a; cin >> a;
        if(a>=0){
            A.push_back(a);
        }else{
            B.push_back(a);
        }
    }
    sort(ALL(A));
    sort(ALL(B), greater<ll>()); // -1, -2, -3..
    // vprint(A);
    // vprint(B);

    vector<pair<ll, ll> > P;

    if(B.size()==0){
        ll L = A.size();
        // プラスだけ
        if(A.size()==2){
            P.push_back(make_pair(A[1], A[0]));
            ll ans = A[1]-A[0];
            p(ans);
        }else{
            // 長さ３以上
            P.push_back(make_pair(A[0], A[1]));
            A[0] -= A[1];
            FOR(i, 2, A.size()-1){
                P.push_back(make_pair(A[0], A[i]));
                A[0] -= A[i];
            }
            P.push_back(make_pair(A[L-1], A[0]));
            A[L-1] -= A[0];
            ll ans = A[L-1];
            p(ans);
        }
    }
    else if(A.size()==0){
        // マイナスだけ
        ll L = B.size();
        FOR(i, 1, L){
            P.push_back(make_pair(B[0], B[i]));
            B[0] -= B[i];
        }
        p(B[0]);
    }
    else{
        // 混合
        ll ans = A.back();
        FOR(i, 0, A.size()-1){
            P.push_back(make_pair(B[0], A[i]));
            B[0] -= A[i];
        }
        FOR(i, 0, B.size()){
            P.push_back(make_pair(ans, B[i]));
            ans += -B[i];
        }
        p(ans);
    }

    for(auto pa : P){
        p2(pa.first, pa.second);
    }
    
    return 0;
}

Measured memory_bytes: 5104
a = []
for i in range(5):
    a.append(int(input()))
k = int(input())
fl = 0
for i in range(5):
    for j in range(i,5):
        if a[j] - a[i] > k:
            fl = 1

if fl == 1:
    print(':(')
else:
    print('Yay!')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[300][300];
int main() {
    int N;
    cin>>N;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            cin>>A[i][j];
        }
    }
    ll ans=0;
    for(int i=0;i<N;i++) {
        for(int j=i+1;j<N;j++) {
            ll m=1LL<<60;
            for(int k=0;k<N;k++) {
                if(k==i||k==j) continue;
                m=min(m,A[i][k]+A[k][j]);
            }
            if(m<A[i][j]) {
                cout<<-1<<endl;
                return 0;
            }
            if(m>A[i][j]) {
                ans+=A[i][j];
            }
        }
    }
    cout<<ans<<endl;
}

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

int main(void) {
  long N,n,Mx,Mn,Mn2;
  scanf("%ld\n",&N);
  scanf("%ld\n",&Mn);
  scanf("%ld\n",&Mx);

  if (Mx>Mn) Mn2=Mn;
  else       Mn2=Mx;
  for(n=2;n<N;n++) {
    long R;
    scanf("%ld\n",&R);

    if(Mx<R) {
      Mx=R;
      if (Mn2<Mn) Mn=Mn2;
    }
    if ((R-Mn2)>(Mx-Mn)) {
      Mx=R;
      Mn=Mn2;
    }
    if (Mn2>R) {
      Mn2=R;
    }
  }
  printf("%ld\n",Mx-Mn);
  return 0;
}

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


void solve(long long A, long long B, long long C){
    if(A == B) {
        cout << C << endl;
        return;
    }
    else if(A== C) cout << B << endl;
    else cout << A << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main() {  
  int64_t R, C, K;
  cin >> R >> C >> K;

  vector<vector<int64_t>> values(R, vector<int64_t>(C));
  for (int64_t k = 0; k < K; ++k) {
    int64_t r, c, v;
    cin >> r >> c >> v;
    values[r-1][c-1] = v;
  }
  
  vector<vector<vector<int64_t>>> dp(4, vector<vector<int64_t>>(R+1, vector<int64_t>(C, -1)));
  dp[0][0][0] = 0;
  for (int64_t r = 0; r < R; ++r) {
    for (int64_t c = 0; c < C; ++c) {
      int64_t value = values[r][c];
      int64_t next = 0;
      for (int64_t k = 3; k > 0; --k) {
        if (value != 0 && dp[k-1][r][c] >= 0) {
          dp[k][r][c] = max(dp[k][r][c], dp[k-1][r][c] + value);
        }
        if (c != C-1) dp[k][r][c+1] = dp[k][r][c];
        next = max(next, dp[k][r][c]);
      }
      if (c != C-1) dp[0][r][c+1] = max(dp[0][r][c+1], dp[0][r][c]);
      dp[0][r+1][c] = max(dp[0][r][c] + value, next);
    }
  }
  cout << dp[0][R][C-1] << endl;

  return 0;
}


Measured memory_bytes: 425696
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
A = [(A[i]<<18) + i for i in range(N)]
B = [(B[i]<<18) + i + (1<<17) for i in range(N)]
AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("Yes")
            break
    else:
        for i in range(N):
            if IA[A[i]] == IB[B[i]]:
                print("Yes")
                break
        else:
            c = 1
            i = 0
            P = [-1] * N
            for i in range(N):
                P[IA[A[i]]] = IB[B[i]]
            i = P[0]
            while i != 0:
                i = P[i]
                c += 1
            if c < N:
                print("Yes")
            else:
                print("No")

Measured memory_bytes: 99088
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    ll n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    vl basis;
    string s; cin >> s;
    ll ans = 0;
    for(ll i=n-1; i>=0; i--){
        for(auto b : basis){
            chmin(a[i], a[i]^b);
        }
        if(s[i]=='0'){
            if(a[i]) basis.push_back(a[i]);
        }else{
            if(a[i]) ans = 1;
        }
    }
    cout << ans << "\n";
}

int main(){
    ll t; cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
M = 10**6 + 1
cnt = [0] * M
for a in A:
    if cnt[a] != 0:
        cnt[a] += 1
        continue
    for b in range(a, M, a):
        cnt[b] += 1
ans = 0
for a in A:
    if cnt[a] == 1:ans += 1
print(ans)


Measured memory_bytes: 32024
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int N;
	cin >> N;
	vector<int>v(N);
	int vmax = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		vmax = max(vmax, v[i]);
	}
	int ans = 0;
	for (int i = vmax; i > 0; i--) {
		bool finder = false;
		for (int j = 0; j < N; j++) {
			if (v[j] == i) {
				if (!finder) {
					finder = true;
				}
				v[j]--;
			}
			else {
				if (finder) {
					ans++;
					finder = false;
				}
			}
		}
		if (finder) {
			ans++;
			finder = false;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;


int main(){
    ll h,w;
    cin>>h>>w;
    bool hfl[h],wfl[w];
    for(ll i=0;i<h;i++)hfl[i]=false;
    for(ll i=0;i<w;i++)wfl[i]=false;
    char a[h][w];
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            cin>>a[i][j];
            if(a[i][j]=='#'){
                hfl[i]=true;
                wfl[j]=true;
            }
        }
    }
    for(ll i=0;i<h;i++){
        if(hfl[i]){
            for(ll j=0;j<w;j++){
                if(wfl[j]){
                    cout<<a[i][j];
                }
            }
            cout<<endl;
        }
    }


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc=new Scanner(System.in);

		long x=sc.nextLong();
		int i=0;
		double yokin=100;
		
		/*while(yokin<x) {
			yokin=yokin*1.01;
			yokin=Math.floor(yokin);
			
			i++;
		}
		System.out.println(i);*/
		
		for(i=0;yokin<x;i++) {
			yokin=yokin*1.01;
			yokin=Math.floor(yokin);
		}
		System.out.println(i);
		
		
		sc.close();
	}

}


Measured memory_bytes: 26996
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> VI;
typedef vector<VI> VVI;

int main(){
    long long n,res=0;
    cin >> n;
    VI a(n);

    REP(i,n){
        cin >> a[i]; 
    }
    REP(i,n){
        res += a[i]-1; 
    }
    
    cout << res << endl;
    return 0;
}
   


Measured memory_bytes: 256