akhauriyash/Code-Regression huggingface dataset:
while 1:
    wid,ver = input().split()
    wid = int(wid)
    ver = int(ver)
    if wid==0 or ver == 0:
        break 
    n=int(input())
    dis = [[0 for i in range(ver)] for j in range(wid)]
    for i in range(n):
        w,v = input().split()
        w = int(w)
        v = int(v)
        dis[w-1][v-1]=1

    coo = [[0 for i in range(ver)] for j in range(wid)]
    for i in range(wid):
        for j in range(ver):
            if i==0 or j==0:
                coo[0][0]=1
                if i>0:
                    coo[i][0]=coo[i-1][0]
                if j>0:
                    coo[0][j]=coo[0][j-1]
                if dis[i][0]==1:
                    coo[i][0] = 0
                if dis[0][j]==1:
                    coo[0][j] = 0
            else:
                if dis[i][j] == 1:
                    coo[i][j] = 0
                else:
                    coo[i][j] = coo[i-1][j] + coo[i][j-1]
    print(int(coo[wid-1][ver-1]))


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

int main() {
	int N, ans = 1000000000;
	cin >> N;
	vector<int> W(N);
	for (int i = 0; i < N; i++) {
		cin >> W.at(i);
	}

	for (int i = 0; i < N; i++) {
		int s1 = 0;
		int s2 = 0;
		for (int a = 0; a < i; a++) {
			s1 += W.at(a);
		}
		for (int b = i; b < N; b++) {
			s2 += W.at(b);
		}
		ans = min(ans, abs(s2 - s1));
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>

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

typedef long long ll;

using namespace std;

int main() {
    
    int a,b,k;
    
    cin >> a >> b >> k;
    
    if((b-a+1)/2 >= k){
        FOR(i, 0, k){
            cout << a+i <<endl;
        }
        for(int i=k;i>0;i--){
            cout << b-i+1 << endl;
        }
    }else{
        FOR(i, 0, b-a+1){
            cout << a+i << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 40010
#define mo 998244353
using namespace std;
ll jie[N+10],nj[N+10],m,n,dp[210][8010],ans,A[N],B[N],w[N],p,lo;
ll po(ll x,ll y){ll z=1;while (y){if (y%2)z=x*z%mo;x=x*x%mo;y/=2;}return z;}
ll c(ll x,ll y){return (jie[x]*nj[y]%mo)*nj[x-y]%mo;}
void fft(ll *a,int fh){
	for (int i=0;i<p;i++)if (w[i]>i) swap(a[i],a[w[i]]);
	for (int i=1;i<p;i*=2){
		for (int j=0;j<p;j+=i*2){
			ll w=1,W=(po(3,(mo-1)/(i*2))+mo)%mo;
			for (int k=0;k<i;k++,w=w*W%mo){
				ll x=a[j+k],y=a[i+j+k]*w%mo;
				a[j+k]=(x+y)%mo;a[j+k+i]=(x-y+mo)%mo;
			}
		}
	}
	if (fh==-1){reverse(a+1,a+p);ll x=po(p,mo-2);for (int i=0;i<p;i++)a[i]=a[i]*x%mo;}
}
int main(){
	cin>>n>>m;
	for (p=1,lo=0;p<=n*2;p*=2,lo++);
	for (int i=0;i<p;i++)w[i]=w[i/2]/2+(i&1)*(1<<(lo-1));
	jie[0]=1;for (int i=1;i<=N;i++)jie[i]=jie[i-1]*i%mo;
	nj[N]=po(jie[N],mo-2);for (int i=N-1;i>=0;i--) nj[i]=nj[i+1]*(i+1)%mo;
	dp[0][0]=1;
	for (int i=0;i<m;i++){
		memset(A,0,sizeof(A));memset(B,0,sizeof(B));
		for (int j=0;j<=n;j++){
			A[j]=dp[i][j]*nj[j]%mo;
			dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(1+c(j+1,2)))%mo;
			if (j)B[j]=nj[j+2];
		}
		fft(A,1);fft(B,1);
		for (int j=0;j<p;j++)A[j]=A[j]*B[j]%mo;
		fft(A,-1);
		for (int j=1;j<=n;j++)dp[i+1][j]=(dp[i+1][j]+A[j]*jie[j+2])%mo;
	}
	for (int i=0;i<=n;i++)ans=(ans+dp[m][i]*c(n,i))%mo;
	cout<<ans<<endl;
	return 0;
}
/*	for (int k=1;k+j<=n;k++){
		dp[i+1][j+k]=(dp[i+1][j+k]+dp[i][j]*c(j+k+2,k+2))%mo;
	}
*/

Measured memory_bytes: 14720
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a,b,t1;
	int c[20];
	int s=1;
	cin>>a>>b;
   if(a<=0&&b>=0)
   	 cout<<"Zero"<<endl;
   if(a>0&&b>0)
     cout<<"Positive"<<endl;
   if(a<0&&b<0)
   {
   
     t1=0;
    for(int i=a;i<=b;i++)
      t1++;
    if(t1%2==0)
    	cout<<"Positive"<<endl;
    else
        cout<<"Negative"<<endl;
   }
  return 0;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int lenght(char* str){
  int i=0;
 while(str[i]){
     i++;
 }
 return i;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
  int count = 1, ans = 0, len = 0, byten = 1 ;
  char S[200000] ;
  cin >> S ;
  len = lenght(S) ;
  int Num[len], mod[len] ;
  for(int i=0;i<len;i++){
    Num[i] = ctoi(S[i]) ;
  }
  mod[len-1] = Num[len-1] ;
  for(int i=len-2;i>=0;i--){
    byten = (byten * 10) % 2019 ;
    mod[i] = (mod[i+1] + Num[i] * byten) % 2019 ;
    if(mod[i] == 0) ans++ ;
  }
  sort(mod,mod+len) ;
  for(int i=1;i<len;i++){
    if(mod[i-1] == mod[i]){
      count++ ;
    }
    else{
      ans += (count * (count-1)) / 2 ;
      count = 1 ;
    }
  }
  ans += (count * (count-1)) / 2 ;
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 5304
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  long long n, k;
  cin >> n >> k;
  long long kk;
  kk = k;
  long long nn = 1000000000000000000;
  if(n % k == 0)
    {
      cout << 0 << endl;
      return (0);
    }
  n = n % k;
  while(1)
  {
    n = labs(n - k);
    if(n > nn)
      break;
    nn = n;
  }
  
  cout << min(kk, nn) << endl;
}

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

int main() {
  int W, H;
  string s;
  cin >> H >> W;
  for(int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  for(int i = 0; i < H; i++) {
    cin >> s;
    cout << '#' << s << '#' << endl;
  }
  for(int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;

}

Measured memory_bytes: 256
#include <iostream>
int main(){
	int x[101]={0},i,j;
	while(std::cin>>i>>j){
		x[1]++;
		x[2]++;
		while(i!=0&&j!=0){
			x[i]^=1;
			x[j]^=1;
			std::cin>>i>>j;
		}
		for(i=0;i<101;i++)if(x[i])break;
		std::cout<<(i==101?"OK\n":"NG\n");
		for(i=0;i<101;i++)x[i]=0;
	}
}

Measured memory_bytes: 1120
use std::cmp::max;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input! {
        n: usize, w: usize,
        items: [(i64, i64); n]
    }

    let mut dp_table = vec![0; w + 1];
    // dp_table[i] => 重さiを超えない中での最大値
    for i in 0..w + 1 {
        for &(value, weight) in &items {
            if weight <= i as i64 {
                dp_table[i] = max(dp_table[i], dp_table[i - (weight as usize)] + value);
            }
        }
    }

    println!("{}", dp_table[w]);
}


Measured memory_bytes: 5036
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;
stack<int> sta;

int main()
{
  int w;
  int wei[10]={512,256,128,64,32,16,8,4,2,1};
  int i,j;

  while(scanf("%d",&w)!=EOF){

    rep(i,10){
      if(wei[i]<=w){
	sta.push(wei[i]);
	w-=wei[i];
      }
    }

    while(1){
      cout<<sta.top();
      sta.pop();
      if(sta.size()==0)break;
      cout<<" ";
    }//while1
    cout<<endl;

  }
}

Measured memory_bytes: 1216
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

int n;
long long int ans;

int main(){
    cin >> n;
    cout << (ll)(n-1)*n/2 << endl;


return 0;
}

Measured memory_bytes: 3632
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()

class UnionFind:
    def __init__(self, n):
        self.parents = [-1] * (n + 1)

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.parents[self.find(x)]

def main():
    N, M, K = map(int, input().split())

    friends = defaultdict(lambda : 1)
    friendsGroup = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        friendsGroup.union(a, b)
        friends[a] += 1
        friends[b] += 1

    blocks = defaultdict(int)
    for _ in range(K):
        c, d = map(int, input().split())
        if friendsGroup.same(c, d):
            blocks[c] += 1
            blocks[d] += 1

    ans = [friendsGroup.size(i) - friends[i] - blocks[i] for i in range(1, N+1)]
    print(*ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 32372
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
#include<math.h>
#include<map>

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

using namespace std;

int main() {
	int k;
	int t;

	cin >> k >> t;
	vector<int>a(t);
	rep(i, 0, t)cin >> a[i];

	sort(a.begin(), a.end(), greater<int>());

	int tmp;
	tmp = a[0];

	rep(i, 1, a.size())tmp -= a[i];

	if (tmp <= 0)cout << "0" << endl;
	else cout << tmp - 1 << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
min = arr.sum
i = 0
while i < n
  if (arr[0..i].sum - arr[(i+1)..(n-1)].sum).abs < min
    min = (arr[0..i].sum - arr[(i+1)..(n-1)].sum).abs
  end
  i += 1
end
puts min

Measured memory_bytes: 14312
#include <iostream>
#include <string.h>
#include<algorithm>
using namespace std;

int main()
{
	int N,band = 0;
	string S;
	cin >> N >> S;
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == S[i + 1])band++;
	}
	cout << N - band << endl;
	return 0;
}


Measured memory_bytes: 512
#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>;
const int MAX = 100;
const int INF = 1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L

int d[MAX][MAX];

void bfs(vector<string> s, int h, int w, int x, int y) {
	queue<pair<int, int>> q;
	q.push(make_pair(x, y));
	rep(i,MAX) {
		rep(j,MAX) {
			d[i][j] = INF;
		}
	}
	d[y][x] = 0;
	pair<int, int> u;
	while ( !q.empty() ) {
		u = q.front(); q.pop();
		rep(v,4) {
			int nx = u.first+dj[v]; int ny = u.second+di[v];
			if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if (s[ny][nx] == '#') continue;
			if (d[ny][nx] != INF) continue;
			q.push(make_pair(nx,ny));
			d[ny][nx] = d[u.second][u.first] + 1;
		}
	}
}

int main() {
	int h, w; cin >> h >> w;
//	int si, sj; cin >> sx >> sy;
//	int ti, tj; cin >> gx >> gy;
//	si--; sj--; ti--; tj--;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	bfs(s, h, w, 0, 0);
	if (d[h - 1][w - 1] == INF) {
		cout << -1 << endl;
		return 0;
	}
	int cnt = 0;
	rep(i, h) {
		rep(j, w) {
			if (d[i][j] != INF && d[i][j] != 0) {
				cnt++;
			}
			if (d[i][j] == INF && s[i][j] == '.') {
				cnt++;
			}
		}
	}
	cnt = cnt - d[h - 1][w - 1];
	cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  int n,a,b;string s;
  cin >> n >> a >> b >> s;
  int now = a + b, cnt = 0;
  for(int i = 0; i < n; i++){
    if(now == 0) cout << "No" << endl;
    else if(s[i] == 'c') cout << "No" << endl;
    else if(s[i] == 'a'){
      cout << "Yes" << endl;
      now--;
    }else{
      if(cnt >= b) cout << "No" << endl;
      else{
        cout << "Yes" << endl;
        now--;
        cnt++;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 896
r,c,k = list(map(int, input().split()))
import copy
dp=[[[0]*4 for _ in range(c)] for _ in range(2)]


F = [[0]*c for _ in range(r)]

for _ in range(k):
  x,y,v = list(map(int, input().split()))
  x-=1
  y-=1
  F[x][y] = v
  
for nn in range(r):
  for j in range(c):
    i = 1
    val = F[nn][j]
  
      
    mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3])

    dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
    dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
    dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
    dp[i][j][0] = mxv

  dp[0] = dp[1] 
  dp[1] = [[0]*4 for _ in range(c)]

best = 0


for k in range(4):
  best = max(best, dp[0][c-1][k])
    
print(best)


Measured memory_bytes: 208088
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define pb push_back
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};


//BIT [1,n]
const int MAX_N = 202020;
int bit[MAX_N + 1], n = 202020;

int sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x) {
  while (i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}


int N, M;
vector<P> arr[101010];

signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> N >> M;
  REP(i,N) {
    int l, r;
    cin >> l >> r;
    arr[r-l].pb({l, r});
  }

  int exclude = 0;
  for (int d=1; d<=M; d++) {
    if (d == 1) {
      cout << N << endl;
    } else {
      for (auto p : arr[d-2]) {
        add(p.first, 1);
        add(p.second + 1, -1);
      }
      exclude += arr[d-2].size();
      int ans = N - exclude;
      for (int x=0; x<=M; x+=d) {
        ans += sum(x);
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 11264
#include <stdio.h>
#include <vector>
#include <array>
#include <unordered_map>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>


using std::string;
using std::vector;


int32_t gcd(int32_t m, int32_t n){
    if (m < n) std::swap<int32_t>(m, n);
    if(n == 0) return m;
    int32_t r = m % n;
    return gcd(n, r);
}

int main() {
    int32_t m, n;
    scanf("%d %d", &m, &n);
    const auto result = gcd(m, n);
    printf("%d\n", result);
    return 0;
}


Measured memory_bytes: 3208
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

N, H, W = map(int, input().split())
ans = 0

for x in range(0, N):
	A, B = map(int, input().split())
	
	if (H <= A and W <= B):
		ans += 1

print("{}".format(ans))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vvl dp(101,vl(100010,INF));
int main(){
    ll n,w;cin >> n >>w;
    vpl it(n);rep(i,n)cin >> it[i].fi >> it[i].se;
    dp[0][0]=0;
    rep(i,n){
        rep(j,100005){
            if(j+it[i].se<=100001)chmin(dp[i+1][j+it[i].se],dp[i][j]+it[i].fi);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    per(i,100005)if(dp[n][i]<=w)cout << i <<endl,exit(0);
}

Measured memory_bytes: 83044
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8, i8, i8, i8[:,:]), cache=True)
def solve(R,C,K,item):
  dp = np.zeros((C+1,5), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i-1][j-1])
  ans = dp[-1].max()
  return ans

R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v
print(solve(R,C,K,item))

Measured memory_bytes: 176892
// AtCoder Regular Contest 062
// C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int ll;


int N;
ll A, B;

int main() {

  ll a, b, p;

  scanf("%d", &N);
  A = B = 1;
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", &a, &b);
    p = max((A + a - 1) / a, (B + b - 1) / b);
    A = a * p;
    B = b * p;
  }

  printf("%lld\n", A + B);

  return 0;

}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	int A = 0, B = 0, C = 0;
	for(int i = 0; i < n; i++) {
		A += (a[i] == 1);
		B += (a[i] == 2);
		C += (a[i] == 3);
	}
	
	using ld = long double;
	
	ld N = n;
	auto dp = make_v<ld>(n + 1, n + 1, n + 1);
	auto used = make_v<bool>(n + 1, n + 1, n + 1);
	std::function<ld (int, int, int)> solve = [&](int x, int y, int z) {
		if(x < 0 or y < 0 or z < 0) return (ld)0;
		if(!x and !y and !z) return (ld)0;
		if(used[x][y][z]) return dp[x][y][z];
		
		ld ret = 0.;
		ret += solve(x - 1, y, z) * x;
		ret += solve(x + 1, y - 1, z) * y;
		ret += solve(x, y + 1, z - 1) * z;
		ret += N;
		ret /= x + y + z;
		
		used[x][y][z] = true;
		return dp[x][y][z] = ret;
	};
	
	printf("%.12lf\n", (double)solve(A, B, C));
	return 0;
}


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

int main() {
    int D;
    cin >> D;
    int d[26];
    vector<int> last(26, 1);

    rep(i, 26) {
        cin >> d[i];
    }

    vector<vector<int>> s(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> ans(D);

    ll level = 0;

    //現時点での価値を高める
    rep(i, D - 1) {
        ll maxnow = -INF;
        ll now = 0;
        vector<int> prelast = last;

        rep(j, 26) {
            rep(k, 26) {
                last = prelast;
                now = 0;
                //とりあえずの得点計算
                int t1 = j;
                int t2 = k;

                now += s[i][t1];
                last[t1] = 0;
                rep(j, 26) {
                    now -= d[j] * last[j];
                    last[j]++;
                }

                now += s[i + 1][t2];
                last[t2] = 0;
                rep(j, 26) {
                    now -= d[j] * last[j];
                    last[j]++;
                }

                if (maxnow < now) {
                    ans[i] = j;
                    ans[i + 1] = k;
                    maxnow = now;
                }
            }
        }

        last = prelast;

        //本当の得点計算
        level += s[i][ans[i]];
        last[ans[i]] = 0;
        rep(j, 26) {
            level -= d[j] * last[j];
            last[j]++;
        }

        if (i == D - 2) {
            level += s[i + 1][ans[i + 1]];
            last[ans[i + 1]] = 0;
            rep(j, 26) {
                level -= d[j] * last[j];
                last[j]++;
            }
        }
    }

    vector<int> koho = ans;

    rep(i, D) {
        cout << ans[i] + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;



int main() {
	int N, K;
	long long maxSumV = -9223372036854775807;
	cin >> N >> K;
	vector<long long> V(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}

	for (int i = 0; i <= min(N, K); ++i) {
		for (int j = 0; j <= min(N, K) - i; ++j) {
			//method of get jewelry
			vector<long long> listV;
			for (int k = 0; k < i; ++k) {
				listV.push_back(V[k]);
			}
			for (int k = 0; k < j; ++k) {
				listV.push_back(V[V.size() - k - 1]);
			}

			//method of throw away
			sort(listV.rbegin(), listV.rend());
			int throwCount = K - i - j;
			for (int k = 0; k < throwCount; ++k) {
				if (0 < listV.size() && listV[listV.size() - 1] < 0) {
					listV.pop_back();
				}
				else {
					break;
				}
			}

			long long sumV = 0;
			for (int k = 0; k < listV.size(); ++k) {
				sumV += listV[k];
			}
			maxSumV = max(sumV, maxSumV);
		}
	}

	cout << maxSumV << endl;

	return 0;
}

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



int main() {
    int N; cin >> N;
    vector<long long> V(N); // A_iにはやばい数も入りうる
    for(int i=0;i<N;i++){
        cin >> V.at(i);
    }
    sort(V.begin(),V.end()); //小さい順に

    long long x;
    x=V.at(0);
    int ans=0;
    int count=0;
    for(int i;i<N;i++){
        if(x==V.at(i)){
            count++;
        } // 前と同じならカウンターだけ大きくして終わり。

        if(x!=V.at(i) && count%2==1){
            ans++;
        } //そうでないとき、カウンターが奇数なら答えに1足す。

        if(x!=V.at(i)){
            count=1;
            x=V.at(i);
        } //前と違うときは、カウンターが偶数でも奇数でもリセット。
    }

    if(count%2==1){
        ans++;
    }//最後のｘのために。
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); 
  int n; 
  cin >> n;
  map<ll, ll> val;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    val[x]++;
  }
  ll area = 0;
  vector<ll> cand;
  for (auto y: val) {
    if (y.second >= 4)
      area = max(area, y.first*y.first);
    if (y.second >= 2)
      cand.push_back(y.first);
  }
  int m = cand.size();
  if (m >= 2)
    area = max(area, cand[m-1]*cand[m-2]);
  cout << area << endl;
  return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    int n;
    int t=0;//sec変更後変動あったか
    int flag,flagj;
    int cnt=0;
    cin >> n;
    int sec=1;
    vector<int>A(n);
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    // for(int i=0; i<n; i++){
    //     cout << A[i] << " ";
    // }cout << endl;
    // flag=A[0];
    // flagj=A[2];
    // for(int i=0; i<n-2; i++){
    //     for(int j=i+2; j<n; j++){
    //         if(sec==j) continue;
    //         cerr << i << " " << sec << " " << j<<endl;
    //         if(A[i]+A[sec]<=A[j]){
    //             if(t==j) {
    //                 sec++;j--;
    //                 continue;
    //             }
    //             cnt+=(j-sec)*(j-sec-1)/2;
    //             t=j;
    //             sec++;j--; 
    //             cerr << "->yes" << endl;
    //         }
    //         if(j==n-1 && A[i]+A[sec]>A[j]) {
    //             cnt+=(j-sec+1)*(j-sec)/2;
    //             cerr << "->kkkk" << endl;
    //         }
    //         cerr << cnt<< endl;
    //     }
    //     sec= i+2;
    // }
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(A[i]+A[j]>A[k]) cnt++;
                else break;
            }
        }
    }
    cout << cnt << endl;
}

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

int K[102][102], V, E;


int main() {
  int k, i, j, s, t, d;
  
  cin >> V >> E;
  
  for(i = 0; i < V; i++)
    for(j = 0; j < V; j++) {
      if (i == j) K[i][j] = 0;
      else K[i][j] = 0x7FFFFFFF;
    }
  for(i = 0; i < E; i++) {
    cin >> s >> t >> d;
    K[s][t] = d;
  }
  for(k = 0; k < V; k++)
    for(i = 0; i < V; i++)
      for(j = 0; j < V; j++)
	{
	  if (K[i][k] != 0x7FFFFFFF && K[k][j] != 0x7FFFFFFF) {
	    d = K[i][k] + K[k][j];
	    if (d < K[i][j]) K[i][j] = d;
	  }
	}
  for(i = 0; i < V; i++)
    if (K[i][i] < 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  for(i = 0; i < V; i++)
    {
      if (K[i][0] == 0x7FFFFFFF) cout << "INF";
      else cout << K[i][0];
      for(j = 1; j < V; j++)
	{
	  cout << " ";
	  if (K[i][j] == 0x7FFFFFFF) cout << "INF";
	  else cout << K[i][j];
	}
      cout << endl;
    }
  return 0;
}

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

int f(vector<int> v){
  if(v.size() == 0) return 0;
  if(v.size() == 1) return v[0];
  
  int m = *min_element(v.begin(), v.end());

  v.push_back(m);

  int res=m;
  vector<int> c;
  for (int i = 0; i < v.size(); i++) {
    if(v[i]==m){
      res +=f(c);
      c.clear();
    } else {
      c.push_back(v[i]-m);
    }
  }

  return res;
}

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

  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  
  cout << f(h) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  string S;
  cin >> S;
  int ans=0;
  string T;
  rep(i,S.size()){
    if(!T.size()) T.push_back(S[i]);
    else if(T[T.size()-1]==S[i]) T.push_back(S[i]);
    else{
      ans+=2;
      T.pop_back();
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main() {
  ll n,k,x,y;
  cin >> n >>k >>x >> y;
  ll ans=0;
  for(ll i=1;i<=n;i++){
    if(i<=k){ans+=x;}else{ans+=y;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,k;
    cin >> n >> k;
    vector<pair<ll,ll>>cnt(n);
    for(ll i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        cnt[i]=make_pair(a,b);
    }
    sort(cnt.begin(),cnt.end());
    ll count=0;
    ll ans;
    for(ll i=0;i<n;i++){
        count += cnt[i].second;
        if(count>=k){
            ans=cnt[i].first;
            break;
        }
    }
    cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n,m,x;
  cin >> n >> m >> x;

  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));

  REP(i,n){
    cin >> c[i];
    REP(j,m)cin >> a[i][j];
  }

  int ans=(1<<30);
  REP(i,(1<<n)){
    vector<int> s(m,0);
    int tmp=0;
    REP(j,n){
      if((i>>j) & 1){
        REP(k,m)s[k] += a[j][k];
        tmp += c[j];
      }
    }

    bool ok=true;
    REP(j,m){
      if(s[j] < x)ok=false;
    }

    if(ok)chmin(ans,tmp);
  }

  cout << (ans==(1<<30) ? -1 : ans) << endl;
}



Measured memory_bytes: 3636
import java.util.*;

public class Main {
  public static void main(final String[] args) throws Exception {
    final Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      int x = scanner.nextInt();
      int[] a = new int[n];

      for (int i = 0; i < n; i++) a[i] = scanner.nextInt();
      Arrays.sort(a);
      
      int ans = 0;
      for (int i = 0; i < n; i++) {
        if (i == n - 1) {
          if (a[i] == x) ans++;
        } else {
          if (a[i] <= x) {
            ans++;
            x -= a[i];
          }
        }
      }
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }
}


Measured memory_bytes: 21588
#include<iostream>
#define INT long long int
using namespace std;
int main(){
	INT a,b;
	cin>>a>>b;
	if(a>0){
		cout<<"Positive"<<endl;
	}else if(b>=0){
		cout<<"Zero"<<endl;
	}else{
		if(b-(a-1)%2==0)
			cout<<"Positive"<<endl;
		else
			cout<<"Negative"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int N, K;
string S;


int main(int argc, const char * argv[]) {
    cin >> N >> S >> K;
    rep(i, N) {
        if (S[i] != S[K-1]) S[i] = '*';
    }

    output(S);


    return 0;
}

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

int64_t n, m;

int main() {
    int64_t ans;

    cin >> n >> m;

    if (m / 2 < n) {
        ans = m / 2;
    }
    else {
        ans = n;
        m -= n * 2;
        ans += m / 4;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
from fractions import gcd
 
N=int(input())
a_list = tuple(int(i) for i in input().split())
MOD = 10**9+7

def cal_lcm(a, b):
  return int(a*b//gcd(a,b))

lcm = 1
for i in range(N):
  lcm = cal_lcm(lcm, a_list[i])
  
ans = 0
for i in range(N):
  ans += lcm//a_list[i]
print(ans%MOD)

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
vector<vector<int>>dp;
char g[1001][1001];
int calc(int i, int j, int n, int m){
   if(i==n-1&&j==m-1)
   return 1;
	
  if(i>=n||j>=m||g[i][j]=='#')
    return 0;
  if(dp[i][j]!=-1)
    return dp[i][j];
  int ans=(calc(i+1,j,n,m)%M+calc(i,j+1,n,m)%M)%M;
  return dp[i][j]=ans%M;
}
int main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      cin>>g[i][j];
  dp.resize(n,vector<int>(m,-1));
  int ans=calc(0,0,n,m);
  cout<<dp[0][0];
  return 0;
}

Measured memory_bytes: 8616
N = int(input())
S = list(input())

for a in [["S","S"],["S","W"],["W","S"],["W","W"]]:
    ans = a[0]+a[1]
    for i in range(1,N-1):
        if S[i] == "o":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "S"
        elif S[i] == "x":
            if ans[i] == "S" and ans[i-1] == "S":
                ans += "W"
            elif ans[i] == "S" and ans[i-1] == "W":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "S":
                ans += "S"
            elif ans[i] =="W" and ans[i-1] == "W":
                ans += "W"

    if S[-1] == "o":
        if ans[-1] == "S":
            if ans[-2] != ans[0]:
                ans = ""
        else:
            if ans[-2] == ans[0]:
                ans = ""
    elif S[-1] == "x":
        if ans[-1] == "S":
            if ans[-2] == ans[0]:
                ans = ""
        else:
            if ans[-2] != ans[0]:
                ans = ""
    
    if ans == "":
        continue

    if S[0] == "o":
        if ans[0] == "S":
            if ans[1] != ans[-1]:
                ans = ""
        else:
            if ans[1] == ans[-1]:
                ans = ""
    elif S[0] == "x":
        if ans[0] == "S":
            if ans[1] == ans[-1]:
                ans = ""
        else:
            if ans[1] != ans[-1]:
                ans = ""
    
    if ans != "":
        print(ans)
        exit()
print(-1)
            



Measured memory_bytes: 4268
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val ab = (0 until n).map { sc.next().toLong() to sc.next().toLong() }
    val cd = (0 until m).map { sc.next().toLong() to sc.next().toLong() }
    println(problem057b(n, m, ab, cd))
}

fun problem057b(
    n: Int,
    m: Int,
    ab: List<Pair<Long, Long>>,
    cd: List<Pair<Long, Long>>
): String {
    val ans = (0 until n).toMutableList()
    for (i in 0 until n) {
        var minPoint = Long.MAX_VALUE
        for (j in 0 until m) {
            val distance = Math.abs(ab[i].first - cd[j].first) + Math.abs(ab[i].second - cd[j].second)
            if (minPoint > distance) {
                minPoint = distance
                ans[i] = j + 1
            }
        }
    }
    return ans.joinToString("\n")
}

Measured memory_bytes: 31144
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

// 二次元累積和
struct cumulative_sum_2d {
    using lint = long long;
    int x, y;
    vector<vector<lint>> data;
    vector<vector<lint>> sum;
    cumulative_sum_2d(const int _x, const int _y) : x(_x), y(_y) {
        data.assign(x, vector<lint>(y, 0));
        sum.assign(x + 1, vector<lint>(y + 1, 0));
    }
    vector<lint> &operator[](const int k) {
        return data[k];
    }
    void build() {
        for (int i = 0; i < x; i++)
            for (int j = 0; j < y; j++)
                sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + data[i][j];
    }
    //[a,b)×[c,d)の和を計算
    lint query(const int a, const int b, const int c, const int d) const {
        return sum[b][d] - sum[b][c] - sum[a][d] + sum[a][c];
    }
};

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

lint n, k;

int main() {
    cin >> n >> k;
    int num_b = 0, num_w = 0;
    cumulative_sum_2d black(2 * k, 2 * k), white(2 * k, 2 * k);
    for (int i = 0; i < n; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        x %= 2 * k, y %= 2 * k;
        if (c == 'B') {
            black[x][y]++;
            num_b++;
        } else {
            white[x][y]++;
            num_w++;
        }
    }
    black.build();
    white.build();
    int ans = 0;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
            int b_ok = black.query(0, i, 0, j) + black.query(i + k, 2 * k, 0, j) +
                       black.query(i, i + k, j, j + k) + black.query(0, i, j + k, 2 * k) +
                       black.query(i + k, 2 * k, j + k, 2 * k);
            int w_ok = white.query(i, i + k, 0, j) + white.query(0, i, j, j + k) +
                       white.query(i + k, 2 * k, j, j + k) + white.query(i, i + k, j + k, 2 * k);
            chmax(ans, b_ok + w_ok);
            chmax(ans, num_b - b_ok + num_w - w_ok);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 125696
#include<stdio.h>

int main(void)
{
    int i, x, n;
    
    scanf("%d", &n);
    
    for ( i=1; i<=n; ++i) {
        x = i;
        
        if ( x%3 == 0)
            printf(" %d", i);
        else{
            do{
                if ( x%10 == 3) {
                    printf(" %d", i);
                    break;
                }
            }while( (x = x/10) != 0);
        }
    }
    putchar('\n');
    
    return 0;
}


Measured memory_bytes: 2056
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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

    string S;  cin >> S;
    int N = S.size();

    const ll MOD = 1e9 + 7;
    const int M = 13;
    vvl dp(N + MGN, vl(M + MGN, 0));
    dp[0][0] = 1;

    int dig = 1;
    for(int i=1; i<=N; i++) {
        if (S[N-i]=='?') {
            for (int d = 0; d<=9; d++) {
                for(int j=0; j<M; j++) {
                    dp[i][(d*dig + j) % M] += dp[i-1][j];
                    dp[i][(d*dig + j) % M] %= MOD;
                }
            }
        } else {
            int d = S[N-i] - '0';
            for(int j=0; j<M; j++) {
                dp[i][(d*dig + j) % M] += dp[i-1][j];
                dp[i][(d*dig + j) % M] %= MOD;
            }
        }

        dig *= 10;
        dig %= M;
    }

    ll ans = dp[N][5];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 19920
#include <bits/stdc++.h>
#define ll long long
#define L long
#define endl "\n"
#define mset(x, val) memset(x, val, sizeof(x))
#define For(i, init, n) for (ll int i = init; i < n; i++)
#define ___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

const double PI = acos(-1), E = exp(1.0), EPS = DBL_EPSILON;
const ll int MOD = (ll int)1e9 + 7, N = (ll int)1e5;

int main()
{   
#ifdef MY_PREPROCESSOR
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	// ___
	
	int d, t, s;
	cin >> d >> t >> s;
	if (d <= t * s)
		cout<< "Yes";
	else
		cout<< "No";
	
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(){
  int r, c;
  scanf("%d %d", &r, &c);

  /*表生成と初期化*/
  int table[r + 1][c + 1];

  for(int i = 0; i <= r; i++){
	for(int j = 0; j <= c; j++){
	  table[i][j] = 0;
	}
  }

  /*値の読み込み*/
  for(int i = 0; i < r; i++){
	for(int j = 0; j < c; j++){
	  scanf("%d", &table[i][j]);
	}
  }

  /*行の集計*/
  for(int i = 0; i < r; i++){
	for(int j = 0; j < c; j++){
	  table[i][c] += table[i][j];
	}
  }

  /*列の集計*/
  for(int i = 0; i <= c ; i++){
	for(int j = 0; j < r; j++){
	  table[r][i] += table[j][i];
	}
  }

  /*表の表示*/
  for(int i = 0; i <= r; i++){
	for(int j = 0; j <= c; j++){
	  printf("%d",table[i][j]);
	  if(j != c){printf(" ");}
	}
	printf("\n");
  }

  return 0;
}


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

typedef pair<int, int> ii;
typedef long long ll;

// (nPm)^2 - sigma(kCn * ((n-k)P(m-k))^2 * kPm)

const ll M = 500002, N = 500002;
const ll MOD = 1000000007; 
ll f[M];

void init(){
	f[0] = 1;
	for(int i = 1; i < M; i++){
		f[i] = (1LL * f[i-1] * i) % MOD;
	}
}

void extend_gcd(ll a, ll b, ll& x, ll& y){
	if(b == 0){
		x = 1;
		y = 0;
		return;
	}
	ll x1, y1;
	extend_gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - (a / b) * y1;
}

ll modpow(ll a, ll p){
    if (p == 0) return 1;
    
    if (p % 2 == 0) {
        return modpow(a * a % MOD, p / 2);
    
    } else
        return a * modpow(a, p - 1) % MOD;
}

ll inverse(ll k){
	ll x, y;
	extend_gcd(k, MOD, x, y);
	x = (x % MOD + MOD) % MOD;
	return x;

	// second way
	// return modpow(k, MOD - 2);
}

ll C(int k, int n){
	return (1LL * f[n] * inverse(f[k] * f[n-k])) %  MOD; 
}

ll P(int k, int n){
	return (1LL * f[n] * inverse(f[n-k])) % MOD;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	init();
	// ll ans = P(n, m);
	// ans = (1LL * ans * ans) % MOD;
	ll ans = 0;
	ll x;
	for(int i = 0; i <= n; i++){
		// ll p = P(n - i, m - i);
		// ll t = (((1LL * C(i, n) * ((1LL * p * p) % MOD)) % MOD) * P(i, m)) % MOD;  
		ll t = C(i, n) * P(n - i, m - i) % MOD * P(n - i, m - i) % MOD * P(i, m) % MOD;
		if(i & 1) ans = (ans - t + MOD) % MOD;
		else ans = (ans + t) % MOD;
	}
	if (ans < 0) ans += MOD;

	cout << ans % MOD;
}

// 141421 356237

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int A, B; cin >> A >> B;
  if (A <= 9 && B <= 9) {
    cout << A * B << endl;
  }else {
    cout << "-1\n";
  }

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}



int main() {
	string s1, s2;
	cin >> s1 >> s2;
	int l1 = s1.length(); int l2 = s2.length();
	if (l1 != l2) {
		if (l1 > l2) {
			cout << "GREATER" << endl;
			return 0;
		}
		else {
			cout << "LESS" << endl;
			return 0;
		}
	}
	else {
		REP(i, l1) {
			if (s1[i] != s2[i]) {
				if (s1[i] > s2[i]) {
					cout << "GREATER" << endl;
					return 0;
				}
				else {
					cout << "LESS" << endl;
					return 0;
				}
			}
		}
		cout << "EQUAL" << endl;
		return 0;
	}
}


Measured memory_bytes: 256