akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N+1),B(N);
	rep(i, N+1) cin >> A[i];
	rep(i, N)cin >> B[i];

	ll ans = 0;
	for (ll i = 0; i < N + 1;++i) {
		if (i == 0) {
			ll tmp = B[i] - A[i];
			if (0<=tmp) {
				ans += A[i];
				B[i] = tmp;
			}
			else {
				ans += B[i];
				B[i] = 0;
			}
		}
		else if (i==N) {
			ll tmp = B[i - 1] - A[i];
			if (0 <= tmp) {
				ans += A[i];
				B[i - 1] = tmp;
			}
			else {
				ans += B[i - 1];
				B[i - 1] = 0;
			}
		}
		else {
			ll tmp = B[i - 1] - A[i];
			if (0 <= tmp) {
				ans += A[i];
				B[i - 1] = tmp;
			}
			else {
				ans += B[i - 1];
				B[i - 1] = 0;
				ll tmp2 = B[i] - abs(tmp);
				if (0 <= tmp2) {
					ans += abs(tmp);
					B[i] = tmp2;
				}
				else {
					ans += B[i];
					B[i] = 0;
				}

			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n, l; cin >> n >> l;
  string s[n];
  for(int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s+n);
  for(int i = 0; i < n; i++)
    cout << s[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
char s[100005];
int main(){
	for(int i = scanf("%s", s+1); s[i+1]; i ++) if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]) return printf("%d %d\n", i, s[i+2]?i+2:i+1), 0;	
	return printf("%d %d\n", -1, -1), 0;
}

Measured memory_bytes: 256
import math
x, y = map(int, input().split())
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def lcm(x,y):
    return (x * y)//gcd(x, y)

def thingo(x,y):
    if (x == 0 and y == 0):
        return -1
    if (x != 0 and y == 0):
        return x
    test = lcm(x,y)
    if (test-x >= x):
        return test-x
    else:
        return -1
print(thingo(x,y))


Measured memory_bytes: 3060
use proconio::*;

const MOD: u64 = 1_000_000_007;

fn mod_pow(r: u64, mut n: u64) -> u64 {
    let mut t = 1;
    let mut s = r;
    while n > 0 {
        if n & 1 == 1 {
            t = t * s % MOD;
        }
        s = s * s % MOD;
        n >>= 1;
    }
    t
}

fn run() {
    input! {
        n: u64,
    }
    let ans = (mod_pow(10, n) - 2 * mod_pow(9, n) + mod_pow(8, n) + 2 * MOD) % MOD;
    println!("{}", ans);
}

fn main() {
    run();
}


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

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int n, a, b;
    cin >> n >> a >> b;
    
    int maxx = min(a, b);
    int minn = max(0, a + b - n);
    
    cout << maxx << " " << minn << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
const int N=510;
void out() { puts("-1"); exit(0);}

int n,s[N],t[N],c[N][N],R[N][2],C[N][2];
ull u[N],v[N],ans[N][N];

void solve() {
	for(int k=0;k<64;k++) {
		memset(c,-1,sizeof c);
		memset(R,0,sizeof R);
		memset(C,0,sizeof C);
		for(int i=1;i<=n;i++) {
			int x=u[i]&1;
			if(s[i]^x) for(int j=1;j<=n;j++) c[i][j]=x;
		}
		for(int i=1;i<=n;i++) {
			int x=v[i]&1;
			if(t[i]^x) {
				for(int j=1;j<=n;j++) {
					if(~c[j][i]&&c[j][i]!=x) out();
					c[j][i]=x;
				}
			}
		}
		for(int i=1;i<=n;i++) 
			for(int j=1;j<=n;j++) {
				if((u[i]&1)==(v[j]&1)) c[i][j]=u[i]&1;
				if(c[i][j]==-1) c[i][j]=0;//不确定的先设为0. 
				R[i][c[i][j]]++;
				C[j][c[i][j]]++;
			}
		//由于0的个数饱和所以只用把部分0改成1即可. (针对| 1)
		for(int i=1;i<=n;i++)
			if(s[i]==1&&(u[i]&1)==1&&!R[i][1]) 
				for(int j=1;j<=n;j++)
					if(t[j]==0&&(v[j]&1)==0&&C[j][0]>1) {
						R[i][0]--; C[j][0]--;
						R[i][1]++; C[j][1]++;
						c[i][j]=1;
						break;
					}
		for(int i=1;i<=n;i++)
			if(t[i]==1&&(v[i]&1)==1&&!C[i][1])
				for(int j=1;j<=n;j++)
					if(s[j]==0&&(u[j]&1)==0&&R[j][0]>1) {
						C[i][0]--; R[j][0]--;
						C[i][1]++; R[j][1]++;
						c[j][i]=1;
						break;
					}
		for(int i=1,x;i<=n;i++) {
			if(s[i]&1) {
				if((u[i]&1)&&!R[i][1]) out();
				if(!(u[i]&1)&&R[i][1]) out();
			}
			else {
				if((u[i]&1)&&R[i][0]) out();
				if(!(u[i]&1)&&!R[i][0]) out();
			}
			if(t[i]&1) {
				if((v[i]&1)&&!C[i][1]) out();
				if(!(v[i]&1)&&C[i][1]) out();
			}
			else {
				if((v[i]&1)&&C[i][0]) out();
				if(!(v[i]&1)&&!C[i][0]) out();
			}
			u[i] >>= 1;
			v[i] >>= 1;
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				ans[i][j]|=(ull)c[i][j]<<k;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			printf("%llu%c",ans[i][j]," \n"[j==n]);
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
	for(int i=1;i<=n;i++) scanf("%d",&t[i]);
	for(int i=1;i<=n;i++) scanf("%llu",&u[i]);
	for(int i=1;i<=n;i++) scanf("%llu",&v[i]);
	solve(); return 0;
}


Measured memory_bytes: 8452
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int H, W;
short dp[102][102][102][102];
short row[101][101], col[101][101];
int EY = -1, EX = -1;
string A[101];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> H >> W;
    rep(y, H) {
        cin >> A[y];
        rep(x, W) {
            if(A[y][x] == 'E') {
                EY = y;
                EX = x;
            } else if(A[y][x] == 'o') {
                row[y][x + 1] = 1;
                col[x][y + 1] = 1;
            }
        }
    }
    rep(y, H)rep(x, W) {
        row[y][x + 1] += row[y][x];
        col[x][y + 1] += col[x][y];
    }

    int up, le, bo, ri;
    short val, ans = 0;
    rep(u, H + 1)if(EY-u>=0)rep(l, W + 1)if(EX-l>=0)rep(d, H + 1)if(EY+d<H)rep(r, W + 1)if(EX+r<W) {
        up = max(EY - u, d);
        le = max(EX - l, r);
        bo = min(EY + d, H - 1 - u);
        ri = min(EX + r, W - 1 - l);
        val = dp[u][l][d][r];
        smax(ans, val);

        smax(dp[u + 1][l][d][r], val);
        if(up - 1 >= 0 && EY - u > d&&le <= ri) {
            smax(dp[u + 1][l][d][r], (short)(val + row[up - 1][ri + 1] - row[up - 1][le]));
        }
        smax(dp[u][l + 1][d][r], val);
        if(le - 1 >= 0 && EX - l > r&&up <= bo) {
            smax(dp[u][l + 1][d][r], (short)(val + col[le - 1][bo + 1] - col[le - 1][up]));
        }
        smax(dp[u][l][d + 1][r], val);
        if(bo + 1 < H&&H - 1 - u > EY + d&&le <= ri) {
            smax(dp[u][l][d + 1][r], (short)(val + row[bo + 1][ri + 1] - row[bo + 1][le]));
        }
        smax(dp[u][l][d][r + 1], val);
        if(ri + 1 < W && W - 1 - l > EX + r&&up <= bo) {
            smax(dp[u][l][d][r + 1], (short)(val + col[ri + 1][bo + 1] - col[ri + 1][up]));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 51200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll h[n];for(ll i=0;i<n;i++)cin>>h[i];
  ll ans=0;
  for(ll i=100;i>0;i--){
    ll s=0;
    for(ll j=0;j<n;j++){
      if(h[j]>=i)s=1;
      else{
        if(s==1)ans++;
        s=0;
      }
    }
    if(s==1)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

setrecursionlimit(1000000)
N,M = list(map(int,input().split()))

edges = [[] for _ in range(N)]

for i in range(M):
    L,R,D = list(map(int,input().split()))
    edges[L - 1].append((R -1,D))
    edges[R - 1].append((L-1, -D))


visited = [None] * N
place = [0] * N
inf = 10 ** 10


def walk(i):
    if visited[i]:
        return (place[i], place[i])
    visited[i] = True
    (n,m) = (inf, - inf)
    for j,d in edges[i]:
        #print(j,d)
        if visited[j] and place[j] != place[i] + d:
            print("No")
            exit()
        place[j] = place[i] + d
        (x,y) = walk(j)
        (n,m) = (min(n,x),max(m,y))
    return (n,m)


for i in range(N):
    if not visited[i]:
        place[i] = 0
    # 連結成分のminとmax
        (n,m) = walk(i)
        if m - n > 10 ** 9:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 134604
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Long> list = new ArrayList<>();
    //final List<Long> list2 = new ArrayList<>();

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

    long max = list.get(0);
    long sum = 0;

    for(int i = 1; i < n ; i++){
        if(max > list.get(i)){
            sum += max - list.get(i);
        }else{
            max = list.get(i);
        }

        //System.out.println(sum + " " + max);
    }
    System.out.println(sum);

    

    





}
}

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

int main(){
  long long n; cin >> n;
  vector<long long> a(5);
  for(int i=0; i<a.size(); ++i) cin >> a[i];

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

  long long ans = (n + (a[0] - 1)) / a[0] + 4;

  cout << ans << endl;
}


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

int main() {
  int A, B;
  char op;
  int ans = 0;
  cin >> A >> op >> B;
  if (op == '+'){
      ans = A + B;
  }
  else if (op == '-'){
      ans = A - B;
  }
  cout << ans << endl;
    
}

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

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

Measured memory_bytes: 256
N=int(input())
m=0
maxa=-1
L=list(map(int,input().split()))
for i in range(N-1):
  if L[i]>=L[i+1]:
    m+=1
  else:
    maxa=max(maxa,m)
    m=0
maxa=max(maxa,m)
print(maxa)

Measured memory_bytes: 20468
#include<iostream>

using namespace std;

int main(){
 int a, b, c, t;
 cin >> a >> b >> c;
 
  if( a > b ) t=a, a=b, b=t;
  if( b > c ) t=b, b=c, c=t;
  if( a > b ) t=b, b=a, a=t;
  cout << a << " " << b << " " << c << endl;

 
  return 0;
}


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

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

        if(a.equals("H") ^ b.equals("H")){
            System.out.println("D");
        }else{
            System.out.println("H");
        }   
    }
}



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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

num a, b;

int main() {
	cin >> a >> b;
	cout << (a - 1) / b + 1 << ln;
}

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

using namespace std;

void solve(int X){
    for(int i=0;i<=X;i++){
        if(int(1.08*i) == X){
            cout << i << endl;
            return;
        }
    }
    cout << ":(" << endl;
}

int main(){
    int N;
    while(cin >> N){
        solve(N);
    }
}

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

int main() {

    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    if(K <= A){
        ans = K;
    }
    else if(K <= A + B){
        ans = A;
    }
    else{
        ans = A - (K-A-B);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int i, x, n, p[105], j;
    scanf("%d %d", &x, &n);
    if(n==0)
    {
        printf("%d", x);
        return 0;
    }
    for(i=0; i<n; i++)
    {
        scanf("%d", &p[i]);
    }
    for(i=0; i<n+1; i++)
    {
        int a=0, b=0;
        for(j=0; j<n; j++)
        {
            if(x-i==p[j])
            {
                a++;
            }
            if(x+i==p[j])
            {
                b++;
            }
        }
        if(a<1)
        {
            printf("%d", x-i);
            return 0;
        }
        if(b<1)
        {
            printf("%d", x+i);
            return 0;
        }
    }
}


Measured memory_bytes: 1692
#include<bits/stdc++.h>
using namespace std;
#define big long long
int main()
{
	//#ifndef ONLINE_JUDGE
		//freopen("take.in","r",stdin);
		//freopen("give.out","w",stdout);
	//#endif

	big a,b;
	cin>>a>>b;

	bool on=1;
	big i=1;

	for(i=1;i<=1e4;i++)
	{
		big a2=(i*8)/100;
		big b2=(i*10)/100;
		if(a2==a and b2==b)
		{
			on=0;
			break;
		}
	}

	if(on) cout<<-1<<endl;
	else cout<<i<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <math.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return (a.first*a.first + a.second*a.second) > (b.first*b.first + b.second*b.second);
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

ll dp[51][2501];

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, A;
    cin >> N >> A;
    REP(i, N) {
        int x;
        cin >> x;
        
        for(int j = i+1; j >= 2; j--) {
            REP(k, 2502-x) {
                dp[j][k+x] += dp[j-1][k];
            }
        }
        dp[1][x] += 1;
    }
    ll sum = 0;
    REP(i, N) {
        REP(j, 2502) {
            if ((i+1)*A == j) {
                sum += dp[i+1][j];
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


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

  if(s=="RRR"){
    cout<<3<<endl;
    return 0;
  }

   if(s=="RRS"){
    cout<<2<<endl;
    return 0;
  }

   if(s=="SRR"){
    cout<<2<<endl;
    return 0;
  }

ll y=0;
  for(int i=0;i<3;i++){

if(s[i]=='R')y++;
  
  
  
}

if(y==0){
  cout<<0<<endl;
return 0;
}

cout<<1<<endl;







}


Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    vector<pll> rec(N);
    rep(i, N){
        rec[i].first = A[i];
        rec[i].second = B[i];
    }
    sort(rec.begin(), rec.end());
    ll ans = 0;
    rep(i, N){
        if(M > rec[i].second){
            M -= rec[i].second;
            ans += rec[i].second * rec[i].first;
        }
        else{
            ans += M * rec[i].first;
            break;
        }
    }
    cout << ans << endl;
    return;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


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

inline vector<pair<int,int>> num(vector<int> vec){
    vector<pair<int, int>> ans;
    vec.push_back(0);
    int n=0;
    for(int i=0; i<vec.size()-1; i++){
        n++;
        if(vec.at(i)!=vec.at(i+1)){
            ans.push_back(make_pair(n,vec.at(i)));
            n=0;
        }
    }
    return ans;
}

int main(){
    int n,k; cin>>n>>k;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    vector<pair<int,int>> A=num(a);
    sort(A.begin(),A.end());
    
    if(A.size()<=k){cout<<0<<endl; return 0;}
    int sum=0,i=0,m=(int) A.size();
    while(m>k){
        sum+=A.at(i).first;
        m--;
        i++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 4848
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=input()
    T=["AKIHABARA","KIHABARA","AKIHBARA","AKIHABRA","AKIHABAR","KIHBARA","KIHABRA","KIHABAR","AKIHBRA","AKIHABR","AKIHABAR","AKIHBR","KIHABR","KIHBAR","KIHBRA","KIHBR"]
    
    flag=0
    for i in range(len(T)):
        if S==T[i]:
            flag=1
        

    
    
    if flag==0:
        print("NO")
    else:
        print("YES")

main()


Measured memory_bytes: 61816
using System;
using System.IO;
using System.Linq;

class Program{
    static void Main(string[] args){
        var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var K = arr[0];
        var N = arr[1];
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
        var longest = 0;
        for (int i = 0; i < N - 1; i++){
            if (longest >= A[i + 1] - A[i]) continue;
            longest = A[i + 1] - A[i];}
        if (A[0] + K - A[^1] > longest) longest = A[0] + K - A[^1];
        var answer = K - longest;
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 44496
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<climits>
#include<cmath>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

typedef unsigned int uint;
typedef long long ll;

using namespace std;

int main(){
  vector<int> v[31];
  int a,b;
  int m = 0;
  while(scanf("%d,%d",&a,&b),a+b){
    v[b].push_back(a);
    m = max(m, a);
  }
  vector<int> ans(m+1);
  int tmp = 1;
  for(int i=30; i>=0; i--){
    REP(j,v[i].size()){
      ans[v[i][j]] = tmp;
    }
    if(v[i].size() != 0) tmp++;
  }
  while(~scanf("%d",&a))
    printf("%d\n",ans[a]);
  return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < n-2; i++) {
        if(s.substr(i, 3) == "ABC"){
            cnt++;
        }
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

    VL x(n), y(n);
    REP(i,n) cin >> x[i] >> y[i];

    ll ans = 4e18 + 2;
    REP(left,n) REP(right,n) REP(bottom,n) REP(top,n){
        if (x[left] > x[right]) continue;
        if (y[bottom] > y[top]) continue;
        int p = 0;
        REP(i,n){
            if (x[i] >= x[left] && x[i] <= x[right] && y[i] >= y[bottom] && y[i] <= y[top]) p++;
        }
        if (p >= k) ans = min(ans, (x[right] - x[left]) * (y[top] - y[bottom]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

if H < W:
    H, W = W, H

S = H * W
for i in range(1, H):
    A = i * W
    BH1 = ((H-i)//2) * W
    BH2 = ((H-i)//2+(H-i)%2) * W
    BW1 = (W//2) * (H-i)
    BW2 = (W//2+W%2) * (H-i)
    SH = max(A,BH1,BH2) - min(A,BH1,BH2)
    SW = max(A,BW1,BW2) - min(A,BW1,BW2)
    S = min(S, SH, SW)

for i in range(1, W):
    A = i * H
    BH1 = ((W-i)//2) * H
    BH2 = ((W-i)//2+(W-i)%2) * H
    BW1 = (H//2) * (W-i)
    BW2 = (H//2+H%2) * (W-i)
    SH = max(A,BH1,BH2) - min(A,BH1,BH2)
    SW = max(A,BW1,BW2) - min(A,BW1,BW2)
    S = min(S, SH, SW)

print(S)


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

#define def 0
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return max(l, r); };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2); 
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
int N, H[200010], A[200010];
SegTree<ll, 1 << 18> dp;

int main(){
    cin >> N;
    rep(i, 0, N) cin >> H[i];
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, N) {
        ll opt = dp.get(0, H[i]) + A[i];
        dp.update(H[i], max(dp[H[i]], opt));
    }

    cout << dp.get(0, 1<<18) << endl;
}

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

int main() {
  int N, K, X, ans;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> X; 
    ans += min(X, K-X);
  }
  cout << 2 * ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n, k, c = map(int,input().split())
    s = input()
    schedule = [w == "o" for w in s]
    left = []
    l_day = 0
    right = []
    r_day = n - 1
    while len(left) < k:
        if schedule[l_day]:
            left.append(l_day)
            l_day += c
        l_day += 1

    while len(right) < k:
        if schedule[r_day]:
            right.append(r_day)
            r_day -= c
        r_day -= 1

    right.reverse()


    for i in range(k):
        if left[i] == right[i]:
            print(left[i] + 1)



if __name__ == "__main__":
    main()


Measured memory_bytes: 22268
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

Q = int(input())

MAX = 10 ** 5 + 2

is_prime = [True] * MAX

is_prime[0] = False
is_prime[1] = False
i = 2
while i ** 2 <= MAX:
    if is_prime[i]:
        for j in range(i * 2, MAX, i):
            is_prime[j] = False
    i += 1

count = [0] * MAX
for i in range(2, MAX):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        count[i] = 1
ans = [0] * MAX
for i in range(1, MAX):
    ans[i] = ans[i - 1] + count[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r + 1] - ans[l])


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

int x, a, b, temp;

void solve() {
    cin >> x >> a >> b;
    x -= a;
    temp = x / b;
    x -= b * temp;
    cout << x << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3632
h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
q=int(input())
lr=[list(map(int,input().split())) for _ in range(q)]
dmap={}
for hi in range(h):
  for wi in range(w):
    dmap[a[hi][wi]-1]=(hi+1,wi+1)
dans={}
for di in range(d):
  s=di
  x,y=dmap[di]
  tmp=0
  while s<h*w:
    nx,ny=dmap[s]
    tmp+=abs(x-nx)+abs(y-ny)
    dans[(di,s)]=tmp
    x,y=nx,ny
    s+=d
for l,r in lr:
  l-=1;r-=1
  s=l%d
  print(dans[(s,r)]-dans[(s,l)])
#print(dans)

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

void solve()
{
    int d, t, s;
    cin >> d >> t >> s;
    cout << (s * t >= d ? "Yes" : "No") << '\n';
}

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

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    if(A>=B){
        cout<<1<<endl;
    }
    else if(B%A){
        cout<<B/A+1<<endl;
    }
    else{
        cout<<B/A<<endl;
    }
}



Measured memory_bytes: 3104
S = input()

c1 = 0
cur = 0
for s in S:
  if cur != int(s):
    c1 += 1
  cur = (cur + 1) % 2

c2 = 0
cur = 1
for s in S:
  if cur != int(s):
    c2 += 1
  cur = (cur + 1) % 2
print(min(c1, c2))


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

int main() {
  int N;
  string S;

  cin >> N;
  
  int Np = 0, Nw = 0, Ng = 0, Ny = 0;
  int Nt;
//cout << Np << Nw << Ng << Ny << endl;
  
  for(int i = 0;i < N; i++) {
    
    cin >> S;
//  cout << S << endl;
   
    if(S == "P" && Np == 0) {
      Np++;
//    cout << Np << endl;
    }

    if(S == "W" && Nw == 0) {
      Nw++;
//    cout << Nw << endl;
    }
    
    if(S == "G" && Ng == 0) {
      Ng++;
//    cout << Ng << endl;
    }
    
    if(S == "Y" && Ny == 0) {
      Ny++;
//    cout << Ny << endl;
    }
    
  Nt = Np + Nw + Ng + Ny;
//cout << Nt << endl;
    
  if(Nt == 4) {
    cout << "Four" << endl;
    break;
  }
    
  }

  if(Nt == 3) {
    cout << "Three" << endl;
  }
  
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for(int i=0; i<n; i++){
        int d = (int)pow(2,9);
        for(int j=0; j<10; j++){
            int x;
            cin >> x;
            v.at(i) += x*d;
            d /= 2;
        }
    }
    int p[n][11];
    for(int i=0; i<n; i++){
        for(int j=0; j<=10; j++){
            cin >> p[i][j];
        }
    }

    int bit = 0b0000000001;
    int max = -1e9;
    while(bit <= 0b1111111111){
        int profit = 0;
        for(int i=0; i<n; i++){
            profit += p[i][__builtin_popcount(bit & v.at(i))];
        }
        if(profit > max){
            max = profit;
        }
        bit++;
    }

    cout << max << endl;

    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        // ABC155C - Poll

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String[] s = new String[n];
        int max = 1;
        HashMap<String, Integer> map = new HashMap();
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
            if (map.containsKey(s[i])) {
                int v = map.get(s[i]) + 1;
                map.put(s[i], v);
                if (v > max) max = v;
            } else {
                map.put(s[i], 1);
            }
        }

        Arrays.sort(s);

        for (int i = 0; i < n; i++) {
            int v = map.get(s[i]);
            if (v == max) {
                System.out.println(s[i]);
            }
            i += (v - 1);
        }

    }
}

Measured memory_bytes: 93400
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#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;
 
    ll x = n%10;
 
    if(x == 3) {
        out("bon");
    }
    else if(x == 0 || x == 1 || x == 6 || x == 8) {
        out("pon");
    }
    else {
        out("hon");
    }
 
    re0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
using namespace std;
int fac[2005]={0};
int mod=1e9+7;
int mm[2005]={0};

int solve(int x,int y)
{
    int ans=1;
    ans=(ans*fac[x])%mod;
    ans=(ans*mm[x-y])%mod;
    ans=(ans*(mm[y]))%mod;
    return ans;
}

int modInverse(int a, int m)
{
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        // q is quotient
        int q = a / m;
        int t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
        x += m0;

    return x;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    fac[0]=1;
    for(int i=1;i<=2004;i++)
    {
        fac[i]=(fac[i-1]*i)%mod;
    }

    mm[0]=1;
    for (int i = 1; i <=2004 ; ++i) {
        mm[i]=(mm[i-1]*modInverse(i,mod))%mod;
    }

    int n,k;
    cin>>n>>k;
    int a=k,b=n-k;

    for (int i = 1; i <=a ; ++i) {
        int res=1;
        if(b>=i-1)
        {
            res=(res*(solve(b+1,b-i+1)))%mod;
            res=(res*solve(a-1,a-i))%mod;
            cout<<res<<"\n";
        }
        else
            cout<<0<<"\n";
    }

}

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

int main(void) 
{
	int m, n;
	int i, j;
	char character;
	char *src, *dst;

	while (scanf("%d", &n), n) {
		src = (char *) malloc(sizeof(char) * n);
		dst = (char *) malloc(sizeof(char) * n);

		for (i = 0; i < n; i++) 
			scanf("\n%c %c", &src[i], &dst[i]);

		scanf("\n%d", &m);

		for (i = 0; i < m; i++) {
			scanf("\n%c", &character);
			
			for (j = 0; j < n; j++) {
				if (character == src[j]) {
					character = dst[j];
					printf("%c", character);
					break;
				} else if (j == n - 1)
					printf("%c", character);
			}
		}
		
		printf("\n");

		free(src);
		free(dst);
	}
	return 0;
}

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

int main() {
  int n, a[200];

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

  int cnt, ans = pow(10, 9);
  for (int i = 0; i < n; i++) {
    cnt = 0;
    while (true) {
      if (a[i] % 2 != 0 || a[i] == 0) break;
      a[i] /= 2;
      cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    f_inf = float("inf")
    b = [f_inf] + LI() + [f_inf]

    a = [0 for _ in range(n)]
    for i in range(n):
        a[i] = min(b[i],b[i+1])
    ans = sum(a)
    print(ans)

main()

Measured memory_bytes: 74620
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll sum_xor(ll x){
    // for n, n ^ n+1 = 1
    if(x < 0) return 0;
    ll y = (x / 2) % 2;
    return (x % 2 == 0) ? x ^ y : 1 ^ y;
}

int main(){
    ll A, B; cin >> A >> B;
    cout << (sum_xor(A-1) ^ sum_xor(B)) << endstr;
    return 0;
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


auto solve() {
    int N;
    cin >> N;
    vi A(N);
    REP(i, N) {
        cin >> A[i];
    }

    vi cpy(N);
    copy(all(A), begin(cpy));
    sort(all(cpy));
    map<int,int> comp;
    REP(i, N) {
        comp[cpy[i]] = i;
    }

    // compress
    int diff = 0;
    REP(i, N) {
        A[i] = comp[A[i]];
        if(abs(A[i] - i) % 2 == 1 )
            diff++;
    }

    if(diff % 2 == 1)
        return -1;

    return diff / 2;
}

int main() {
    cout << solve() << endl;
    return 0;
}


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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  
  if((r*100 + g*10 + b) % 4 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}

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

signed main(){
  ll n;cin>>n;
  vector<ll> v(n),u(n);

  rep(i,n){
    cin>>v[i];
  }
  u=v;
  sort(all(u),greater<ll>());

  rep(i,n) cout<<u.at(u[0]==v[i])<<endl;
  
}


Measured memory_bytes: 4736
N = int(input())
Height = list(map(int, input().split()))
judge = 'Yes'

for i in range(N-1,0,-1):
    
    if (Height[i] >= Height[i-1]):
        continue
    
    elif (Height[i] == Height[i-1]-1):
        Height[i-1] -= 1
    
    else:
        judge = 'No'
        break

print(judge)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, t;
    cin >> n >> x >> t;
    int cnt = 1;
    while (1) {
        if (n <= x) {
            cout << cnt * t << '\n';
            return 0;
        }
        ++cnt;
        n -= x;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int k;
    cin>>k>>s;
    if (s.size()>k)
    {
        for (int i=0;i<k;i++)cout<<s[i];
        cout<<"...";
    }
    else
        cout<<s;
    return 0;
}


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

int main() {
  long double l,ans;
  cin>>l;
  ans=pow(l/3,3);  

  cout<<fixed<<setprecision(12)<<ans<<endl;

}

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

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b)

#define lint long long
#define pb push_back
#define F first 
#define S second 
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef vector < int > vi ;
typedef pair < int, int > pii ;

// template <typename T>
inline int modpow(lint base, int exp, int modulo) {
  base %= modulo;
  lint result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo;
    exp >>= 1;
  }
  return result;
}

const int N = 3e3 + 2 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;

lint dp[N][N][4] ;
int val[N][N] ;
// int idx[N][N] ;
int n, m, k ;

lint solve(int i, int j, int curRow) {
	if(i >= n) return 0;
	if(j >= m) return 0;
	if(dp[i][j][curRow] != -1) return dp[i][j][curRow] ; 
	lint ans = 0 ;
	
	// dont pick
	reMax(ans, max(solve(i, j+1, curRow), solve(i+1, j, 0)));

	// pick
	if(curRow < 3) {
		reMax(ans, solve(i, j+1, curRow + 1) + val[i][j]);
		reMax(ans, solve(i+1, j, 0) + val[i][j]); 
	}
	return dp[i][j][curRow] = ans ; 
}

int main()
{
    fastio; cin >> n >> m >> k ; int r, c, v ;
    // SET(index, -1);
    SET(val, 0);
    for(int i = 0; i < k; i++) {
    	cin >> r >> c >> v ;
    	r-- ; c-- ; 
    	// idx[r][c] = i ; 
    	val[r][c] = v ; 
    }
    SET(dp, -1); cout << solve(0, 0, 0); 
}


Measured memory_bytes: 321016
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	void kaijou_set(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	int X,Y;
	cin>>X>>Y;
	
	int ans = 0;
	combi C;
	C.kaijou_set(1100000);
	for(int i=0;i<=X;i++){
		int cnt1 = i;
		if((X-i)%2!=0)continue;
		int cnt2 = (X-i)/2;
		if(cnt1*2+cnt2!=Y)continue;
		ans += C.combination(cnt1+cnt2,cnt2);
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 9216
import sys

[
    print('o' if 'ooo' in b else ('x' if 'xxx' in b else 'd'))
    for b in [
        [
            "".join([l[i] for i in t])
            for t in [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)]
        ]
        for l in (
            list(s.strip())
            for s in sys.stdin
        )
    ]
]

Measured memory_bytes: 7356
# include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a,b,c;
    if(n%10==7||n/100==7||(n-(n/100*100))/10==7)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(){
    int W,H,x,y,r;

    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

    if (x>=r && x+r<=W && y>=r && y+r<=H){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    
    return 0;
}



Measured memory_bytes: 2104
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,x,t = readInts()
import math

need = n//x + (1 if (n - x*(n//x)) else 0)
#print(need)
print(need * t)


Measured memory_bytes: 10480
#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 N;
ll A,B,S[101010];
ll TA[101010],TB[101010];
ll mo=1000000007;

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	V add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	V set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};

BIT<ll,20> BTA,BTB;
vector<int> VA,VB;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B;
	S[0]=-1LL<<60;
	S[N+1]=1LL<<61;
	for(i=1;i<=N;i++) cin>>S[i];
	
	int LA=0,LB=0;
	
	TA[0]=TB[0]=1;
	BTA.add(0,1);
	BTB.add(0,1);
	VA.push_back(0);
	VB.push_back(0);
	for(i=2;i<=N;i++) {
		
		/*
		for(j=0;j<i-1 && S[i]-S[j]>=A;j++) (TB[i-1]+=TA[j])%=mo;
		for(j=0;j<i-1 && S[i]-S[j]>=B;j++) (TA[i-1]+=TB[j])%=mo;
		*/
		while(LA<i-2&&S[i]-S[LA+1]>=A) LA++;
		while(LB<i-2&&S[i]-S[LB+1]>=B) LB++;
		
		
		TB[i-1]=BTA.total(LA)%mo;
		TA[i-1]=BTB.total(LB)%mo;
		
		if(S[i]<S[i-1]+A) {
			FORR(r,VB) {
				BTB.add(r,-TB[r]);
				TB[r]=0;
			}
			VB.clear();
		}
		if(S[i]<S[i-1]+B) {
			FORR(r,VA) {
				BTA.add(r,-TA[r]);
				TA[r]=0;
			}
			VA.clear();
		}
		BTA.add(i-1,TA[i-1]);
		BTB.add(i-1,TB[i-1]);
		VA.push_back(i-1);
		VB.push_back(i-1);
	}
	
	ll ret=0;
	FOR(i,N+1) ret+=TA[i]+TB[i];
	cout<<ret%mo<<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);
	solve(); return 0;
}


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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 20000005;
bool isPrime[MAXN];
vector<int> pr;
vector<pair<int,int>> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {
            if(!pr.empty())
            {
                if(i-pr.back()==2)
                {
                    ans.push_back({pr.back(),i});
                }
            }
            pr.push_back(i);

        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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

    return 0;
}


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

int main(){
	int A, B;
	cin >> A >> B;
	if(A >= 13){
		cout << B << endl;
		return 0;
	} else 
		if(A <= 5){

			cout << 0 << endl;
			return 0;
		} else {
				cout << B/2 << endl;
				return 0;
			}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll d;

int main(void){
	scanf("%d%lld",&n,&d);
	d=d*d;
	int ans=0;
	for(int i=0;i<n;i++){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x=x*x;
		y=y*y;
		if(d>=x+y){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3820