akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	string S, T;
	cin >> S >> T;
	vl C(26);
	vl D(26);
	for (i = 0; i < S.length(); i++) {
		C[S[i] - 'a']++;
		D[T[i] - 'a']++;
	}
	sort(C.begin(), C.end());
	sort(D.begin(), D.end());
	if (C == D) cout << "Yes";
	else cout << "No";

}

Measured memory_bytes: 776
#include<stdio.h>
int prime(int n){
  int i;
  for(i=2;i*i<=n;i++){
    if(n % i == 0){
      return 0;
    }
  }
  return 1;
}
int main(){
  int n, i;
  scanf("%d", &n);
  while(n != 0){
    for(i=n;i>0;i--){
      if(prime(i)){
        if(prime(i-2)){
          printf("%d %d\n", i-2, i);
          break;
        }
      }
    }
    scanf("%d", &n);
  }
  return 0;
}

Measured memory_bytes: 1804
/*ex 9_2
  saitomo*/
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100001
//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    int count=0;
    char cube_color[SIZE];
    scanf("%s", cube_color);
    //最初のノードの指す先
    node *first = NULL;
    //キューブを積み上げていく
    for(int i=0; i<strlen(cube_color); i++){
        if(first == NULL || first->elem == cube_color[i]){//色が同じなら単純に積み上げ
            push(&first, cube_color[i]);
        }else{//違うなら一つ取り除きカウントを2あげる
            pop(&first);
            count=count+ 2;
        }
    }
    printf("%d\n",count);

    return 0;
}


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

using ll = long long;

int main()
{
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);
    for (int i = 0; i < N; i++)
        cin >> t[i];
    ll ans = 0LL;
    for (int i = 0; i < N - 1; i++)
    {
        ans += min(T, t[i + 1] - t[i]);
    }
    cout << ans + T << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int e=0;
	if(a>b)e+=b;
	else  e+=a;
	if(c>d) e+=d;
	else e+=c;
	cout<<e;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>vec(n*3);
  for(int i = 0;i<n*3;i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  long long total = 0;
  for(int i = 0;i<n;i++){
        total+=vec[n+i*2];
  }
    cout << total << endl;
}

Measured memory_bytes: 1408
const val m = 1000000007L
fun main(args: Array<String>) {
    val n = getInt()
    val a = getLongs()
    var sum = 0L
    a.forEach {
        sum = (sum + it) % m
    }

    var out = 0L
    a.forEach {
        sum -= it
        if (sum < 0) sum += m
        out = (out + sum * it) % m
    }
    println(out)
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }
fun getLong() = readLine()!!.toLong()
fun getLongs() = readLine()!!.split(" ").map { it.toLong() }



Measured memory_bytes: 64720
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
cnt = 0
while B != A:
    for i in range(n):
        a, c = B[i-1], B[(i+1)%n]
        if (B[i] > A[i]) &\
           (B[i] > a) &\
           (B[i] > c):
            d = (B[i]-max(A[i], a, c)+a+c-1)//(a+c)
            B[i] -= (a+c)*d
            cnt += d
        elif B[i] < A[i]:
            print(-1)
            exit()
print(cnt)

Measured memory_bytes: 122432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int nokori = a;
		nokori -= b;
		boolean kaeru = true;
		while(kaeru == true) {
			if(nokori>=c) {
				nokori -= c;
			}else {
				kaeru = false;
			}
		}
		System.out.println(nokori);
	}

}


Measured memory_bytes: 22612
#include"bits/stdc++.h"
using namespace std;

int main(){
  for(int l=0;l<100;l++){
  	int N;
	cin >> N;
    if(N == 0){
      break;
    }
	int player[108];
  	string card;
 	cin >> card;
  	int ba=0;
    
    for(int i=0;i<N;i++){
        player[i] = 0;
    }
    
    for(int i=0;i<100;i++){
      if(i<N){
        player[i]++;
       	if(card[i] == 'S'){
        	ba += player[i];
       		player[i] = 0;
      	}	
    	else if(card[i] == 'L'){
       		player[i] += ba;
       		ba = 0;
      	}
      }
      
      else{
        player[i%N]++;
      	if(card[i] == 'S'){
       	 	ba += player[i%N];
       	 	player[i%N] = 0;
      	}
     	else if(card[i] == 'L'){
       		player[i%N] += ba;
       		ba = 0;
      	}
      }
    }
    
    sort(player,player+N);
    
    for(int i=0;i<N;i++){
      cout << player[i] << " ";
    }
    
    cout << ba << endl;
  }	
  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int n;
    cin >> n;
    int h[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    h[0] = h[1];
    int dp[n + 1];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    for (int i = 2; i < n; i++)
        dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i - 1] + abs(h[i + 1] - h[i - 1]));

    OP(dp[n]);

    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int N, x = 0, ans = 0;
    string S;
    cin >>N >> S;

    for (int i = 0; i < N; i++) {
        (S[i] == 'I') ? x++ : x--;
        ans = max(ans, x);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int ans = A[0];

    auto gcd = [](int a, int b){
        while(1){
            swap(a,b);
            if(b == 0) return a;
            a%=b;
        }
    };

    rep(i,N){
        ans = gcd(ans,A[i]);
    }
    cout << ans << endl;
}

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

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

    int N, K; cin >> N >> K;
    string S; cin >> S;

    vector<int> v = {0};
    char p = S[0];
    for (int i = 1; i < N; i++) {
        if (S[i] != p) {
            v.push_back(i);
            p = S[i];
        }
    }
    v.push_back(N);
    int M = v.size();
    
    int ans = 0;
    for (int i = 0; i < M-1; i++) {
        int d = S[v[i]]-'0';
        ans = max(ans, v[min(i+2*K+d, M-1)] - v[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no = 1;
#define w(x) int x; cin>>x; while(x--)
#define ANS #ifndef ONLINE_JUDGE freopen("answer.txt", "w", stdout); #endif
	/*
	#ifndef ONLINE_JUDGE 
   	freopen("input.txt", "r", stdin); 
   	freopen("error.txt", "w", stderr); 
   	freopen("answer.txt", "w", stdout); 
   	#endif 
   	*/
int main() {
	FIO
	int n, cnt = 0; cin >> n;
	char ch[n];
	for(int i = 0; i < n; i++) {
		cin >> ch[i];
		//if(ch[i] == 'W') cnt++;
	}
	//cnt % 2 == 0 ? cnt = 0 : cnt = 1;
	int white = 0, red = n - 1;
	while(white <= red) {
		if(ch[white] == 'W' and ch[red] == 'R') {
			cnt++;
			white++;
			red--;
		}
		else if(ch[white] == 'R') white++;
		else if(ch[red] == 'W') red--;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}


char c;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> c) {
        cout << (char)(c+1) << endl;
    }
}


















Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200010
using namespace std;
struct pos1{int l, r, f;}pos[N];
int n, m, w[N], L, R, mid, a[N], l;
inline int check(int mid){
	for(int i=1; i<=n; i++)a[i]=w[i]>=mid?1:0; a[0]=a[n+1]=0;
	l=1; pos[1].l=pos[1].r=pos[1].f=0;
	for(int i=1; i<=n; i++)
		if(a[i]==a[i-1]){
			if(pos[l].r==i-1)pos[l].r++;
			else{l++; pos[l].l=i-1; pos[l].r=i; pos[l].f=a[i];}
		}
	if(pos[l].f||pos[l].r<=n-1){l++; pos[l].l=a[n]?n+1:n;}
	pos[l].r=n+1; pos[l].f=0;
	if(l==1)return 0;
	int L, R;
	for(int i=1; i<=l-1; i++){
		L=pos[i].r+1; R=pos[i+1].l-1;
		if(R-L+1<=2*m){pos[i].r+=(R-L+1)/2; pos[i+1].l-=(R-L+2)/2;}
		else{pos[i].r+=m; pos[i+1].l-=m;}
	}
	int x=m+1;
	for(int i=1; i<=l; i++){
		if(pos[i].l<=x&&x<=pos[i].r)return pos[i].f;
		if(pos[i].r<x&&x<pos[i+1].l)return (pos[i].f+x-pos[i].r)&1;
	}
}
int main(){
	scanf("%d", &n); m=n-1; n=n*2-1;
	for(int i=1; i<=n; i++)scanf("%d", &w[i]);
	L=1; R=n;
	while(L<R){
		mid=(L+R)>>1; if(L==R-1)mid++;
		if(check(mid))L=mid; else R=mid-1;
	}
	printf("%d", L);
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int n, m, t;
int a[3];
vector<vector<int>> mul(vector<vector<int>> &a, vector<vector<int>> &b){
	int r1 = a.size(), c1 = a[0].size();
	int r2 = b.size(), c2 = b[0].size();
	assert(c1 == r2);
	auto res = vector<vector<int>>(r1, vector<int>(c2));

	rep(i, r1) rep(j, c2){
		int sum = 0;
		rep(k, c1){
			sum = (sum + a[i][k] * b[k][j]) % m;
		}
		res[i][j] = sum;
	}

	return res;
}

vector<vector<int>> mod_pow(vector<vector<int>> v, int p){
	auto res = v;
	rep(i, n) rep(j, n) res[i][j] = i == j;

	while (p){
		if (p & 1) res = mul(res, v);
		v = mul(v, v);
		p /= 2;
	}

	return res;
}

int main(){
	while (cin >> n >> m >> a[0] >> a[1] >> a[2] >> t, n){
		vector<vector<int>> ss(n);
		rep(i, n){
			int s;
			cin >> s;
			ss[i].push_back(s);
		}

		auto v = vector<vector<int>>(n, vector<int>(n, 0));
		rep(i, n){
			for (int j = -1; j <= 1; ++j){
				if (0 <= i + j && i + j < n) v[i][i + j] = a[j + 1];
			}
		}

		auto tmp = mod_pow(v, t);
		auto ans = mul(tmp, ss);

		bool f = true;
		for (auto v : ans) for (auto e : v){
			if (!f) cout << " ";
			f = false;
			cout << e;
		}
		cout << endl;
	}

	return 0;
}

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

using ll = long long;

const ll MOD = 1000000007;

int main() {
    int H, W;
    std::cin >> H >> W;

    std::vector<std::vector<char>> A(H, std::vector<char>(W));
    for(int i = 0; i < H; ++i) {
        std::string line;
        std::cin >> line;
        for(int j = 0; j < W; ++j) {
            A[i][j] = line[j];
        }
    }

    std::vector<std::vector<ll>> F(H, std::vector<ll>(W));
    F[0][0] = 1;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(A[i][j] == '.') {
                if(i > 0) {
                    F[i][j] += F[i - 1][j];
                }
                if(j > 0) {
                    F[i][j] += F[i][j - 1];
                }
                F[i][j] %= MOD;
            }
        }
    }

    std::cout << (F[H - 1][W - 1] % MOD) << "\n";
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, M, a, b;
  std::cin >> N >> M;
  std::vector<bool> A(N+1, true);
  for(int i=0;i<M;i++){
    std::cin >> a >> b;
    if(a==1) A[b] = (A[b]?false:true);
    else if(b==1) A[a] = (A[a]?false:true);
    else A[b] = (A[b]?false:true), A[a] = (A[a]?false:true);
  }
  bool flag = true;
  for(int i=1;i<=N;i++) if(!A[i]) flag = false;
  std::cout << (flag?"YES":"NO") << '\n';
  return 0;
}


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

using namespace std;

vector <int> Solve(int n, int u, int v)
{
    vector <int> res;
    if (n == 0) return res = {u, v};
    int Z = (1<<n) & u, ZZ = Z^(1<<n);
    if ((u>>n) == (v>>n)) {
        vector <int> vec = Solve(n-1, u^Z, v^Z);
        vector <int> _vec = Solve(n-1, vec[0], vec[1]);
        res.push_back(vec[0]^Z);
        for (int i : _vec) res.push_back(i^ZZ);
        for (int i = 1; i < vec.size(); i++) res.push_back(vec[i]^Z);
    }
    else {
        vector <int> vec = Solve(n-1, u^Z, __builtin_popcount(u^Z)&1^1);
        vector <int> _vec = Solve(n-1, __builtin_popcount(v^ZZ)&1^1, v^ZZ);
        for (int i : vec) res.push_back(i^Z);
        for (int i : _vec) res.push_back(i^ZZ);
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, a, b; cin >> n >> a >> b;
    if ((__builtin_popcount(a)&1) == (__builtin_popcount(b)&1)) return cout << "NO\n", 0;
    cout << "YES\n";
    vector <int> ans = Solve(n - 1, a, b);
    for (int i : ans) cout << i << " ";
    cout << "\n";

    return 0;
}


Measured memory_bytes: 1756
#include <stdio.h>
int main()
{
    long long n, k, q;
    long long a;
    long long p[100010] = {};
    scanf("%lld %lld %lld", &n, &k, &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%lld", &a);
        p[a]++;
    }
    for (int i = 1; i <= n; i++)
    {
        if (p[i] > q - k)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

struct N {
  ll a, b, c;
};
bool operator<(const N &l, const N &r) { return l.c > r.c; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<N> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i].a >> c[i].b;
    c[i].c = c[i].a + c[i].b;
  }
  sort(c.begin(), c.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      ans += c[i].a;
    else
      ans -= c[i].b;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2688
/**
 *    Creator :  bizarre
 *    Date : 4/2020
 *    Problem Number : 424
**/
#include <bits/stdc++.h>
using namespace std;
#define bizarre     ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );
/*
vector<int> prime_Numbers;
int primes[1000005];
void prime(int n)
{
    primes[1]=primes[0]=0;
    for(int i=2; i<=n; i++)
        primes[i]=true;
    for(int i=2; i<=n; i++)
    {
        if(primes[i]==true)
        {
            prime_Numbers.push_back(i);
            for(int j=i+i; j<=n; j+=i)
                primes[j]=false;
        }
    }
    for(int i=2; i<=n; i++)
        primes[i]+=primes[i-1];
}

void move1step(long long& a, long long& b, long long q)
{
    long long c= a-q*b;
    a=b;
    b=c;
}
long long egcd(long long r0,long long r1,long long& x0,long long& y0)
{
    long long x1=0,y1=1;
    x0=1;
    y0=0;
    while(r1)
    {
        long long q=r0/r1;
        move1step(r0,r1,q);
        move1step(x0,x1,q);
        move1step(y0,y1,q);
    }
    return r0;
}
bool  solve (long long a, long long b, long long c,long long&x, long long& y)
{
    long long g=egcd(a,b,x,y);
    int m=c/g;
    x*=m;
    y*=m;
    return c%g==0;
}



int npr(long long n, long long r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
void PrimeFactorization(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        int c=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
            }

        }
    }

}
const int inf = 2e9, mod = 1e9 + 7,N=1e5+5;
long long fact[N], inv[N];
long long fp(long long base, long long exp)
{
    if (exp == 0)
        return 1;
    long long ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}
void pre(long long n)
{
    fact[0] = 1;
    inv[0] = 1;
    for (long long i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
int ncr(long long n, long long r)
{
    return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}
long long ncrtane(long long n, long long r)
{
    long long ans=1,cntr=1;
    for(int i=n;i>n-r;i--)
    {
        ans*=i;
        ans/=cntr;
        cntr++;
    }
    return ans;
}
*/
const int mod=1e9+7;
int main()
{
    bizarre
     int n,m;
     cin>>n>>m;
     char arr[n+2][m+2];
     for(int i=0;i<n;i++)
        cin>>arr[i];
     long long dp[n+2][m+2];
     memset(dp,0,sizeof dp);
     dp[0][0]=1;
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<m;j++)
         {
             if(arr[i-1][j]=='.'&&i-1>=0)
                dp[i][j]+=dp[i-1][j];
             if(arr[i][j-1]=='.'&&j-1>=0)
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=mod;
            //cout << dp[i][j]<<endl;
         }
     }
     cout << dp[n-1][m-1];
    return 0;
}


Measured memory_bytes: 9088
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a%3 == 0){
        printf("Possible\n");
    }else if(b%3 == 0){
        printf("Possible\n");
    }else if((a+b)%3 == 0){
        printf("Possible\n");
    }else{
        printf("Impossible\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<utility>//pair
#include<list>
#include<vector>//可変長配列
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<ll,ll>
#define F first
#define S second
int dx[8] = { 1,0,-1,0,1,-1,-1,1 };
int dy[8] = { 0,1,0,-1,1,1,-1,-1 };


ll n, a, b;


int main() {
	cin >>  a >> b >> n;
	ll now;
	if (n >= b - 1)
		now = b - 1;
	else
		now = n;

	cout << (a * now) / b - a * (now / b);


	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<double> v(N);
  for(int i=0;i<N;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  vector<double> H(N-1);
  H[0]=(v[0]+v[1])/2;
  for(int i=1;i<N-1;i++){
    H[i]=(H[i-1]+v[i+1])/2;
  }
   printf("%.14f\n",H[N-2]);
}

Measured memory_bytes: 256
N = int(input())
S = input()
mod = 10**9+7
base = 1234
power = [1]*(N+1)
for i in range(1, N+1):
    power[i] = power[i-1]*base%mod
def check(m):
    dic = {}
    for i in range(N-m+1):
        s = S[i:i+m]
        if s in dic.keys():
            if dic[s]+m<=i:
                return True
        else:
            dic[s] = i
    return False
ok = 0
ng = N+1
while ng-ok>1:
    mid = (ok+ng)//2

    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 9636
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStream is = System.in;
		solve(is);
	}

	private static void solve(InputStream is) {
		try (Scanner cin = new Scanner(is)) {
			int m = cin.nextInt();
			int n = cin.nextInt();

			if (m == 0) {
				if (n != 100) {
					System.out.println(n);
				} else {
					System.out.println(101);
				}
			} else if (m == 1) {
				if (n != 100) {
					System.out.println(100 * n);
				} else {
					System.out.println(10100);
				}
			} else {
				if (n != 100) {
					System.out.println(10000 * n);
				} else {
					System.out.println(1010000);
				}
			}
		}
	}
}


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

int main() {
  int N, X, L;
  cin >> N;

  vector<pair<long long, long long>> R(N);
  for (int i = 0; i < N; i++) {
    cin >> X >> L;
    R.at(i) = make_pair(X + L, X - L);
  }

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

  int res = 0;
  int cnt = -1001001001;
  for (int i = 0; i < N; i++) {
    long long E, S;
    tie(E, S) = R.at(i);
    if (cnt <= S) {
      cnt = E;
      res ++;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 1792
dic1 = {}
dic2 = {}

while True:
  s = input()
  if s == "":
    break

  c, d = map(int, s.split(","))

  if c in dic1:
    dic1[c] += 1
  else:
    dic1[c] = 1

while True:
  try:
    c, d = map(int, input().split(","))

    if c in dic1:
      if c in dic2:
        dic2[c] += 1
      else:
        dic2[c] = 1

  except EOFError:
    break

for k, v in sorted(dic2.items()):
  print(k, v + dic1[k])



Measured memory_bytes: 5596
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
int main() {
	// 入力
	ll N;cin>>N;
    
    
	// 解法
	ll ans = (N*(N-1))/2;
    
	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int n;
int a[32];
int mini;
int s;

void rec(int teamA, int idx)
{
	if(idx == n){
		int dx = 2 * teamA - s;
		if(dx < 0){
			dx *= -1;
		}
		if(dx < mini){
			mini = dx;
		}
		return ;
	}
	rec(teamA + a[idx], idx + 1);
	rec(teamA         , idx + 1);
	return ;
	
}

int main(void)
{
	int i;
	
	while (scanf("%d", &n) && n){
		s = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			s += a[i];
		}
	
		mini = 100000000;
		rec(0, 0);
	
		printf("%d\n", mini);
	}
	return (0);
}

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

    vl a(n);
    bool zero = false;
    ll cnt = 0;
    ll sum = 0;
    vl x(n);
    rep(i, n) {
        cin >> a[i];
        x[i] = abs(a[i]);
        sum += abs(a[i]);
        if(a[i] == 0) {
            zero = true;
        }
        if(a[i] < 0) {
            cnt++;
        }
    }
    sort(all(x));
    
    if(zero) {
        out(sum);
        re0;
    }

    if(cnt%2 == 0) {
        out(sum);
    }
    else {
        out(sum - 2*x[0]);
    }
        
    re0;
}

Measured memory_bytes: 1792
def main():
    S,T = input().split()
    A,B = map(int,input().split())
    U = input()
    if U == S :
        print("{0} {1}".format(A-1,B))
    else:
        print("{0} {1}".format(A , B - 1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
import java.util.PriorityQueue;
import java.util.Scanner;

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

        int n = sc.nextInt();

        PriorityQueue<Integer> q = new PriorityQueue<>(n);

        for (int i = 0; i < n; i++) {
            q.add(sc.nextInt());
        }

        while (q.size() > 1) {
            int smallest = q.poll();
            int nextSmallest = q.poll();

            if (nextSmallest % smallest != 0)
                q.add(nextSmallest % smallest);

            q.add(smallest);
        }

        System.out.println(q.poll());
    }
}

Measured memory_bytes: 62676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
  unsigned long long a[5000]={0},c=0,p,o,u;
  rep(i,n){
    scanf("%d%d%d",&p,&o,&u);
    a[p]+=o*u;
    if(a[p]>999999){cout<<p<<endl;c++;}
  }
  if(!c)cout<<"NA"<<endl;
}}

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

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		int tan = 0 ;
		int suu = 0 ;
		int ave = 0;
		int total = 0;
		int kaz = 0;
		while (s.hasNext()) {
			String string = s.nextLine();
			String[] stra = string.split(",");
			tan = Integer.parseInt(stra[0]);
			suu = Integer.parseInt(stra[1]);
			total = (tan * suu) + total ; 
			kaz += suu;
			ave++;			
		}
		System.out.println(total);
		System.out.println((int)((double)kaz/ave+0.5));
		
		s.close();
	}

}

Measured memory_bytes: 17128
import java.util.Scanner;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        for (int i = 0; i < 26; i++) {
            if (S.indexOf('a' + i) == -1) {
                System.out.println((char) ('a' + i));
                return;
            }
        }
        System.out.println("None");
    }
}


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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  vector<int> array;
  array.push_back(a);
  array.push_back(b);
  array.push_back(c);
  array.push_back(d);
  array.push_back(e);


  int min = 10;
  int min_i = 0;
  for (int i = 0; i < array.size(); i++) {
    int tmp = array[i] % 10;
    if (min > tmp && tmp != 0) {min = tmp; min_i = i;}
  }
  swap(array[array.size() - 1], array[min_i]);

  int res = 0;
  for (int i = 0; i < array.size(); i++) {
    res += array[i];
    if (i == array.size() - 1) break;
    if (res % 10 == 0) {
      continue;
    } else {
      res += 10 - res % 10;
    }
  }
  cout << res << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//有向気味でもなぜかよさそうと解説放送で聞いたけど

int N;
int C[200001];
int E[200001];
int next[200001];
int H[200001];
void dfs(int p, int c) {
	C[p] = c + C[p];
	for (int i = H[p]; i; i = next[i]) {
		dfs(E[i], C[p]);
	}
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = ' ';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

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


	int N = getint(), Q = getint();
	int k = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[k] = b;
		next[k] = H[a];
		H[a] = k++;
	}
	rep(i, Q) {
		int p = getint(), x = getint();
		C[p] += x;
	}
	dfs(1, 0);

	rep1(i, N) putint(C[i]);

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 13824
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int A,B,K;
    Set<Integer> set = new TreeSet<Integer>();
    A = s.nextInt();
    B = s.nextInt();
    K = s.nextInt();
    for(int i = A; i < A + K && i <= B ; i++){
      set.add(i);
    }

    for(int i = B; i > B - K && i >= A ; i--){
      set.add(i);
    }

    for (Iterator<Integer> itr = set.iterator(); itr.hasNext();) {
      System.out.println(itr.next());
    }

  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

void solve(){
    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;
    vector<int> ans(n, 0);
    for(int i = 0; i < n; i++){
        queue<int> q;
        vector<bool> v(n, false);
        vector<int> d(n, 1e9);
        q.push(i);
        v[i] = true;
        d[i] = 0;
        while(!q.empty()){
            int node = q.front();
            q.pop();
            vector<int> adj;
            if(node > 0) adj.push_back(node-1);
            if(node < n-1) adj.push_back(node+1);
            if(node == x) adj.push_back(y);
            if(node == y) adj.push_back(x);

            for(int next : adj){
                if(!v[next]){
                    v[next] = true;
                    d[next] = 1+d[node];
                    q.push(next);
                } 
            }
        }

        for(int j = 0; j < n; j++){
            ans[d[j]]++;
        }
    }

    for(int i = 1; i < n; i++){
        cout << ans[i]/2 << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3616
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{s:chars};
    let mut map = HashMap::new();
    for ch in s {
        let mut count = map.entry(ch).or_insert(0);
        *count += 1;
    }
    if map.len() == 4 { println!("Yes"); return (); }
    else if map.len() == 3 || map.len() == 1 { println!("No"); return (); }

    if map.contains_key(&'W') && map.contains_key(&'E') || map.contains_key(&'N') && map.contains_key(&'S') { println!("Yes"); } else { println!("No"); }
}

Measured memory_bytes: 4352
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	sc.Scan()
	s := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(s[0])
	m, _ := strconv.Atoi(s[1])
	l, _ := strconv.Atoi(s[2])

	A := make([][]int, n)
	for i := range A {
		A[i] = make([]int, m)
	}

	B := make([][]int, m)
	for i := range B {
		B[i] = make([]int, l)
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		s := strings.Split(sc.Text(), " ")
		for j := 0; j < m; j++ {
			A[i][j], _ = strconv.Atoi(s[j])
		}
	}

	for i := 0; i < m; i++ {
		sc.Scan()
		s := strings.Split(sc.Text(), " ")
		for j := 0; j < l; j++ {
			B[i][j], _ = strconv.Atoi(s[j])
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < l; j++ {
			tmp := 0
			for k := 0; k < m; k++ {
				tmp += A[i][k] * B[k][j]
			}
			fmt.Print(tmp)
			if j != l-1 {
				fmt.Print(" ")
			}
		}
		fmt.Println("")
	}
}



Measured memory_bytes: 1892
program sequential_operations_on_sequence
  implicit none
  integer :: n, q, i, j, u = 1, l, r, m, x
  integer(8) :: p(0:100000) = 0_8, k, t(100000) = 0_8, ans(100001) = 0_8
  read(*,*) n, q
  p(1) = int(n,8)
  do i = 1, q
    read(*,*) k
    do while (k <= p(u))
      u = u-1
    end do
    u = u+1
    p(u) = k
  end do
  t(u) = 1_8
  do i = u, 1, -1
    j = i
    k = p(i)
    do while (k > p(1))
      r = j
      l = 1
      do while (r-l > 1)
        m = (l+r)/2
        if (p(m) > k) then
          r = m
        else
          l = m
        end if
      end do
      j = l
      t(j) = t(j)+t(i)*(k/p(j))
      k = mod(k,p(j))
    end do
    x = int(k,4)
    ans(x) = ans(x)+t(i)
  end do
  do i = n, 1, -1
    ans(i) = ans(i)+ans(i+1)
  end do
  do i = 1, n
    write(*,'(i0)') ans(i)
  end do
end program sequential_operations_on_sequence

Measured memory_bytes: 3968
#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;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
ll dp[3010][3010][4] = {};
ll item[3010][3010] = {};
int main(){
    cout << fixed << setprecision(10);
    int r,c,k;
    cin >> r >> c >> k;
    rep(i,k){
        ll x,y,z;
        cin >> x >> y >> z;
        x--; y--;
        item[x][y] = z;
    }
    dp[0][0][1] = item[0][0];
    rep(i, r){
        rep(j, c){
            rep(k, 4){
                if(k == 0){
                    if(j - 1 >= 0){
                        chmax(dp[i][j][k], dp[i][j-1][k]);
                    }
                    rep(l, 4){
                        if(i - 1 >= 0) chmax(dp[i][j][k], dp[i-1][j][l]);
                    }
                }
                else if(k == 1){
                    if(j - 1 >= 0){
                        chmax(dp[i][j][k], dp[i][j-1][k]);
                        chmax(dp[i][j][k], dp[i][j-1][k-1] + item[i][j]);
                    }
                    rep(l, 4){
                        if(i - 1 >= 0) chmax(dp[i][j][k], dp[i-1][j][l] + item[i][j]);
                    }
                }else if(k == 2){
                    if(j - 1 >= 0){
                        chmax(dp[i][j][k], dp[i][j-1][k]);
                        chmax(dp[i][j][k], dp[i][j-1][k-1] + item[i][j]);
                    }
                }else if(k == 3){
                    if(j - 1 >= 0){
                        chmax(dp[i][j][k], dp[i][j-1][k]);
                        chmax(dp[i][j][k], dp[i][j-1][k-1] + item[i][j]);
                    }
                }
            }
        }
    }
    ll ans =  max({dp[r-1][c-1][0],dp[r-1][c-1][1],dp[r-1][c-1][2],dp[r-1][c-1][3] });
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 356180
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

vec san(32, 1);

int bit3_t(ll a, int t){
    return (a % san[t + 1]) / san[t];
}

bool between(ll x, ll y1, ll y2){
    if(y1 > y2) swap(y1, y2);
    ++y1; --y2;
    if(!(y1 <= y2)) return false;
    while(x > 0){
        if(x%3 == 1){
            if(y2 - y1 > 3) return true;
            for(ll y = y1; y <= y2; ++y) if(y%3 == 1) return true;
        }
        x /= 3;
        y1 /= 3;
        y2 /= 3;
    }
    return false;
}

ll f(ll a, ll b, ll c, ll d){
    ll res = 0;
    Rrep(i, 31){
        /*if(bit3_t(b, i) == 1 && bit3_t(d, i) == 1){
            swap(a, b);
            swap(c, d);
        }*/
        if(a / san[i] == c / san[i]){
            //if(abs(d - b) >= 2 * san[i]
            //|| abs((d % (san[i + 1])) / san[i] - (b % (san[i + 1])) / san[i]) == 2){
            if(between(a / san[i], b / san[i], d / san[i])){
                ll diff1 = a % san[i], diff2 = c % san[i];
                res = max(res, min({diff1 + 1, san[i] - diff1,
                                    diff2 + 1, san[i] - diff2}) * 2);
            }
        }
    }
    return res;
}


int main() {
    cin>>Q;
    reps(i, 1, 32) san[i] = san[i-1] * 3;
    rep(i,Q){
        vec v(4);
        rep(j,4){
            cin>>v[j];
            --v[j];
        }
        ll res = abs(v[0] - v[2]) + abs(v[1] - v[3]);
        //cout<<res<<endl;
        cout<<res + max(f(v[0], v[1], v[2], v[3]), f(v[1], v[0], v[3], v[2]))<<endl;
    }
}

Measured memory_bytes: 384
#include<iostream>

int main(void){
    int n=0,k=0,a=0;
    scanf("%d",&n);
    scanf("%d",&k);
    int h[n+1];
    
    for(int i=1;i<=n;i++){
        scanf("%d",&h[i]);
        if(h[i]>=k){
            a++;
        }
    }
    printf("%d\n",a);
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int k;
    cin >> k;
    int r = 7 % k;
    for (int i = 0; i < 2000000; ++i)
    {
        if (r == 0)
        {
            cout << i + 1;
            return 0;
        }
        r = (r * 10 + 7) % k;
    }
    cout << "-1";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <random>
const int HOUSES = 4;
const int STORIES = 3;
const int ROOMS = 10;
int house[HOUSES][STORIES][ROOMS];
struct Die
{
	int A_One;
	int B_Two;
	int C_Three;
	int D_Four;
	int E_Five;
	int F_Six;
};
Die GoNorth(Die pips)
{
	int tmp = pips.A_One;
	pips.A_One = pips.B_Two;
	pips.B_Two = pips.F_Six;
	pips.F_Six = pips.E_Five;
	pips.E_Five = tmp;
	return pips;
}
Die GoSouth(Die pips)
{
	int tmp = pips.A_One;
	pips.A_One = pips.E_Five;
	pips.E_Five = pips.F_Six;
	pips.F_Six = pips.B_Two;
	pips.B_Two = tmp;
	return pips;
}
Die GoEast(Die pips)
{
	int tmp = pips.D_Four;
	pips.D_Four = pips.F_Six;
	pips.F_Six = pips.C_Three;
	pips.C_Three = pips.A_One;
	pips.A_One = tmp;
	return pips;
}
Die GoWest(Die pips)
{
	int tmp = pips.A_One;
	pips.A_One = pips.C_Three;
	pips.C_Three = pips.F_Six;
	pips.F_Six = pips.D_Four;
	pips.D_Four = tmp;
	return pips;
}
Die Roll(Die die, char c)
{
	if (c == 'N')
	{
		die = GoNorth(die);
	}
	else if (c == 'W')
	{
		die = GoWest(die);
	}
	else if (c == 'S')
	{
		die = GoSouth(die);
	}
	else
	{
		die = GoEast(die);
	}
	return die;
}
Die RandomShake(Die die)
{
	std::random_device rnd;
	if (rnd()%2 == 1)
	{
		return GoNorth(die);
	}
	else
	{
		return GoWest(die);
	}
}
int getPip(Die die, int x, int y)
{
	while (die.B_Two != x || die.A_One != y)
	{
		die = RandomShake(die);
	}
	return die.D_Four;
}
int main()
{
	int a, b, c, d, e, f;
	std::cin >> a >> b >> c >> d >> e >> f;

	Die die{ a,b,c,d,e,f };
	int in;
	std::cin >> in;
	while (in--)
	{
		int x, y;
		std::cin >> x >> y;
		std::cout << getPip(die, x, y) << std::endl;;
	}
	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int divby2(int i){
    int cnt = 0;
    while(i != 0){
        i /= 2;
        cnt++;
    }
    return cnt;
}
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());
    vector<vector<ll>> split(divby2(n) + 1);
    for(int i = 0; i < n; i++){
        split[divby2(i)].push_back(a[i]);
    }
    /*for(int i = 0; i < split.size(); i++){
        cout << "\n";
        for(int j = 0; j < split[i].size(); j++){
            cout<< split[i][j] << " ";
        }
    }*/
    ll total = 0;
    for(int i = 1; i < split.size(); i++){
        for(int j = 0; j < split[i].size(); j++){
            total += split[i - 1][j / 2];
        }
    }
    cout << total;
}

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

int main(void)
{
  char comma;
  int num;
  string blood;
  int groups[4] = { 0, 0, 0, 0, };
  while (true)
  {
    cin >> num >> comma >> blood;
    if (cin.eof() ) break;
    if (blood == "A")
    {
      ++groups[0];
    }
    else if (blood == "B")
    {
      ++groups[1];
    }
    else if (blood == "AB")
    {
      ++groups[2];
    }
    else
    {
      ++groups[3];
    }
  }
  for (int i = 0; i < 4; ++i)
  {
    cout << groups[i] << endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;
constexpr int  MAX_N = (1 << 17);

class BIT {
  public:
    ll bit[MAX_N + 1], n;
  
    BIT()
    {
        n = MAX_N + 1;
        for (int i = 0; i < n; i++) {
            bit[i] = 0;
        }
    }

    ll sum(int i, int P)
    {
        int s = 0;
        while (i > 0) {
            s = (s + bit[i]) % P;
            i -= i & -i;
        }
        return s;
    }
  
    void add(int i, int x, int P)
    {
        while (i <= n) {
            bit[i] = (bit[i] + x) % P;
            i += i & -i;
        }
    }
};

int main()
{
    int A, B, P;
    while (cin >> A >> B >> P, A > 0) {
        vector<string> str_num;
        for (int i = A; i <= B; i++) {
            str_num.emplace_back(to_string(i));
        }

        sort(str_num.begin(), str_num.end());                
        
        BIT b;
        ll res = 0;
        for (const auto& s : str_num) {
            int v = stoi(s) - A + 1;
            res = (res + b.sum(v, P) + 1) % P;
            b.add(v, b.sum(v, P) + 1, P);
        }
        cout << res << endl;
    }        
    return 0;
}

Measured memory_bytes: 9516
#include <iostream>

int main() {
  int num;
  std::cin >> num;

  int count = 0;
  for (int i = 1; i <= num; ++i) {
    if (i % 2 == 0) continue;
    int divisor_count = 0;
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0) ++divisor_count;
    }
    if (divisor_count == 8) ++count;
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256