akhauriyash/Code-Regression huggingface dataset:
import math

class doubling:
    def __init__(self, seni, max_jump, reward = None):
        self.depth = math.ceil(math.log2(max_jump))
        self.N = len(seni)
        self.jumps = [[0 for i in range(self.N)] for _ in range(self.depth+1)]
        self.jumps[0] = seni
        
        if reward:
            self.rewards = [[0 for i in range(self.N)] for _ in range(self.depth+1)]
            self.rewards[0] = reward
            
        for i in range(self.depth):
            for j in range(self.N):
                self.jumps[i+1][j] = self.jumps[i][self.jumps[i][j]]
                if reward:
                    self.rewards[i+1][j] = self.rewards[i][j] + self.rewards[i][self.jumps[i][j]]
    def calculation(self, now, move):
        count = move.bit_length()
        reward = 0
        for i in range(count):
            if move & 1<<i == 1<<i:
                if self.rewards:
                    reward += self.rewards[i][now]
                now = self.jumps[i][now]
        return now, reward
#%%

N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
#%%

answer = -int(1e+50)

if K < N:
    minimum = K
else:
    minimum = N

for i in range(N):
    now2, reward2 = i, 0
    for j in range(minimum):
        reward2 = reward2 + C[now2]
        now2 = P[now2]
        if reward2 > answer:
            answer = reward2

consume = K-N
if consume > 0:
    dbl = doubling(P, consume, C)
    for i in range(N):
        now1, reward1 = dbl.calculation(i, consume)
        for j in range(N):
            reward1 = reward1 + C[now1]
            now1 = P[now1]
            if reward1 > answer:
                answer = reward1
print(answer)

Measured memory_bytes: 77552
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <tuple>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(v) (v).begin(),(v).end()
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;



int main(){
    int n;
    cin>>n;
    set<ll> st;
    rep(i,0,n){
        ll a,b,c;
        cin>>a>>b>>c;
        st.insert(a*a*a+b*b*b+c*c*c);
    }
    cout<<n-st.size()<<endl;
    
    return 0;
}



Measured memory_bytes: 3124
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    n=int(input())
    graph=[[]for _ in range(n)]
    for _ in range(n-1):
        u,v,w=map(int,input().split())
        graph[u-1].append((v-1,w))
        graph[v-1].append((u-1,w))
    D=[-1]*n
    D[0]=0
    que=deque([0])
    while que:
        q=que.popleft()
        qw=D[q]
        for nn,w in graph[q]:
            if D[nn]==-1:
                D[nn]=qw+w
                que.append(nn)
    for d in D:
        if d%2==0:
            print(0)
        else:
            print(1)


if __name__=='__main__':
    main()

Measured memory_bytes: 43028
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int A[N], X[N][N], Y[N][N];//証言が"確実"か、"不確定"か。
	rp(i, 0, N){
		cin>>A[i];
		rp(j, 0, A[i]){ cin>>X[i][j]>>Y[i][j]; X[i][j]--; }
	}

	int ans = 0;
	rp(bits, 1, 1<<N){//bits: 仮定のbit列: 0|1=不確実|確実
		bool ok = true;//true|false=仮定に矛盾なし|あり
		for(int i=0; i<N && ok; ++i){
			int assume_i = (bits>>i)&1;//i番目の仮定: 0|1
			if(!assume_i) continue;//不確実: 確認のしようがない
			for(int j=0; j<A[i] && ok; ++j){//以降、i番目の証言は全て確実と仮定して処理
				int assume_x = (bits>>X[i][j])&1;//x番目の仮定: 0|1
				if(assume_x != Y[i][j]) ok = false;//x番目の仮定と証言が矛盾
			}
		}
		if(ok) ans = max(ans, (int)bitset<16>(bits).count());//矛盾なし: 仮定から最大数を得る
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	long long res = 0;
	for(auto i = 1; i <= n; ++ i){
		for(auto j = 1; j <= n; ++ j){
			for(auto k = 1; k <= n; ++ k){
				res += gcd(gcd(i, j), k);
			}
		}
	}
	cout << res;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3652
#include <stdio.h>
#include <limits.h>
int main(void)
{
	int i,n;
	scanf("%d", &n);
	int a[n];
	
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	
	int max = INT_MIN;
	int min = a[0];
	
	for(int i=1; i <n; i++){
		if(max < a[i]-min){
			max = a[i]-min;
		}
		
		if(min > a[i]){
			min = a[i];
		}
	}
	
	printf("%d\n", max);
	
	return 0;
}




Measured memory_bytes: 2616
s1 = " "+input()
s2 = " "+input()
from collections import defaultdict
dp = defaultdict(lambda: defaultdict(lambda: max(len(s1), len(s2))))
dp[0][0] = 0
for i in range(len(s1)-1):
    for j in range(len(s2)-1):
        if s1[i]!=s2[j+1]:
            dp[i][j+1]=min(dp[i][j+1], dp[i][j]+1)

        if s1[i+1]!=s2[j]:
            dp[i+1][j]=min(dp[i+1][j], dp[i][j]+1)

        if s1[i+1]!=s2[j+1]:
            dp[i+1][j+1]=min(dp[i][j]+1, dp[i+1][j]+1, dp[i][j+1]+1)
        else:
            dp[i+1][j+1]=min(dp[i][j], dp[i+1][j]+1, dp[i][j+1]+1)
print(dp[len(s1)-1][len(s2)-1])


Measured memory_bytes: 94264
function Main(input) {
  const array = input.trim().split('').map(s => parseInt(s))
  const N = array.length
  const X = 7

  for(var bit = 0; bit < (1 << N); ++bit) {
    var res = array[0]
    var str = `${array[0]}`
    for(var i = 1; i < N; ++i) {
      if(bit & (1 << i)) {
        res += array[i]
        str = `${str}+${array[i]}`
      } else {
        res -= array[i]
        str = `${str}-${array[i]}`
      }
    }

    if (res === X) {
      console.log(str+'=7')
      break
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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 FOR(i,s,n) for(int i = s;i < (int)n;++i)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;--i)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline void out(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
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;}
constexpr int INF = 1e18;
vector<string>s;
int N;
void dfs(int now,int num,string t){
	if(now == N){
		s.emplace_back(t);
		return;
	}
	REP(i,min(num+1,N)){
		dfs(now+1,num + (i == num),t + char('a'+i));
	}
}
signed main(){
	cin >> N;
	dfs(0,0,"");
	sort(ALL(s));
	for(auto e:s){
		out(e);
	}
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    // 処理
    // 出力
    cout << ((e - a > k) ? ":(" : "Yay!") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
struct Node {
    int index;
    Node *parent, *left, *right;
};
Node* NIL;
Node* getNil()
{
    Node* node = (Node*)malloc(sizeof(Node));
    node->index = -1;
    node->parent = node;
    node->left = node;
    node->right = node;
    return node;
}
Node* getNewNode()
{
    Node* node = (Node*)malloc(sizeof(Node));
    node->index = -1;
    node->parent = NIL;
    node->left = NIL;
    node->right = NIL;
    return node;
}
Node* insertNode(Node* rootNode, int index)
{
    Node* node = rootNode;
    Node* parentNode = NIL;
    Node* indexNode = getNewNode();
    indexNode->index = index;
    if (node->index == -1) {
	return indexNode;
    }
    while (node->index != -1) {
	parentNode = node;
	if (node->index > index) {
	    node->left->parent = node;
	    node = node->left;
	} else {
	    node->right->parent = node;
	    node = node->right;
	}
    }
    indexNode->parent = parentNode;
    if (parentNode->index > index) {
	parentNode->left = indexNode;
    } else {
	parentNode->right = indexNode;
    }
    return rootNode;
}
void printNodeIn(Node* node)
{
    if (node->index == -1) {
	return;
    }
    std::cout << " " << node->index;
    printNodeIn(node->left);
    printNodeIn(node->right);
}
void printNodePre(Node* node)
{
    if (node->index == -1) {
	return;
    }
    printNodePre(node->left);
    std::cout << " " << node->index;
    printNodePre(node->right);
}
int main()
{
    NIL = getNil();
    Node* node = NIL;
    int n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
	std::string command;
	std::cin >> command;
	if (command == "insert") {
	    int index;
	    std::cin >> index;
	    node = insertNode(node, index);
	} else if (command == "print") {
	    printNodePre(node);
	    std::cout << std::endl;
	    printNodeIn(node);
	    std::cout << std::endl;
	}
    }
}

Measured memory_bytes: 26584
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,N;
string S,T;
int Y,X;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N>>Y>>X>>S>>T;
	Y--,X--;
	
	int L=0,R=W-1,U=0,D=H-1;
	for(i=N-1;i>=0;i--) {
		if(T[i]=='U') D=min(D+1,H-1);
		if(T[i]=='D') U=max(U-1,0);
		if(T[i]=='L') R=min(R+1,W-1);
		if(T[i]=='R') L=max(L-1,0);
		if(S[i]=='U') U++;
		if(S[i]=='D') D--;
		if(S[i]=='L') L++;
		if(S[i]=='R') R--;
		if(R<L || D<U) return _P("NO\n");
	}
	
	if(X<L || X>R || Y<U || Y>D) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 920
import copy

class Solver:
    def __init__(self, _n, _k, _s):
        self.n = _n
        self.k = _k
        self.upper = copy.deepcopy(_s)
        self.lower = _s.lower()

        self.solve()
    
    def solve(self):
        ans = ""
        for i in range(self.n):
            if i == self.k - 1:
                ans = ans + self.lower[i]
            else:
                ans = ans + self.upper[i]
        
        print(ans)

def main():
    n, k = (int(i) for i in input().split())
    s=input()
    Solver(n, k, s)



if __name__ == "__main__":
    main()

Measured memory_bytes: 3436
import itertools
n, m, q = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(q)]
ans = 0
for A in itertools.combinations_with_replacement(range(m), n):
    tmp = 0
    for i in range(len(x)):
        a, b, c, d = x[i]
        if A[b-1] - A[a-1] == c:
            tmp += d
    ans = max(ans, tmp)
print(ans)

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

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

vector<bool> sieve(1000007,true);

void help(){
     sieve[0] = false;
     sieve[1] = false;

     for(int i=2;i*i<=1000000;++i){
        if(sieve[i]){
            for(int j=i*i;j<=1000000;j+=i)
                sieve[j] = false;

        }
     }


}

int main() {
   fastIO



   int a,b;
  cin>>a>>b;
   cout<<max({a+b,a-b,a*b});


   return 0 ;
      }


Measured memory_bytes: 384
function Main(input) {
    var maisu = 0;
    var input = input.split("\n");
    var one = input[0].split(" ");
    var N = parseInt(one[0]);
    var H = parseInt(one[1]);
    var W = parseInt(one[2]);
    for(i = 1; i <= N; i++){
        var hantei = input[i].split(" ");
        var A = parseInt(hantei[0]);
        if(H > A) continue;
        var B = parseInt(hantei[1]);
        if(W <= B) maisu++;
    }
	console.log(maisu);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main(){
   int n,m; cin>>n>>m;
   vector<P> p(m);
   rep(i,m) cin>>p[i].first>>p[i].second;
   rep(x,1000){
      int nx=x/10;
      vector<int> d(1,x%10);
      while(nx){
         d.push_back(nx%10);
         nx/=10;
      }
      reverse(d.begin(),d.end());
      if(d.size()!=n) continue;
      bool ok=true;
      rep(i,m){
         if(d[p[i].first-1]!=p[i].second) ok=false;   
      }
      if(ok){
         cout<<x<<endl;
         return 0;
      }
   }
   cout<<-1<<endl;
   return 0;
}

   


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int H,N,i,A;
	scanf("%d%d",&H,&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&A);
		H-=A;
	}
	if(H<=0) puts("Yes");
	else puts("No");
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    ll sum =0;
    for(int i=1;i<b-a;i++){
        sum+=i;
    }
    cout << sum-a << endl;
}


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

class State
{
public:
	double d;
	int p, n;

	State(int pp, double dd = 0.0, int nn = 0)
		:p(pp), d(dd), n(nn) {}

	bool operator < (const State& s) const
	{
		return this->d > s.d;
	}

};

int main()
{
	//freopen("1138.txt", "r", stdin);
	const double INF = 1000000000.0;

	int n, m, p, a, b;
	while (scanf("%d %d %d %d %d", &n, &m, &p, &a, &b) != EOF) {
		if (n == 0 && m == 0 && p == 0 && a == 0 && b == 0)
			break;
		--a;
		--b;

		vector<int> t(n);
		for (int i = 0; i < n; ++i)
			scanf("%d", &t[i]);

		vector<vector<int> > edge(m, vector<int>(m, -1));
		for (int i = 0; i < p; ++i) {
			int x, y, z;
			scanf("%d %d %d", &x, &y, &z);
			--x;
			--y;
			edge[x][y] = edge[y][x] = z;
		}

		double ans = INF;
		priority_queue<State> que;
		vector<vector<int> > visited(m, vector<int>(1 << (n+1), 0));
		vector<vector<double> > cost(m, vector<double>(1 << (n+1), INF));
		que.push(State(a));
		cost[0][0] = 0;

		while (!que.empty()) {
			State st = que.top();
			que.pop();

			if (st.p == b) {
				ans = st.d;
				break;
			}

			if (cost[st.p][st.n] < st.d || visited[st.p][st.n] || st.n == (1 << (n+1)))
				continue;

			visited[st.p][st.n] = 1;
			for (int i = 0; i < m; ++i) {
				if (edge[st.p][i] == -1)
					continue;

				for (int j = 1; j < n+1; ++j) {
					if (st.n & (1 << j))
						continue;
					double tmp = st.d + edge[st.p][i] / static_cast<double>(t[j-1]);
					if (cost[i][(1 << j) | st.n] > tmp) {
						cost[i][(1 << j) | st.n] = tmp;
						que.push(State(i, tmp, (1 << j) | st.n));
					}
				}

			}

		}

		if (ans == INF)
			printf("Impossible\n");
		else
			printf("%.3f\n", ans);

	}

	return 0;
}

Measured memory_bytes: 7644
#include <iostream>
#include <unordered_map>

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

	std::unordered_map<int, int> m;
	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;
		m[a] = -(m[a] - 1);
	}

	int ans = 0;
	for (auto&& e : m)
		if (e.second == 1)
			++ans;

	std::cout << ans << std::endl;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007
#define rev(v) reverse(v.begin(), v.end());

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int x; cin >> x;
    int h = (x/500)*1000;
    h += ((x-500*(x/500))/5)*5;
    cout << h << endl;
    return 0;
}

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

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

using namespace std;

int main() {
    string a;
    cin >> a;
    if (a[0] > '2') {
        cout << "TBD" << endl;
        return 0;
    }   
    else if (a[1] > '0') {
        cout << "TBD" << endl;
        return 0;
    }   
    else if (a[2] > '1') {
        cout << "TBD" << endl;
        return 0;
    }   
    else if (a[3] > '9') {
        cout << "TBD" << endl;
        return 0;
    }   
    else if (a[5] > '0') {
        cout << "TBD" << endl;
        return 0;
    }   
    else if (a[6] > '4') {
        cout << "TBD" << endl;
        return 0;
    }   
    else cout << "Heisei" << endl;
}


Measured memory_bytes: 256
#4方向走査
#下、右、上、左
dy=[1,0,-1,0]
dx=[0,1,0,-1]

H,W=map(int,input().split())

field=[]
for _ in range(H):
  field.append(list(input()))

is_success=True

for y in range(H):
  for x in range(W):
    if field[y][x]==".":
      continue
    
    for k in range(4):
      tmp_y=y+dy[k]
      tmp_x=x+dx[k]

      if tmp_y<0 or tmp_y>=H or tmp_x<0 or tmp_x>=W:
        continue
      if field[tmp_y][tmp_x]=="#":
        break
      if k==3:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())

ans_success = "Yay!"
ans_fail = ":("


def get_ans(a, b):
    if a == 8 and b == 8:
        return ans_success
    if a > 8 or b > 8:
        return ans_fail
    else:
        return ans_success


# 出力
print(get_ans(a, b))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b, c, x,count=0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (i * 500 + j * 100 + k * 50 == x) {
					count++;
				}
			}
		}
	}
	cout << count << endl;
	int y;
	cin >> y;
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [w, a, b] <- fmap read . words <$> getLine :: IO [Int]
    let p1 = b <= a + w
    let p2 = a <= b + w
    let c = abs $ b - (a + w)
    let d = abs $ (b + w) - a
    if and [p1, p2]
        then print 0
        else print $ min c d

Measured memory_bytes: 508
N = int(input())
grundy = 0
for i in range(N):
    a, k = map(int, input().split())
    while a % k:
        p, q = divmod(a, k)
        a -= (p + 1)*((p+q)//(p+1))
    grundy ^= a // k
print('Takahashi' if grundy else 'Aoki')

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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(int i=0;i<n;i++)
#define forS(i,start,n) for(int i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int gcd(int,int);
int main(){
    int n,m,cnt=0;
    string s;

    cin >> n;
    vi a(n);
    forN(i,n){
        cin >> a[i];
    }
    int p=0;
    forN(i,n){
        p=gcd(p,a[i]);
    }
    cout << p<<endl;
}
int gcd(int x, int y){
    int a=x,b=y;
    if(a==0||b==0) return max(a,b);
    if(a<b) swap(int,a,b);
    int tmp;
    while((tmp=a%b)!=0){
        a=b;b=tmp;
    }
    return b;
}

Measured memory_bytes: 3776
import java.util.Scanner;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		
		int b = a + a*a + a*a*a;
		
		System.out.println(b);
		
	}
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	double ans=.0,x;
	string s;
	for (int i = 0; i < n; ++i)
	{
		cin>>x>>s;
		if (s=="JPY")
		{
			ans+=x;
		}
		else
		{
			ans+=x*380000.0;
		}
	}
	printf("%.6f\n", ans);
	return 0;
}


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

int main() {
  string c;
  cin >> c;
  if (c == "a") {
    cout << "vowel";
  }
  else if (c == "i") {
    cout << "vowel";
  }
  else if (c == "u") {
    cout << "vowel";
  }
  else if (c == "e") {
    cout << "vowel";
  }
  else if (c == "o") {
    cout << "vowel";
  }
  else {
    cout << "consonant";
  }
}




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


def solve(S: str):
    s = int(S[:4] + S[5:7] + S[8:10])
    if s <= 20190430:
        ret = 'Heisei'
    else:
        ret = 'TBD'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main() {
    int n, k, s;
    cin >> n >> k >> s;
    vector<int> ans(n);
    rep(i,n){
        if (0 < k) {
            ans.at(i) = s;
            k--;
        }
        else {
            if (s == 1e9) ans.at(i) = s-1;
            else ans.at(i) = s + 1;
        }
    }
    
    rep(i,n) {
        cout << ans.at(i);
        if (i < n-1) cout << ' ';
    }
    cout << endl;
    return 0;
}

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


ll mod = 1e9 + 7;

struct ModComb {
    vector<long long> fact, rfact;
    long long max, mod;
    ModComb(long long ma = 1, long long mod=1e9+7) :fact(ma, 0), rfact(ma, 0), max(ma), mod(mod) {
        fact[0] = 1;
        for (long long i=1; i<max; ++i) {
            fact[i] = fact[i-1]*i;
            fact[i] %= mod;
        }
        rfact[max-1] = mod_inverse(fact[max-1], mod);
        for (long long i=max-2; i>=0; --i) {
            rfact[i] = rfact[i+1]*(i+1);
            rfact[i] %= mod;
        }
    }
    long long mod_pow(long long x, long long n, long long mod) {
        long long a = 1LL;
        while (n) {
            if (n%2) a = ((a%mod)*(x%mod))%mod;
            x = ((x%mod)*(x%mod))%mod;
            n /= 2LL;
        }
        return a;
    }

    // a / y -> a * y^(-1)
    // y^(m-2) = y^(-1) (mod m)
    long long mod_inverse(long long a, long long m) {
        return mod_pow(a, m-2, m);
    }

    // O(r)で求める方法
    long long calc(ll n, ll r, ll mod) {
        ll ret = 1, k = 0;
        for (ll a=r; a>=1; --a) {
            ll tmp = (n - k) * mod_inverse(a, mod) % mod;
            tmp %= mod;
            ret *= tmp;
            ret %= mod;
            k++;
        }
        return ret;
    }

    // 重複組合せ
    // nHr = n+r-1Cr
    // (n+r-1)まで初期化していないとエラー
    long long nHr(ll n, ll r, ll mod) {
        return (*this)(n+r-1, r);
    }

    long long operator()(long long n, long long r) {
        if (n < r) return 0;
        return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
    }
};


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

    ll ans = 0;
    ModComb mb(n+1, mod);
    for (int i=0; i<min(n, k+1); ++i) {
        ans += (mb(n, i) % mod) * (mb.nHr(n-i, i, mod) % mod) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1000000007;

void solve() {
  int N, K, S;
  cin >> N >> K >> S;
  int dummy = S == 1000000000 ? 1 : S + 1;
  for (int i = 0; i < N; i++) {
    if (i < K) {
      cout << S << ' ';
    } else {
      cout << dummy << ' ';
    }
  }
  cout << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1280
# coding: utf-8

s = input()
K = int(input())

n = len(s)

# sにでてくる英小文字1文字ごとをUTF-8コードのリストで管理する
pos = [[] for __ in range(256)]
for i in range(n):
    pos[ord(s[i])].append(i)

strset = set()
for c in range(ord('a'), ord('z')+1):
    for i in pos[c]:
        for j in range(K):
            strset.add(s[i:i+j+1])

    # 最初の1文字が最も若い英小文字で始まるすべての部分文字列がK以上なら、それより後ろになる文字列は調べなくて良い
    if len(strset) > K:
        break


strlist = list(strset)
strlist.sort()
print(strlist[K-1])


Measured memory_bytes: 3316
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc100/tasks/abc100_d
//ポイント：
//最終的な値がx>0ならできるだけxが大きくなるように集めた方がいい
//x<0ならできるだけ負の方向に大きくなるように集めた方がいい
//xだけでなくy,zも同様

//参考：https://babcs2035.hateblo.jp/entry/2018/06/17/124029

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
LL x[1000],y[1000],z[1000];
 
LL ans = 0;

void solve(){
	//bitの1ビット目が1ならxを負の方向に伸ばすと仮定
	//bitの2ビット目が1ならyを負の方向に伸ばすと仮定
	//bitの3ビット目が1ならzを負の方向に伸ばすと仮定
	for(int bit=0;bit<(1<<4);bit++){
		LL x_sign = (bit&1)?-1:1;
		LL y_sign = ((bit>>1)&1)?-1:1;
		LL z_sign = ((bit>>2)&1)?-1:1;

		//各ケーキごとにx+y+zを計算,priority_queueに入れて
		//x+y+zのでかいものからM個取り出す
		priority_queue<LL> pq;
		for(int i=0;i<N;i++){
			pq.push(x_sign*x[i] + y_sign*y[i] + z_sign*z[i]);
		}

		LL sum = 0;
		for(int i=0;i<M;i++){
			sum += pq.top();
			pq.pop();
		}
		ans = max(ans,sum);
	}
}
 
int main(){
    cin >> N >> M;
    for(int i=0;i<N;i++) cin >> x[i] >> y[i] >> z[i];
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    ll a,b;
    cin>>a>>b;
    ll ans=__gcd(a,b),cnt=a*b;
    cout<<cnt/ans<<nl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
A = [int(_) for _ in input().split()]

O, E = [], []

for i, a in enumerate(A):
    if a % 2 == 0:
        o, e = 2, 1
    else:
        o, e = 1, 2
        
    if i == 0:
        O.append(o)
        E.append(e)
    else:           
        numo, nume = 0, 0
        numo += O[-1] * o
        nume += E[-1] * e
        nume += E[-1] * o
        nume += O[-1] * e

        O.append(numo)
        E.append(nume)

print(E[-1])


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

int main() {
	int N; cin >> N;
	long Tnow=1, Anow=1, Trat, Arat, T, A;
	for(int i=0; i<N; ++i){
	    cin >> T >> A;
	    Trat=(Tnow+T-1)/T;
	    Arat=(Anow+A-1)/A;
	    Tnow=max(Trat, Arat)*T;
	    Anow=max(Trat, Arat)*A;
	}
	cout << Tnow+Anow << endl;
	return 0;
}


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

using pii = pair<int, int>;

int main() {
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<pii> sec(q);
  for (auto&& e : sec) {
    int l, r;
    cin >> l >> r;
    e.first = l;
    e.second = r;
  }

  vector<int> acCount(n + 1);
  char prev = 'X';
  for (int i = 0; i < n; ++i) {
    acCount[i + 1] = acCount[i];
    if (prev == 'A' && s[i] == 'C') {
      acCount[i + 1] += 1;
    }
    prev = s[i];
  }

  for (const auto& e : sec) {
    cout << acCount[e.second] - acCount[e.first] << endl;
  }
}


Measured memory_bytes: 2176
#pragma GCC optimize(1)
#include<bits/stdc++.h>
using namespace std;
const int maxn=4;
char x[maxn];int n;
int main(){
	for(register int i=1;i<=1000000000;i++);
	scanf("%s",x);
	n=strlen(x);
	if(n==2) printf("%s\n",x);
	else{
		putchar(x[2]);putchar(x[1]);putchar(x[0]);putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string S;int r,N,i;
int main(){
    cin>>S;
    r=S.size();
    N=r;
    for(i=1;i<N;++i)if(S[i-1]==S[i])--r,i+=2;
    cout<<r<<endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = nm[0];
        int M = nm[1];

        var surveyList =
            Enumerable.Range(0, N)
            .Select(n => Console.ReadLine().Split(' ').Select(s => int.Parse(s)))
            .Select(arr => new { favoriteFoods = arr.Skip(1).ToArray() })
            .ToArray();

        var allFood = surveyList.SelectMany(s => s.favoriteFoods).Distinct();

        Console.WriteLine(allFood.Count(f => surveyList.All(s => s.favoriteFoods.Contains(f))));
        
    }
    
}

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

#define int long long
#define mod 1000000007

using namespace std;

int a[100010];

int32_t main()
{
    int n,k;
    cin >> n >> k;

    memset(a,0,100010*sizeof(a[0]));

    for(int i=1;i<=n;i++)
        a[i%k]++;

    int ans = a[0]*a[0]*a[0];

    if(k%2 == 0)
        ans += a[k/2]*a[k/2]*a[k/2];

    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextInt()
    val y = sc.nextInt()
    println(gcd(x, y))
}

fun gcd(x: Int, y: Int): Int {
    val a: Int
    val b: Int
    if (x < y) {
        a = y
        b = x
    } else {
        a = x
        b = y
    }
    if (a % b == 0) {
        return b
    } else {
        return gcd(b, a % b)
    }
}


Measured memory_bytes: 25636
#include<iostream>

using namespace std;

int main(){
	int h1, h2, k1, k2, a,b , c, d;
	cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
	int h, k;
	h = h1*a + h2*b + (h1/10)*c +(h2/20)*d;
	k = k1*a + k2*b + (k1/10)*c +(k2/20)*d;
	if(h > k){
		cout << "hiroshi" << endl;
	}
	else if(h == k){
		cout << "even" << endl;
	}
	else{
		cout << "kenjiro" << endl;
	}

	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var array1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var array2 = Console.ReadLine().Split().Select(int.Parse).ToArray();

            if (array1[0] != array2[0] && array2[1] ==1)
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine("0");
            }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    if(n%2==0){
        if(n/2 >= k) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else{
        if(n/2+1 >= k) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#n=int(input())
n,m,x=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

price_list=[]
cl=[]
al=[]
for i in range(n):
    l=list(map(int,input().split()))
    cl.append(l[0])
    al.append(l[1:])


for i in range(2**n):
    b=bin(i)
    price=0
    score=[0 for k in range(m)]
    #print(b)
    # それぞれの組み合わせ
    for j in range(n):
        if ((i >> j) & 1):#二進数iの下から数えてj桁目が1か否か
            a=al[j]
            for k in range(m):
                score[k]=score[k]+a[k]
            price+=cl[j]
    # if x<
    if min(score)>=x:
        price_list.append(price)

if len(price_list)==0:
    print('-1')
else:
    print(min(price_list))


Measured memory_bytes: 9208
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

int val[4000];
vector <int> tree[4000];

int rec(int p, int hei) {
  if (val[p] != -1) return val[p];

  int ret = 0;
  vector <int> list;
  for (int i = 0; i < tree[p].size(); i++) {
    list.push_back(rec(tree[p][i], hei+1));
  }

  sort(list.begin(), list.end());
  for (int i = 0; i < list.size()/2+1; i++) {
    ret += list[i];
  }
  
  return val[p] = ret;
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string str;
    cin >> str;

    vector <int> temp;
    for (int j = 0; j < 4000; j++) {
      tree[j] = temp;
    }

    memset(val, -1, sizeof(val)); // 入ってないところは-1
    stack <int> st;
    int cnt = 0;
    int p = 0;
    st.push(cnt);
    while(!st.empty()) {
      p++;
      if (str[p] == '[') {
	cnt++;
	st.push(cnt);
      }else if (str[p] == ']') {
	int topv = st.top(); st.pop();
	if (!st.empty()) {
	  tree[st.top()].push_back(topv);
	}
      }else {
	int v = 0;
	for (; p < str.size(); p++) {
	  if (str[p] == ']') {
	    p--;
	    break;
	  }
	  v = v*10+str[p]-'0';
	}
	val[cnt] = v/2+1;
      }
    }

    cout << rec(0, 0) << endl;    
    
  }
}

Measured memory_bytes: 1492
S = input()
ans = 0
count = 0
ACGT = ['A', 'C', 'G', 'T']
for i in range(len(S)):
    for j in range(i, len(S)):
        if all(ACGT.count(c) == 1 for c in S[i : j+1]):
            ans = max(ans, j-i+1)
print(ans)

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

class C
{
	class Blue
	{
		public int[] p;
		public bool u;
	}

	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var n = int.Parse(Console.ReadLine());
		var rs = new int[n].Select(_ => read()).OrderBy(p => p[0]).ToArray();
		var bs = new int[n].Select(_ => new Blue { p = read() }).OrderBy(_ => _.p[1]).ToArray();

		var map = new int[n].Select(_ => bs.Take(0).ToList()).ToArray();
		for (int i = 0; i < n; i++)
		{
			var p = rs[i];
			for (int j = 0; j < n; j++)
			{
				var q = bs[j].p;
				if (p[0] < q[0] && p[1] < q[1]) map[i].Add(bs[j]);
			}
		}

		var c = 0;
		for (int i = n - 1; i >= 0; i--)
		{
			var b = map[i].FirstOrDefault(_ => !_.u);
			if (b != null)
			{
				c++;
				b.u = true;
			}
		}
		Console.WriteLine(c);
	}
}


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

int gcd(int x, int y){
    int r;
    if(x<y)swap(x,y);
    
    while(y > 0){
        r = x%y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    
    return 0;
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using plglg = pair<ll, ll>;
using tlglglg = tuple<ll, ll, ll>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    ll a, b, c, d; cin >> a >> b >> c >> d;
    // ll x = max(abs(a), abs(b));
    // ll y = max(abs(c), abs(d));
    ll ans = max(a*c, max(b*d, max(b*c, a*d)));
    print(ans);

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n,m,k;
  cin>>n>>m>>k;
  vector<vector<ll>> a(n+1,vector<ll>(m+1,0));
  vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(m+1,vector<ll>(4,0)));
  forn(i,0,k){
    ll ri,ci,vi;
    cin>>ri>>ci>>vi;
    a[ri][ci] = vi;
  }
  forn(i,1,n+1){
    forn(j,1,m+1){
      forn(k,0,4){
        ll query1 = 0, query2 = 0;
        if(k!=0)
          query1 = dp[i][j-1][k-1] + a[i][j];
        if(k!=0)
          query2 = dp[i-1][j][3] + a[i][j];
        dp[i][j][k] = max( { dp[i][j-1][k] , dp[i-1][j][3] , query2 , query1 } );
      }
    }
  }
  cout<<dp[n][m][3]<<endl;
  return 0;
}


Measured memory_bytes: 707096
using System;
using System.Collections.Generic;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var count = 0;
            for (var i = 0; i < n; ++i)
            {
                var m = int.Parse(Console.ReadLine());
                if (m != 2 && m % 2 == 0) continue;
                bool isPrime = true;
                for (var k = 3; k * k <= m; k += 2)
                {
                    if (m % k == 0)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if(isPrime) count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 15892
def main():
    S = input()
    d = {}
    for i in range(4):
        if S[i] not in d.keys():
            d[S[i]] = 1
        else:
            d[S[i]] += 1
    if len(d.keys()) == 2 and list(d.values())[0] == 2 and list(d.values())[1] == 2:
        print('Yes')
    else:
        print('No')


main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  char b;
  cin >> b;
  if(b == 'A') cout << 'T' << endl;
  if(b == 'T') cout << 'A' << endl;
  if(b == 'C') cout << 'G' << endl;
  if(b == 'G') cout << 'C' << endl;
  return 0;
}

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

//定数πの定義
#define PI 3.14159265359

int main(void)
{
	//dist_a、dist_b、dist_cは各辺の長さ
	double dist_a, dist_b, dist_c;
	//angle_cは角Cの角度(度)、rad_cは角Cの角度(ラジアン)
	double angle_c, rad_c;
	//areaは面積を、circuitは周の長さを、heightは三角形の高さを格納
	double area, circuit, height;

	//辺a、辺b、角Cを入力
	scanf("%lf %lf %lf", &dist_a, &dist_b, &angle_c);
	//角Cの値をラジアンに変換
	rad_c = PI * angle_c / 180;

	//面積を求め、結果を出力
	area = dist_a * dist_b * sin(rad_c) / 2;
	printf("%lf\n", area);

	//余弦定理を利用し辺cの長さを求め、周の長さを出力する
	dist_c = sqrt(pow(dist_a, 2.0) + pow(dist_b, 2.0) - (2 * dist_a * dist_b) * cos(rad_c));
	circuit = dist_a + dist_b + dist_c;
	printf("%lf\n", circuit);

	/*
	底辺をdist_a、高さをheight、面積をareaとすると
	dist_a * height / 2 = area
	height = 2 * area / dist_a
	*/
	height = 2 * area / dist_a;
	printf("%lf\n", height);

	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <array>

using namespace std;

static void printArray(int A[], int N) {
  for (int i = 0; i < N; i++) {
    std::cout << (i != 0 ? " " : "") << A[i];
  }
  std::cout << std::endl; 
}

static void inputArray(int A[], int num) {
  for (int i = 0; i < num; i++) {
    scanf("%d", &A[i]);
  }
}

static int selectionSort(int A[], int N) {
  int minj, count = 0;
  for (int i = 0; i < N; i++) {
    minj = i;
    for (int j = i; j < N; j++) {
      if (A[j] < A[minj]) {
    	minj = j;
      }
    }
    if (A[i] != A[minj]) {
        swap(A[i], A[minj]);
        count++;
    }
  }
  return count;
}

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

  array<int, 100> A;
  inputArray(A.data(), N);

  int count = selectionSort(A.data(), N);

  printArray(A.data(), N);
  cout << count << endl;
  
  return 0;
}



Measured memory_bytes: 3260
Class Main
    Public Shared Sub Main()
        Dim N As Integer = Console.ReadLine()
        Dim i As Integer
        Dim sum As Long = 0
        For i = 1 To N
    If fix(i / 3) * 3 <> i Then
      If fix(i / 5) * 5 <> i Then
                    sum += i
                End If
            End If
        Next
        Console.WriteLine(sum)
    End Sub
End Class


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

int main() {
  int p=0;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='p')p++;
  }
  cout<<(s.size()/2)-p<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  string s;
  cin >> s;
  int ans = 700;
  rep (i, 3) {
    if (s[i] == 'o') ans += 100;
  }
  P(ans);


  return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int[] x = new int[n];

		for ( int i=0; i<n; i++ ) {
			x[i] = sc.nextInt();
		}
		Arrays.sort(x);

		int[] p = new int[100];
		for ( int i= 0; i<100; i++ ) {
			p[i] = i*i;
		}

		int pmin = 100000000;
		for ( int m=x[0]; m<=x[n-1]; m++ ) {
			int pm = 0;
			for ( int i=0; i<n; i++ ) {
				int d = Math.abs(x[i]-m);
				pm = pm + p[d];
			}
			pmin = Math.min(pmin, pm);
		}
		System.out.println(pmin);
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,m,x,y,c;
    cin >> A >> B >> m;
    int a[A],b[B];
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    int ans = 1e9;
    rep(i,m){
        cin >> x >> y >> c;
        chmin(ans,a[x-1]+b[y-1]-c);
    }
    sort(a,a+A);
    sort(b,b+B);
    chmin(ans,a[0]+b[0]);
    PRINT(ans);
}


Measured memory_bytes: 1024