akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[N];

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> A[i];

    sort(A, A + n);

    int ans = 0;

    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            int k = A[i] + A[j];
            int idx = lb(A + j + 1, A + n, k) - A;
            if (idx > j + 1) {
                if (A[idx - 1] < k)
                    ans += idx - j - 1;
            }
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll ans=0;
  string s,t;
  cin>>s>>t;
  rep(i,sz(s)){
    if(s[i]!=t[i]) ans++;
  }
  COUT(ans);
}

Measured memory_bytes: 3836
#include<string>
#include<vector>
#include<iostream>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

vector<string> yaml;
int indent[50000];

string query(int l,int r,int i,const string &q){
	i++;
	int pos=q.find_first_of('.',i);
	string s=q.substr(i,pos-i)+":";
	if(pos==-1){ // 終端
		for(int y=l;y<r;y++){
			if(indent[y]==indent[l] && yaml[y]==s) return "object";
			if(indent[y]==indent[l] && yaml[y].substr(0,s.length())==s){
				return "string \""+yaml[y].substr(s.length()+1)+"\"";
			}
		}
	}
	else{
		for(int y=l;y<r;y++){
			if(indent[y]==indent[l] && yaml[y]==s){
				int r_next;
				for(r_next=y+1;r_next<yaml.size()&&indent[r_next]>indent[y];r_next++);
				return query(y+1,r_next,pos,q);
			}
		}
	}
	return "no such property";
}

int main(){
	string q; getline(cin,q);
	for(string s;getline(cin,s);yaml.push_back(s));

	rep(i,yaml.size()){
		indent[i]=yaml[i].find_first_not_of(' ');
		yaml[i]=yaml[i].substr(indent[i]); // 先頭の空白を除去
	}

	cout<<query(0,yaml.size(),0,q)<<endl;

	return 0;
}

Measured memory_bytes: 1288
import java.io.IOException;
import java.util.Scanner;

/**
 */
class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		while(in.hasNext()) {
			double v = in.nextDouble();

			int ans = getMinimumFloor(v);
			System.out.println(ans);
		}
	}

	public static int getMinimumFloor(double v) {
		// v = 9.8t
		// y = 4.9*t^2

		// N???????????? 5*N-5

		double t = v / 9.8;
		double y = 4.9*t*t;

		return (int)Math.floor( (y+5.0) / 5.0 + 1.0);
	}
}

Measured memory_bytes: 27744
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		long long int pipelen = 0;
		for (int i = 0; i < N; ++i) {
			int p; cin >> p; pipelen += p;
		}
		vector<int>jos;
		for (int i = 0; i < N - 1; ++i) {
			int j; cin >> j;
			jos.push_back(j);
		}
		sort(jos.begin(), jos.end(), greater<int>());
		long long int jolen = 0;
		long long int ans = 0;
		for (int i = 0; i < N; ++i) {
			ans = max(ans, (pipelen + jolen)*(N - i));
			if (i != N - 1) {

				jolen += jos[i];
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

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

typedef long long int ll;

using namespace std;

int main()
{
  ll N,  M;
  cin >> N >>M ;

  vector<ll> p(M),S(M);
  string A;

  for (ll i = 0; i < M; i++) {
    cin >> p.at(i) >> A;
    if(A=="AC"){
      S.at(i) = 1;
    }
    else{
      S.at(i) = 0;
    }
  }

  vector<ll> count_AC(N),count_WA(N);

  for (ll i = 0; i < N; i++) {
    count_AC.at(i)=0;
    count_WA.at(i) = 0;
  }

  for (ll i = 0; i < M; i++) {
    ll num=0;
    num = p.at(i)-1;

    if(count_AC.at(num)==0&&S.at(i)==0){
      count_WA.at(num)++;
    }
    else if (count_AC.at(num) == 0 && S.at(i) == 1)
    {
      count_AC.at(num)=1;
    }
    

    //cout << count_WA.at(num) << count_AC.at(num) << endl;
  }

  ll ans_WA = 0, ans_AC = 0;

  for (ll i = 0; i < N; i++) {
    if(count_AC.at(i)==1){
      ans_WA += count_WA.at(i);
    }
    
    ans_AC += count_AC.at(i);
  }

  cout << ans_AC << ' ' << ans_WA << endl;
}

Measured memory_bytes: 3328
times = [int(input()) for _ in range(5)]

amarino_times = [i % 10 for i in times]
#
# min_index = amarino_times.index(min(amarino_times))
#
# last_choose_time = times.pop(min_index)
#
#
# sum = 0
# for i in times:
#     sum += i
#     if i % 10 != 0:
#         sum += 10 - (i % 10)
#
# sum += last_choose_time
#
# hoge = 0
# for i in amarino_times:
#     if i == 0:
#         hoge += 1
# for i in range(hoge):
#     fuga = amarino_times.pop(amarino_times.index(min(amarino_times)))
# print(hoge)
# if hoge:
#     sum -= min(amarino_times)
#
#
# print(sum)

sum = 0
for i in times:
    if i % 10 == 0:
        sum += i
    else:
        sum += i + 10-i % 10

hoge = []
for i in range(len(amarino_times)):
    if amarino_times[i] != 0:
        hoge.append(amarino_times[i])

if any(amarino_times):
    sum -= (10-min(hoge))

print(sum)


Measured memory_bytes: 3060
#include<stdio.h>
 
const int MAX_V = 10000;
int prime[10001];
 
int main(){
    int v, q1;
    for(int i = 2;i <= MAX_V;i++){
        prime[i] = 1;
    }
    for(int i = 2; i * i <= MAX_V;i++){
        if(prime[i]){
            for(int k = 2 * i;k <= MAX_V; k += i){
                prime[k] = 0;
            }
        }
    }
    while(scanf("%d", &v) != EOF){
        if(v == 0) break;
        for(int i = v;i >= 2;i--){
            if(prime[i]){
                if(prime[i-2]){
                    q1 = i;
                    break;
                }
            }
        }
        printf("%d %d\n", q1 - 2, q1);
    }
    return 0;
}

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> A(N);

  for (auto &x: A)
    cin >> x;

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

  std::vector<int> sides;

  while (A.size() > 0 && sides.size() < 2){
    int l = A.back();
    A.pop_back();

    if (A.size() > 0 && A.back() == l){
      sides.push_back(l);
      A.pop_back();
    }
  }

  if (sides.size() == 2)
    cout << 1LL * sides[0] * sides[1] << endl;
  else
    cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

template <typename T>
void print_line(const T& x){
	for(const auto c : x){ cout << c; }
	cout << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	deque<char> cur[2];
	string response;
	while(cur[0].size() < n){
		bool found = false;
		for(int x = 0; !found && x < 4; ++x){
			cur[0].push_back((x & 1) ? '#' : '.');
			cur[1].push_back((x & 2) ? '#' : '.');
			print_line(cur[0]);
			print_line(cur[1]);
			cout << flush;
			cin >> response;
			if(response == "end"){ return 0; }
			if(response == "T"){
				found = true;
			}else{
				cur[0].pop_back();
				cur[1].pop_back();
			}
		}
		if(!found){ break; }
	}
	while(cur[0].size() < n){
		for(int x = 0; x < 4; ++x){
			cur[0].push_front((x & 1) ? '#' : '.');
			cur[1].push_front((x & 2) ? '#' : '.');
			print_line(cur[0]);
			print_line(cur[1]);
			cout << flush;
			cin >> response;
			if(response == "end"){ return 0; }
			if(response == "T"){
				break;
			}else{
				cur[0].pop_front();
				cur[1].pop_front();
			}
		}
	}
	return 0;
}



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

using namespace std;

int main() {
    long long int H;
    cin >> H;
    long long int mon = 1;
    long long int count = 0;
    while(H != 0) {
        count += mon;
        mon *= 2;
        H /= 2;
    }
    cout << count << endl;
}

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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main(){
  int a;
  cin>>a;
  int vec[a];
  int sum=0;
  for(int i=0;i<a;i++){
    cin>>vec[i];
    sum+=vec[i];
  }
  int b,c,d;
  cin>>b;
  for(int i=0;i<b;i++){
    cin>>c>>d;
    cout<<sum-vec[c-1]+d<<endl;
  }
}

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

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		for (;;) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int p = sc.nextInt();
			if ((n | m | p) == 0) {
				return;
			}
			int sum = 0;
			int[] x = sc.nextIntArray(n);
			for (int i = 0; i < n; i++) {
				sum += x[i] * 100;
			}
			sum = sum * (100 - p) / 100;
			System.out.println(x[m - 1] == 0 ? 0 : sum / x[m - 1]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	boolean inner(int h, int w, int lim) {
		return 0 <= h && h < lim && 0 <= w && w < lim;
	}

	void swap(int[] x, int a, int b) {
		int tmp = x[a];
		x[a] = x[b];
		x[b] = tmp;
	}

	// find minimum i (a[i] >= border)
	int lower_bound(int a[], int border) {
		int l = -1;
		int r = a.length;

		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (border <= a[mid]) {
				r = mid;
			} else {
				l = mid;
			}
		}
		// r = l + 1
		return r;
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}

		int[] nextIntArray(int n) {
			int[] in = new int[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextInt();
			}
			return in;
		}

		int[][] nextInt2dArray(int n, int m) {
			int[][] in = new int[n][m];
			for (int i = 0; i < n; i++) {
				in[i] = nextIntArray(m);
			}
			return in;
		}

		double[] nextDoubleArray(int n) {
			double[] in = new double[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextDouble();
			}
			return in;
		}

		long[] nextLongArray(int n) {
			long[] in = new long[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextLong();
			}
			return in;
		}
	}
}

Measured memory_bytes: 19312
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int a,b,h;
  cin>>a>>b>>h;
  cout << (a+b)*h/2 << endl;
  return 0;
}


Measured memory_bytes: 256
input = gets
#lst = input.split(" ").each{ |str|
#  str = str.to_i
#}
lst = input.split(" ")
for i  in 0..2
  lst[i] = lst[i].to_i
  #print l + ","
end
if lst[0] <= lst[2] && lst[0] + lst[1] >= lst[2]
    print("YES\n")
else
print("NO\n")
end




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

int main(){
  int n,h,w,ans=0;
  cin >> n >> h >> w;
  for(int i=0; i<n; i++){
    int a,b;
    cin >> a >> b;
    if( h<=a && w<=b ) ans++;
  }
  
  cout << ans << endl;
    
  return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	LL a = 1, b = 1;

	//現在の値がa,bだとする。
	//次の比率はx,yが与えられたとして。
	//x;y 2x:2y 3x:3y … nx:ny
	//の中でa,b両方を超えるnを探して更新する。
	//a<=nx,b<=ny;
	//nはa/xとb/yの厳しいほう。


	for (int i = 0; i < n; i++) {
		LL x, y; cin >> x >> y;

		LL n = max((a + x - 1) / x, (b + y - 1) / y);

		a = n*x; b = n*y;
	}

	cout << a+b << endl;

	return 0;
}

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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO;
	
	ll n;
	cin >> n;
	vector<ll> ar(n+1);
	
	for (int i = 1; i <= n; ++i) {
		for (ll j= i; j <= n; j+= i) {
			ar[j]++;
		}
	}
	
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans += (i * ar[i]);
	}
	
	cout << ans;
		
	
}


Measured memory_bytes: 81320
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] s = sc.nextLine().split(" ");
        String s1 = s[0];
        String s2 = s[1];
        for (int i = 0; i < n; i++) {
            System.out.print(String.valueOf(s1.charAt(i)) + String.valueOf(s2.charAt(i)));
        }
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	// cin.ignore(); must be there when using getline(cin, s)
	int d, t, s;
	cin >> d >> t >> s;

	string ans = "Yes";
	if (d > t * s) {
		ans = "No";
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
	while(1){
		string s;
		int m;
		
		cin >> s;
		if(s == "-") break;
		cin >> m;
		for(int i=0; i<m; ++i){
			int a;
			cin >> a;
			
			string add = s.substr(0,a);
			s = s+add;
			s = s.substr(a, s.size());
		}
		
		cout << s << endl;
	}
	return 0;
}



Measured memory_bytes: 3140
#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int n,k,x,y; cin >> n >> k >> x >> y;
    cout << (k<n?(n-k)*y+k*x:n*x) << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <random>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, y;
int main() {
  cin >> n >> y;
  lli a=0, b=0, c=0;
  for (a=0; a<=n; ++a) {
    for (b=0; b<=n-a; ++b) {
      c = n-a-b;
      if (10000*a + 5000*b + 1000*c == y) {
        cout << a << ' ' << b << ' ' << c << '\n';
        return 0;
      }
    }
  }
  cout << "-1 -1 -1\n";
  return 0;
}


Measured memory_bytes: 256
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define bf ios_base::sync_with_stdio (0), cin.tie (0)
typedef unsigned long long int li;
typedef long long ll;
typedef double d;
#define MAX 200001
#define MIN -1
#define mod 1000000007
#define INF 50000
using namespace std;
typedef vector<li> Vector;
typedef queue<li > Queue;
typedef stack<li> Stack;
typedef pair<li,li> Pair;
#define mp make_pair
#define pb push_back
li dp[1001];
int main(){
    //bf;
    li t,j,k,i,f; string s;
    cin>>t;
    f=t/11; i=t%11;
    if(i==0) cout<<f*2;
    else if(i<=6){
        cout<<f*2+1;
    }
    else cout<<f*2+2;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(A, B));

        sc.close();
    }

    static int solve(int A, int B) {
        return (A - 1) * (B - 1);
    }
}

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

using namespace std;

const int MAXN = 302;

int n;
double dp[MAXN][MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];

double solve(int x, int y, int z) {
  if(vis[x][y][z])
    return dp[x][y][z];
  vis[x][y][z] = 1;

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

  int total = x + y + z;
  double tot = (double)(n - total)/total;

  if(x != 0) tot += x*((solve(x-1,y,z) + 1)/total);
  if(y != 0) tot += y*((solve(x+1,y-1,z) + 1)/total);
  if(z != 0) tot += z*((solve(x,y+1,z-1) + 1)/total);
  return dp[x][y][z] = tot;
}

int main() {
  int a[4] = {0,0,0,0};
  cin >> n;
  for(int i=1; i<=n; ++i) {
    int x;
    cin >> x;
    ++a[x];
  }
  cout.precision(10);
  cout << solve(a[1],a[2],a[3]);
  return 0;
}


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

using namespace std;

int main(){
    int n, d, i, x;
    
    cin >> n >> d;
    
    x = d*2+1;

    
    i = (n/x);
    
    if(i*x < n){
    	i++;
    }
    
    cout << i << endl;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

ll f(ll b,ll n){
    ll res = 0;
    while(n>=b){
        res+=n%b;
        n/=b;
    }
    res+=n;
    return res;
}

int main(){
    ll n,s;
    cin >> n >> s;
    if(n==s){
        cout << n+1 << endl;
        return 0;
    }else if (n<s){
        cout << -1 << endl;
        return 0;
    }
    //b<=sqrt(n)
    for(ll i=2;i*i<=n;i++){
        if(f(i,n)==s){
            cout << i << endl;
            return 0;
        }
    }
    //b>sqrt(n)
    ll res = 1e12;
    for(ll p=1;p*p<=n;p++){
        ll b=(n-s+p)/p;
        if(b>1)if(f(b,n)==s)res=min(res,b);
    }
    if(res==1e12)res=-1;
    cout << res << endl;
    return 0;
}

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

long gcd(long a, long b) {
  long c;
  if(a < b) {
    long temp = a;
    a = b; 
    b = temp;
  }
 
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int main(){
  long a, b;
  
  while(cin >> a >> b) {
    long GCD = gcd(a, b);
    long LCM = a * b / GCD;
    cout << GCD << " " << LCM << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n, k = Scanf.sscanf (read_line ()) "%d %d" @@ fun n k -> (n, k)
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string

module IntMap = Map.Make(struct type t = int let compare = compare end)

let map = List.fold_left (fun map i ->
  let cnt = try IntMap.find i map with Not_found -> 0 in
  IntMap.add i (cnt + 1) map
) IntMap.empty a

let rec drop n acc = match (n, acc) with
  | (0, acc) -> acc
  | (_, []) -> []
  | (n, x :: xs) -> drop (n - 1) xs

let () =
  IntMap.bindings map
  |> List.sort (fun (_, a) (_, b) -> b - a)
  |> drop k
  |> List.map snd
  |> List.fold_left (+) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 60040
l=input().split()
r=int(l[0])
c=int(l[1])
l=[]
for i in range(r):
	s=input()
	l.append(s)
dp=[[0 for i in range(c)]for i in range(r)]
dp[0][0]=1
for i in range(1,r):
	if(l[i][0]=='#'):
		dp[i][0]=0
		continue
	dp[i][0]=dp[i-1][0]
for j in range(1,c):
	if(l[0][j]=='#'):
		dp[0][j]=0
		continue
	dp[0][j]=dp[0][j-1]
for i in range(1,r):
	for j in range(1,c):
		if(l[i][j]=='#'):
			dp[i][j]=0
		else:
			dp[i][j]=dp[i-1][j]+dp[i][j-1]
			dp[i][j]%=1000000007
print(dp[r-1][c-1])


Measured memory_bytes: 53852
import math

def main():
    N = int(input())
    dam_list  = list(map(int, input().split(" ")))
    water_list = [0 for i in range(N)]
    upstream = dam_list[N-1]
    downstream = 0
    
    for i in range(N):
        water_list[N-1-i] = water_list[N-1-i] + upstream
        water_list[i] = water_list[i] + downstream

        if i == N-1:
            break

        upstream = upstream * -1 + dam_list[N-1 - (i+1)]
        downstream = downstream * -1 + dam_list[i]

    for i in water_list:
        print(i, end=" ")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14264
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int ans;
int N;

int main(){
	cin >> N;

	for (int i = 0; i <= N; i++){
		if (1 <= i&&i <= 9)ans++;
		else if (100 <= i&&i <= 999)ans++;
		else if (10000 <= i&&i <= 99999)ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  int h,w;
  cin>>h>>w;

  vector<vector<int>> p(h,vector<int>(w));
  rep(i,h){
    rep(j,w){
      cin>>p[i][j];
    }
  }

  vector<vector<int>> ans;

  rep(i,h){
    if(i%2==0){
      rep(j,w-1){
        if(p[i][j]%2==1) {
          ans.pb({i+1,j+1,i+1,j+2});
          p[i][j+1]++;
        }
      }
      if(i+1<h){
          if(p[i][w-1]%2==1) {
          ans.pb({i+1,w,i+2,w});
          p[i+1][w-1]++;
        }
      }
    }
    if(i%2==1){
      for(int j=w-1;j>0;j--){
        if(p[i][j]%2==1) {
          ans.pb({i+1,j+1,i+1,j});
          p[i][j-1]++;
        }
      }
      if(i+1<h){
          if(p[i][0]%2==1) {
          ans.pb({i+1,1,i+2,1});
          p[i+1][0]++;
        }
      }
    }
  }

  cout << ans.size() << endl;
  rep(i,ans.size()){
    rep(j,4){
      cout << ans[i][j];
      if(j!=3) cout << " ";
      if(j==3) cout << endl;
    }
  }

}


Measured memory_bytes: 11952
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define IN(a, x, b) (a <= x && x < b)
#define OUT(a, x, b) (x < a || b <= x)
template <class T> inline T chmax(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T> inline T chmin(T &a, const T b) {
  return a = (a > b) ? b : a;
}

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

int powMod(int n, int p) {
	int res = 1;
	while (p) {
		if (p & 1) (res *= n) %= MOD;
		(n *= n) %= MOD;
		p >>= 1;
	}
	return res;
}
int invMod(int n) {
	return powMod(n, MOD - 2);
}
 

vector<pair<int, int>> primeFact(int n) {
  vector<pair<int, int>> res;
  for (int i = 2; i * i <= n; i++) {
    int divcnt = 0;
    if (n % i == 0) {
      do {
        divcnt++;
        n /= i;
      } while (n % i == 0);
      res.emplace_back(i, divcnt);
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

signed main() {
  int N;
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  map<int, int> m;
  REP(i, N){
    vector<pair<int, int>> pv(primeFact(A[i]));
    for(pair<int, int> p : pv){
      if(m[p.first] == 0) m[p.first] = p.second;
      else chmax(m[p.first], p.second);
    }
  }

  int l = 1;
  for(pair<int, int>p : m){
    l *= powMod(p.first, p.second);
    l %= MOD;
  }

  int ans = 0;
  REP(i, N){
    ans += l*invMod(A[i]);
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 896
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
point = 0
result = []
for i in range(n):
  if i+1 <= k or result[i-k] == "f" or t[i] != t[i-k]:
    if t[i] == "r":
      point += p
    elif t[i] == "s":
      point += r
    else:
      point += s
    result.append("t")
  else:
    result.append("f")
print(point)
    

Measured memory_bytes: 4792
import time
A=time.time()
p=[1 for i in range(1001)]
p[0]=0
p[1]=0
for i in range(2,1001):
    if p[i]==1:
        for j in range(2,1001):
            if i*j<=1000:
                p[i*j]=0
#print(p[:25])
Prime=[]
for i in range(1001):
    if p[i]==1:
        Prime.append(i)

#print(Prime)
#print(len(Prime))
N=int(input())
L=list(map(int,input().split()))

def gcd(a,b):
    if b>a:
        a,b=b,a
    while a%b!=0:
        a,b=b,a%b
    return b
    
X=L[0]
for i in range(1,N):
    X=gcd(X,L[i])
    if X==1:
        break
if X>1:
    print("not coprime")
    exit()
        
D={}

for I in L:
    B=time.time()
    if B-A>1.9:
        print("pairwise coprime")
        exit()
    for j in Prime:
        if I%j==0:
            if j not in D:
                D[j]=1
            else:
                print("setwise coprime")
                exit()
            while I%j==0:
                I//=j
    if I!=1:
        if I not in D:
            D[I]=1
        else:
            print("setwise coprime")
            exit()
#print(D)

print("pairwise coprime")

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

using namespace std;
typedef long long ll;
int main() {
  int n, k;
  ll r, s, p;
  string t;
  
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;

  vector<ll> points(n, -1);
  for (int i = 0; i < n; ++i) {
    if (points[i] < 0) {
      if (t[i] == 'r') {
	points[i] = p;
      } else if (t[i] == 'p') {
	points[i] = s;
      } else {
	points[i] = r;
      }
      if (i + k < n && t[i] == t[i + k]) {
	points[i + k] = 0;
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += points[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	vector<int> Number(5);
	scanf("%d%d%d%d%d", &Number[0], &Number[1],&Number[2],&Number[3],&Number[4]);
	sort(Number.begin(), Number.end(), greater<int>());
	printf("%d %d %d %d %d\n", Number[0], Number[1], Number[2], Number[3], Number[4]);
	return 0;
}

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

const int INF = 1000000000;
const int d_i[] = {-1,0,1,0};
const int d_j[] = {0,-1,0,1};

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H) cin >> S[i];
  int ans = 0;
  rep(S_i,H)rep(S_j,W){
    if(S[S_i][S_j] == '#') continue;
    vector<vector<int>> dist(H, vector<int>(W, INF));
    queue<P> q;
    dist[S_i][S_j] = 0;
    q.push(P(S_i,S_j));
    while(!q.empty()){
      int i = q.front().first;
      int j = q.front().second;
      q.pop();
      rep(dir,4){
        int n_i = i + d_i[dir];
        int n_j = j + d_j[dir];
        if(n_i < 0 || n_i >= H || n_j < 0 || n_j >= W) continue;
        if(S[n_i][n_j] == '#') continue;
        if(dist[n_i][n_j] != INF) continue;
        dist[n_i][n_j] = dist[i][j]+1;
        q.push(P(n_i,n_j));
      }
    }
    
  	rep(i,H)rep(j,W){
      if (dist[i][j] == INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
n = int(input())
s = input()

dic = {s[0]:1}
ans = 1
for i in range(1,n):
    if s[i] not in dic:
        ret = 1
        for v in dic.values():
            ret *= v + 1
            ret %= MOD
        ans += ret
        dic[s[i]] = 1
    else:
        ret = 1
        for k,v in dic.items():
            if k == s[i]:
                continue
            else:
                ret *= v + 1
                ret %= MOD
        ans += ret
        dic[s[i]] += 1
    ans %= MOD
print(ans)





Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin >> s;

    map<char,bool> dict;
    for(int i = 0;i < s.size();i++){
        dict[s[i]] = true;
    }

    int ans = 1000;
    for(auto p:dict){
        char c = p.first;
        string now = s;
        int cnt = 0;
        while(true){
            bool flag = false;
            for(int i = 0;i < now.size();i++){
                if(now[i] != c){
                    flag = true;
                    cnt++;
                    break;
                }
            }
            if(!flag)break;

            int now_size = (int)now.size();
            string next(now_size - 1,'*'); 

            for(int i = 0;i < next.size();i++){
                if(now[i] == c)next[i] = now[i];
                else if(now[i+1] == c)next[i] = now[i+1];
                else{
                    next[i] = now[i];
                } 
            }
            now = next;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        int t[n][n + 1] = {};
        rep(i, n)rep(j, n + 1) cin >> t[i][j];
        int dp[1<<n] = {};
        fill(dp, dp + (1<<n), INF);
        dp[0] = 0;
        rep(i, 1<<n) {
            int cnt = 0;
            int num = 0;
            rep(j, n) {
                if (i>>j & 1) {
                    num = j;
                    cnt++;
                }
            }
            if (cnt == 1) {
                dp[i] = t[num][0];
                continue;
            }
            rep(j, n) {
                if (!(i>>j & 1)) continue;
                int ti = t[j][0];
                rep(k, n) {
                    if (j == k) continue;
                    if (!(i>>k & 1)) continue;
                    ti = min(ti, t[j][k + 1]);
                }
                dp[i] = min(dp[i], dp[i^(1<<j)] + ti);
            }
        }
        cout << dp[(1<<n) - 1] << endl;
    }
}

Measured memory_bytes: 3380
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MAX_N = 3000 + 10, MOD = 1e9 + 7;
ll n, k, dp[MAX_N][MAX_N], fac[MAX_N * MAX_N], en[MAX_N * MAX_N], r,pwmakh, makh = 1;
ll pw(int x,int y){
	if(!y) return 1ll;
	ll t = pw(x, y / 2);
	t = 1ll * t * t % MOD;
	if(y & 1) t = 1ll * t * x % MOD;
	return t;
}
int32_t main(){
    cin>>n>>k;
    if(k == 1){
        cout<<1;
    }
    else{
        fac[0] = 1;
        for(int i = 1; i <= n * k; i++){
            fac[i] = fac[i - 1] * i;
            fac[i] %= MOD;
        }
        for(int i = 1; i <= k - 2; i++){
            makh *= i;
            makh %= MOD;
        }
        pwmakh = pw(makh, MOD - 2);
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++){
                if(j > 0){
                    if(en[i * k + j * (k - 1) - 1] == 0){
                        r = fac[i * k + j * (k - 1) - 1] * pwmakh % MOD * pw(fac[i * k + j * (k - 1) - 1 - (k - 2)], MOD - 2) % MOD;
                        en[i * k + j * (k - 1) - 1] = r;
                    }
                    else{
                        r = en[i * k + j * (k - 1) - 1];
                    }
                }
                if(i > 0 && j > 0){
                    dp[i][j] = dp[i - 1][j + 1] + (dp[i][j - 1] * r) % MOD;
                }
                else if(i == 0 && j > 0){
                    dp[i][j] = dp[i][j - 1] * r;
                }
                else if(i > 0 && j == 0){
                    dp[i][j] = dp[i - 1][j + 1];
                }
                else{
                    dp[i][j] = 1;
                }
                dp[i][j] %= MOD;
            }
        }
        /*for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++){
                cout<<dp[i][j]<<"  ";
            }
            cout<<endl;
        }*/
        ll ans = 1ll * dp[n][0] * fac[n] % MOD;
        cout<<ans;
    }
}


Measured memory_bytes: 144256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  char s;
  int cnt=0;
  for(int i=0;i<3;i++)
  {
    cin>>s;
    if(s=='o') cnt++;
  }

  int ans=700+cnt*100;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    int now = a + b;
    if (now < (a - b)) {
        now = a - b;
    }
    if (now < (a * b)) {
        now = a * b;
    }
    printf("%d", now);
    return 0;
}

Measured memory_bytes: 128
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

#import sys
#input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())
    A = [[0]*C for _ in range(R)]
    for i in range(K):
        r, c, v = map(int, input().split())
        r, c = r-1, c-1
        A[r][c] = v

    dp0 = [[0]*(C+1) for i in range(R+1)]
    dp1 = [[0]*(C+1) for i in range(R+1)]
    dp2 = [[0]*(C+1) for i in range(R+1)]
    dp3 = [[0]*(C+1) for i in range(R+1)]
    for i in range(R):
        for j in range(C):
            dp3[i][j] = max(dp3[i][j], dp2[i][j]+A[i][j])
            dp2[i][j] = max(dp2[i][j], dp1[i][j]+A[i][j])
            dp1[i][j] = max(dp1[i][j], dp0[i][j]+A[i][j])

            dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j])
            dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j])
            dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j])
            dp0[i][j+1] = max(dp0[i][j+1], dp0[i][j])

            dp0[i+1][j] = max(dp0[i+1][j], dp0[i][j])
            dp0[i+1][j] = max(dp0[i+1][j], dp1[i][j])
            dp0[i+1][j] = max(dp0[i+1][j], dp2[i][j])
            dp0[i+1][j] = max(dp0[i+1][j], dp3[i][j])
    #print(dp)
    print(max([dp0[R-1][C-1], dp1[R-1][C-1], dp2[R-1][C-1], dp3[R-1][C-1]]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 429416
//    _        _   __
//   (_)      | | / /
//    __ ___  | |/ / ___    ____
//   | |/ _ `\|   | / _ `\ / _  \
//   | | (_) | |\ \| (_) || (_) |
//   | |\__,_|_| \_\___,_|\____/
// _/ |
//|__/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007LL
#define lowbit(x) (x&-x)
using namespace std;
using ll = long long;


int main(){
	ios::sync_with_stdio(false);cin.tie(NULL);
	int arr[5];
	for(int i=0;i<4;i++)	cin>>arr[i];
	sort(arr,arr+4);
	cout<<abs(arr[0]+arr[3]-arr[1]-arr[2])<<endl;
	
	return 0;
}



Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  string s;
  cin >> s;
  int g=0;
  int score=0;
  rep(i,s.size()){
    if(s[i]=='g'){
      if(g>0){
        g--;
        score++;
      }
      else g++;
    }
    else{
      if(g>0){
        g--;
      }
      else{
        g++;
        score--;
      }
    }
  }
  cout << score << endl;
return 0;}

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

int main(){
	int n;
	cin >> n;
	vector<int> sum(n-1);
	for(int i=1; i<n; i++){
		int suma=0;
		int sumb=0;
		int c=i;
		int d=n-c;
		while (c>0){
			suma += c%10;
			c /=10;
		}
		while (d>0){
			sumb += d%10;
			d /=10;
		}
		sum.at(i-1)=suma+sumb;
	}
	sort(sum.begin(), sum.end());
	cout << sum.at(0) << endl;
}


Measured memory_bytes: 3640
n, m, l = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for y in range(n)]
b = [[int(x) for x in input().split()] for y in range(m)]
c = [[0 for x in range(l)] for y in range(n)]

for i in range(n):
    for j in range(l):
        c[i][j] = sum([a[i][x] * b[x][j] for x in range(m)])

for i in c:
    print(*i)

Measured memory_bytes: 8988
#include <stdio.h>
#define rep(i,j,k) for(i = j;i <= k;i++)

int main(){
  int n,k,a[100000],max,temp;

  while(1){
    int i,j;
    max = 0;
    scanf("%d%d",&n,&k);
    if (n == 0 && k == 0) break;
    rep(i,0,k-1){
      scanf("%d",&a[i]);
      max += a[i];
    }
    rep(i,1,n-k){
      scanf("%d",&a[k+i-1]);
      if(i == 1) temp = max - a[i-1] +a[k+i-1];
      else temp = temp - a[i-1] +a[k+i-1];      
      if(max < temp) max = temp;
    }

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

  }
    
  return 0;
}

Measured memory_bytes: 0
S = input()

first = int(S[0:2])
second = int(S[2:])

mm1 = first <= 12 and first > 0
mm2 = second <= 12 and second > 0

if mm1 and mm2:
    print('AMBIGUOUS')
elif mm1:
    print('MMYY')
elif mm2:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(s==u) cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int64_t gcd(int64_t m, int64_t n) {
  int64_t tmp;
  while (m % n != 0) {
    tmp = n;
    n = m % n;
    m = tmp;
  }
  return n;
}
int64_t lcm(int64_t a, int64_t b) { return a / gcd(a, b) * b; }

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, M;
  cin >> N >> M;
  int64_t b = 1;
  vector<int> A(N);
  rep(i, N) {
    int64_t a;
    cin >> a;
    A[i] = a;
    b = lcm(a, b);
  }
  int64_t c = b / 2;

  rep(i, N) {
    int64_t t = b / A[i];
    if (t % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  int64_t ans = (M / c) - (M / b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main() {
    int l, i=0, a[10000];
    while (cin>>l)
    {
        if (l==0) break;
        a[i] = l;
        i++;
        cout << "Case" << " " << i << ":" << " " << a[i-1] << endl;

    }

    
	return 0;
}



Measured memory_bytes: 3064
s = input()

ss = s.replace('x','')
if ss != ss[::-1]:
  print(-1)
  exit()

xc = []
c = 0
for i in range(len(s)):
  if s[i] == 'x':
    c += 1
  else:
    xc.append(c)
    c = 0
xc.append(c)
#print(xc)
ans = 0
for i in range(len(xc)//2):
  ans += abs(xc[i] - xc[len(xc)-1-i])
print(ans)


Measured memory_bytes: 45936
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

struct Combination{
    vector<long long> _fac,_finv,_inv;
    const int m = MOD;

    Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){
        _fac[0] = _fac[1] = 1;
        _finv[0] = _finv[1] = 1;
        _inv[1] = 1;
        for(int i = 2; i <= sz; i++){
            _fac[i] = _fac[i-1]*i%m;
            _inv[i] = m-_inv[m%i]*(MOD/i)%m;
            _finv[i] = _finv[i-1]*_inv[i]%m;
        }
    }

    inline int fac(int n){return _fac[n];}
    inline int inv(int n){return _inv[n];}
    inline int finv(int n){return _finv[n];}

    int comb(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return _fac[n]*(_finv[k]*_finv[n-k]%m)%m;
    }
};

int main(){
    int x,y; cin >> x >> y;
    if(2*x < y || 2*y < x || (2*x-y) % 3 != 0 || (2*y-x) % 3 != 0) cout << 0 << endl;
    else{
        int k = (2*y-x)/3;
        int l = (2*x-y)/3;
        Combination C(2000000);
        cout << C.comb(k+l,k) << endl;
    }
}


Measured memory_bytes: 47104