akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;

int main() {
 

vector<int> A(3);
  cin>>A[0]>>A[1]>>A[2];
  sort(A.begin(),A.end());
  if((2*A[2]-A[1]-A[0])%2==0)cout<<(2*A[2]-A[1]-A[0])/2<<endl;
  else cout<<(2*A[2]-A[1]-A[0]+4)/2<<endl;
// for(int i=0; i<N; i++)cin>>A[i];}
// vector<vector<int>> A(N,vector<int>(M));
// for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}

}



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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N; in(N);
  int ans = 0;
  int next = 1;
  rep(i, 0, N) {
    int ai; in(ai);
    if (ai == next) next++;
    else ans++;
  }
  print(next == 1 ? -1 : ans);
}


Measured memory_bytes: 256
short t[3600];w,h,c,z;f(x,i){for(t[x]=0;i;t[z=x+"<>xyz\1\2"[--i]-61]&1&&f(z,8));}main(i){for(;scanf("%d%d",&w,&h)*h;printf("%d\n",c)){for(i=++h;c=--i;)scanf(" %[^\n]",i*60+1+t);for(;!i?i=w,--h:1;)t[z=h*60+i--]&1&&++c-f(z,8);}}

Measured memory_bytes: 0
n = int(input())
data = []
for _ in range(n):
    data.append(list(map(int, input().split())))
data = sorted(data, key=lambda x: x[2], reverse=True)

ok = True
res = []
x0, y0, h0 = data[0]
for cx in range(101):
    for cy in range(101):
        hh = h0 + abs(cx - x0) + abs(cy - y0)
        ok = True
        for i, (x, y, h) in enumerate(data[1:]):
            if h != max(hh - abs(cx - x) - abs(cy - y), 0):
                ok = False
                continue
        if ok:
            res = [cx, cy, hh]
            break
    if ok:
        break
print(' '.join(map(str, res)))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long N,H;

int main(){
	while(cin >> N >> H){
		vector<long long>A(N,0), B(N,0);
		long long ans = 0;
		for(int i=0;i<N;i++){
			cin >> A[i] >> B[i];
		}
		sort(A.begin(),A.end());
		reverse(A.begin(),A.end());
		sort(B.begin(),B.end());
		reverse(B.begin(),B.end());
		long long amax = A[0];
		long long b = B[0];
		long long i = 0;
		while(b>=A[0] && i<N && H>0){
			H -= b;
			ans++;
			i++;
			if(i < N) b = B[i];
		}
		if (H > 0){
			ans += H/A[0];
			if(H%A[0] != 0) ans++;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 1792
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)

const int maxn=2e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
ll n ;
ll k ;
double arr[maxn];
double ans;
double ps[maxn];
int main(){
	migmig;
	cin >> n >> k;
	for(int i = 1 ; i <= n;i++){
		double x ;
		cin >> x;
		arr[i] = (x * (x+1))/x/2;
	}
	for(int i = 1 ; i <= n;i++){
		ps[i] = ps[i-1] + arr[i];
		//cout<<ps[i]<<" ";
	}
	for(int i = k ; i <= n ;i++){
		//cout<<ps[i]<<" "<<ps[i-k-1]<<endl;
		ans = max(ans , ps[i] - ps[i-k]);
	}
	cout<<fixed<<setprecision(10);
	cout<<ans;
}



Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  s[b-1]  = tolower(s[b-1]);
  cout << s;
return 0;
}

Measured memory_bytes: 256
n,m,x = map(int, input().split())
ref = []
c = []
for i in range(n):
  ref.append(list(map(int, input().split())))
  c.append(ref[i].pop(0))
ans = sum(c)
ok = False
for i in range(1<<n):
  cost = 0
  skill = [0]*m
  for r,j in enumerate(ref):
    if (i>>r)&1 == 1:
      cost += c[r]
      for k in range(m):
        skill[k] += j[k]
  if min(skill)>=x:
    ok = True
    if cost < ans:
      ans = cost
if ok:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 9220
def main():
    input = sys.stdin.readline
    try:
        N = int(input())
        a = [int(input()) for i in range(N)]
        i = 0
        cnt = 0
        while True:
            cnt += 1
            if a[i] == 2:
                print(cnt)
                break
            elif a[i] == -1:
                print(-1)
                break
            a[i], i = -1, a[i] - 1

    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


Measured memory_bytes: 7084
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long

int main(){

    int a[3];
    for(int i=0;i<3;i++) cin >> a[i];
    sort(a,a + 3);
    int ans = 0;
    for(int i=1;i<3;i++){
        ans += a[i] - a[i-1];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}

int main(){
  long double a, b, c;
  cin >> a >> b >> c;
  if(a+b+2*sqrt(a*b)<c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

/*bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}*/

int memo[100010];
vector<vector<int>> v(100010);
int N, M;

int dfs(int V)
{
    if (memo[V] != -1)
        return memo[V];
    memo[V] = 0;
    for (int i = 0; i < (int)v[V].size(); ++i)
    {
        memo[V] = max(memo[V], dfs(v[V][i]) + 1);
    }
    return memo[V];
}

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

    cin >> N >> M;
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
    }
    for (int i = 0; i < 100010; ++i)
    {
        memo[i] = -1;
    }
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        ans = max(ans, dfs(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define lb(a, b) lower_bound(a.begin(), a.end(), b)
#define ub(a, b) lower_bound(a.begin(), a.end(), b)
#define st(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef long double ld;
using namespace std;

struct WS{
  vvl d = vv(0, 0, 0, ll);
  ll N;
  WS(ll n){
    N = n;
    d.resize(n+1, vll (n+1, 10000000000));
    init();
  }
  void init(){
    re(i, N+1) d[i][i] = 0;
  }
  void insert(ll a, ll b, ll c){
    d[a][b] = min(d[a][b], c);
  }
  void warshall(){
    init();
    re(i, N+1) re(s, N+1) re(t, N+1) d[s][t]=min(d[s][t],d[s][i]+d[i][t]);
  }
};

struct permutation{
  vector<int> v, idx;
  ll N;
  permutation(ll n){
    v.resize(n);
    idx.resize(n);
    N = n;
    init();
  }
  void init(){
    re(i, N) v[i] = i;
  }
  bool step(){
    return next_permutation(v.begin(), v.end());
  }
  void sorted(){
    re(i, N) idx[v[i]] = i;
  }
};
int main(int argc, char const *argv[]) {
  ll x, y, z, n, m, r;std::cin >> n >> m >> r;
  vll s(r);re(i, r) std::cin >> s[i];
  WS w(n);
  re(i, m){
    std::cin >> x >> y >> z;
    w.insert(x, y, z);
    w.insert(y, x, z);
  }
  w.warshall();
  ll ans = 10000000000000000;
  permutation p(r);

  do{
    ll tmp = 0;
    p.sorted();
    rep(i, 1, r) tmp += w.d[s[p.idx[i]]][s[p.idx[i-1]]];
    ans = min(ans, tmp);
  }while(p.step());
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 760
n, m = map(int, input().split())
list = []
for x in range(n):
    list.append(0)
for y in range(m):
    a, b = map(int, input().split())
    list[a - 1] += 1
    list[b - 1] += 1
for id in range(n):
    print(list[id])


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define MAX 200000
#define MOD (int) 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//階乗とその逆元
ll fac[MAX+1],facInv[MAX+1];

ll power(ll e, ll x){ //e^x % MOD
    if (x == 0) return 1LL;
    if (x % 2 != 0) return ((power(e, x-1) * e) % MOD);
    ll temp = power(e, x / 2);
    return (temp * temp) % MOD;
}

ll nck(ll n, ll k){
    if (!(n >= k && k >= 0)) return 0;
    ll temp = (fac[n] * facInv[n-k]) % MOD;
    return ((temp * facInv[k]) % MOD);
}

void fact(void){
    //階乗とその逆元
    fac[0] = facInv[0] = 1; //0! = 1
    //(x!)^(-1) ≡ (x!)^(p-2) (mod p)
    Rep(1, MAX, i) fac[i] = (fac[i-1] * i) % MOD;
    facInv[MAX] = power(fac[MAX], MOD-2);
    Rep(1, MAX-1, i) facInv[MAX-i] = (facInv[MAX-i+1] * (MAX-i+1)) % MOD;
}

void solve(void){
    int w, h, a, b;
    cin >> h >> w >> a >> b;
    //combination
    fact();
    ll ans = 0;
    Rep(0, h-a-1, i) {
        ans += nck(i+b-1, i) * nck(h+w-b-i-2, h-i-1);
        ans %= MOD;
    }
    cout << ans << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
#define _USE_MATH_DEFINES

int main(){
	double r;
	double s, l;

	cin >> r;
	//r = 2561.234;

	s = M_PI * r * r;
	l = 2 * M_PI * r;
	
	cout << fixed << setprecision(10) << s << " " << l << endl;

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  float result = 0;
  string type;
  float btc_rate = 380000.0;
  for (int i=0; i<N; i++) {
    float money;
    cin >> money >> type;
    if (type == "JPY") {
      result += money;
    } else {
      result += money*btc_rate;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll k;cin>>k;
    while(n){
        n/=k;
        ans++;
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var n,m int
  fmt.Scan(&n)
  var v []int = make([]int,n)
  var c []int = make([]int,n)
  for i:=0;i<n;i++ { fmt.Scan(&v[i]) }
  for i:=0;i<n;i++ { fmt.Scan(&c[i]) }
  for i:=0;i<n;i++ {
    if v[i]-c[i] > 0 { m += v[i]-c[i] }
  }
  fmt.Println(m)
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;
typedef long long ll;

int main() {
	ll n, a;
	cin >> n;
	set<ll>st;
	for (ll i = 0;i < n;i++) {
		cin >> a;
		if (!st.count(a))st.insert(a);
		else st.erase(a);
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 4864
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    mod = 2019
    l, r = map(int, input().split())
    l_div = l // mod
    if mod * (l_div + 2) < r:
        print(0)
        quit()
    elif mod * (l_div + 1) < r:
        print(1)
        quit()
    ans = 2020
    r_mod = r % mod
    for i in range(l % mod, r_mod + 1):
        for j in range(i+1, r_mod + 1):
            ans = min(ans, i * j % mod)
    print(ans)

if __name__ == '__main__':
    main()


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

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    int maxx=0,minx=w,maxy=0,miny=h;
    int x,y,a;

    for (int i = 0; i < n; i++){
        cin >> x >> y >> a;
        if (a==2){
            minx = min(x,minx);
        }else if (a==1){
            maxx = max(maxx,x);
        }else if (a==4){
            miny = min(miny,y);
        }else{
            maxy = max(maxy,y);
        }
    }
    if (minx <= maxx || miny <= maxy){
        cout << 0 << endl;
        return 0;
    }else{
        cout << (minx-maxx)*(miny-maxy) << endl;
        return 0;
    }
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>

constexpr int MAX_D = 50;
int Count[2 * MAX_D + 1][2 * MAX_D + 1];


int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);

    int n; std::cin >> n;
    for(int i = 0; i < n; ++i){
        std::string S; std::cin >> S;
        const int m = S.size();
        int dot = m;
        long long int val = 0;
        for(int idx = 0; idx < m; ++idx){
            if(S[idx] == '.') dot = idx + 1;
            else val = 10 * val + (S[idx] - '0');
        }
        int two = dot - m, five = dot - m;
        while(val % 2 == 0){ val /= 2; ++two; }
        while(val % 5 == 0){ val /= 5; ++five; }
        ++Count[two + MAX_D][five + MAX_D];
    }

    long long int res = 0;
    for(int i1 = -MAX_D; i1 <= MAX_D; ++i1) for(int j1 = -MAX_D; j1 <= MAX_D; ++j1){
        const long long int a = Count[i1 + MAX_D][j1 + MAX_D];
        if(i1 >= 0){
            if(j1 >= 0) res += a * (a - 1) / 2;
            for(int j2 = j1 + 1; j2 <= MAX_D; ++j2) if(j1 + j2 >= 0){
                res += a * Count[i1 + MAX_D][j2 + MAX_D];
            }
        }
        for(int i2 = i1 + 1; i2 <= MAX_D; ++i2) if(i1 + i2 >= 0){
            for(int j2 = -MAX_D; j2 <= MAX_D; ++j2) if(j1 + j2 >= 0){
                res += a * Count[i2 + MAX_D][j2 + MAX_D];
            }
        }
    }
    std::cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    cout<<count(s.begin(),s.end(),'2');
    return 0;
}


Measured memory_bytes: 3656
N = int(input())
S = input()

num_west = [0] * N
for i, s in enumerate(S, 1):
  if i == N:
    continue
  num_west[i] += num_west[i-1]
  if s == 'W':
    num_west[i] += 1

num_east = [0] * N
S = S[::-1]
for i, s in enumerate(S, 1):
  if i == N:
    continue
  num_east[i] += num_east[i-1]
  if s == 'E':
    num_east[i] += 1
num_east = num_east[::-1]

ans = N
for nw, ne in zip(num_west, num_east):
  ans = min(ans, nw + ne)

print(ans)

Measured memory_bytes: 29644
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 60, MAXD = 1000 + 10;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

bool mp[MAXN][MAXN][4];
bool vis[MAXD][MAXN][MAXN][4];
int dir[MAXD];

struct Node {
  int x, y, s, d;
  Node() {}
  Node(int x, int y, int s, int d): x(x), y(y), s(s), d(d) {}
};

int main() {
  int n, x0, y0, t;
  while (scanf("%d%d%d%d", &n, &x0, &y0, &t) == 4) {
    memset(mp, 0, sizeof(mp));
    memset(vis, 0, sizeof(vis));
    memset(dir, -1, sizeof(dir));
    for (int i = 0; i < n; ++ i) {
      int xs, ys, xe, ye; scanf("%d%d%d%d", &xs, &ys, &xe, &ye);
      if (xs == xe) {
        if (ys > ye) swap(ys, ye);
        for (int y = ys; y <= ye; ++ y) {
          if (y < ye) mp[xs][y][1] = 1;
          if (y > ys) mp[xs][y][3] = 1;
        }
      }
      else {
        if (xs > xe) swap(xs, xe);
        for (int x = xs; x <= xe; ++ x) {
          if (x < xe) mp[x][ys][0] = 1;
          if (x > xs) mp[x][ys][2] = 1;
        }
      }
    }
    int m = 0;
    for (int i = 0; i < t; ++ i) {
      int d; char op[10];
      scanf("%d%s", &d, op);
      m += d;
      if (op[0] == 'E') dir[m] = 0;
      if (op[0] == 'N') dir[m] = 1;
      if (op[0] == 'W') dir[m] = 2;
      if (op[0] == 'S') dir[m] = 3;
    }
    vector<PII> res;
    queue<Node> Q;
    Q.push(Node(x0, y0, 0, -1));
    while (!Q.empty()) {
      Node nw = Q.front(); Q.pop();
      int s = nw.s, d = nw.d, rd = d ^ 2;
      if (s == m) {
        if (d == dir[m] || (rd != dir[m] && mp[nw.x][nw.y][dir[m]])) {
          res.push_back(PII(nw.x, nw.y));
        }
        continue;
      }
      for (int i = 0; i < 4; ++ i) {
        if (i == rd || !mp[nw.x][nw.y][i]) continue;
        if (dir[s] >= 0 && i != dir[s] && nw.d != dir[s]) continue;
        int ss = s + 1, x = nw.x + dx[i], y = nw.y + dy[i];
        if (!vis[ss][x][y][i]) {
          vis[ss][x][y][i] = 1;
          Q.push(Node(x, y, ss, i));
        }
      }
    }
    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());
    for (auto &p: res) {
      printf("%d %d\n", p.first, p.second);
    }
  }
  return 0;
}

Measured memory_bytes: 15464
X = 10**4
H, W = map(int, input().split())

# 入力マップ(1,1~(H,W)を埋める)
map_data = [['.' for j in range(W+1)] for i in range(H+1)]
for i in range(H):
    dat = list(input())
    for j in range(W):
        map_data[i+1][j+1] = dat[j]

# 計算マップ
r_map_data = [[X for j in range(W+1)] for i in range(H+1)]
# 始めのマスが0となるように初期化
r_map_data[0][1] = 0
r_map_data[1][0] = 0

# (1,1)~(H-1,W-1)のマスを調べる
for i in range(H):
    for j in range(W):
        # 真上の値を取得
        t_val = r_map_data[i][j+1]
        # 白→黒ときは+1
        if(map_data[i][j+1] == '.' and map_data[i+1][j+1] == '#'):
            t_val += 1

        # 真左の値を取得
        l_val = r_map_data[i+1][j]
        if(map_data[i+1][j] == '.' and map_data[i+1][j+1] == '#'):
            l_val += 1

        val = min([t_val, l_val])
        # 取得した値をセット
        r_map_data[i+1][j+1] = val

print(r_map_data[H][W])

Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(true){
String s = sc.next();
if(s.equals("0")){
break;
}
int sum = 0;
for (int i = 0;i < s.length(); i++){
sum = sum + s.charAt(i) - '0';
}
System.out.println(sum);
}
sc.close();
}
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
	ll n;
	cin >> n;
	vll w(n);
	vin(w);
	ll ans = mod;
	rep(i, 1, n) chmin(ans, (ll)abs(accumulate(w.begin(), w.begin() + i, 0) - accumulate(w.begin() + i, w.end(), 0)));
	cout << ans << endl;	
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main (String [] args){
		ArrayList <Integer> list = new ArrayList<Integer>();
//		String [][] boad = new String[4][4];
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		int c = Integer.parseInt(sc.next());
//		int d = Integer.parseInt(sc.next());
		int count = 0;
		if(a<b){
			for(int i = 0; i < a; i++){
				int d = i+1;
				if(a%d == 0 && b%d == 0){
					list.add(d);
				}
			}
		}else{
			for(int i = 0; i < b; i++){
				int d = i+1;
				if(a%d == 0 && b%d == 0){
					list.add(d);
				}
		}
		}
		
		System.out.println(list.get(list.size()-c));
		System.out.flush();
		sc.close();

	}
}

Measured memory_bytes: 24020
import java.io.*;
import java.util.*;

public class Main {

  static FastScanner sc = new FastScanner();

  public static void main(String[] args) {

    int N = sc.nextInt();
    int T = sc.nextInt();

    int minCost = Integer.MAX_VALUE;
    for (int i=0; i<N; i++) {
      int c = sc.nextInt();
      int t = sc.nextInt();
      if (t <= T) {
        minCost = Math.min(minCost, c);
      }
    }

    if (minCost == Integer.MAX_VALUE) {
      System.out.println("TLE");
    } else {
      System.out.println(minCost);
    }

  }

  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) return buffer[ptr++];
      else return -1;
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
      skipUnprintable();
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      return (int) nextLong();
    }
  }

}


Measured memory_bytes: 22996
n=int(input())
s=[int(c) for c in input()]

pc=sum(s)

resm=[0]*n
resp=[0]*n

jm=1
jp=1

totm=0
totp=0
for i in range(n):
    if pc-1>0:
        resm[n-i-1]=jm%(pc-1)
        jm=(2*jm)%(pc-1)
        totm+=resm[n-i-1]*s[n-i-1]
        totm%=pc-1
    
    resp[n-i-1]=jp%(pc+1)
    jp=(2*jp)%(pc+1)
    totp+=resp[n-i-1]*s[n-i-1]
    totp%=pc+1

def popc(x):
    return sum([int(c) for c in format(x,'b')])

for i in range(n):
    if s[i]==1:
        pcc=pc-1
        if pcc==0:
            print(0)
            continue
        cres=(totm+pc-1-resm[i])%(pc-1)
    else:
        pcc=pc+1
        cres=(totp+resp[i])%(pc+1)
    
    if cres==0:
        print(1)
        continue

    cnt=1
    while cres>0:
        cres%=popc(cres)
        cnt+=1
    
    print(cnt)


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

signed main(){
  bool ok = false;
  lint K, A, B; cin >> K >> A >> B;
  for(lint i = A; i <= B; i++){
    if(i % K == 0) ok = true;
  }
  if(ok) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
long long hh;
int n;
int main() {
  //freopen (".in", "r", stdin);
  //freopen (".out", "w", stdout);
  scanf ("%d", &n);
  for (int i = 1; i <= n; i++) {
  	int x;
  	scanf ("%d", &x);
  	hh += (x - 1);
	}
	cout<<hh<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll a[21][21];

int main()
{
	while (1) {
		cin >> n;
		if (n == 0) {
			return 0;
		} else {
			memset(a, 0, sizeof(a));

			REP(i, n)
			{
				ll x, y;
				cin >> x >> y;
				a[y][x] = 1;
			}

			ll x = 10, y = 10;
			ll cnt = 0;

			ll m;
			cin >> m;
			REP(i, m)
			{
				char c;
				ll step;
				cin >> c >> step;
				REP(j, step)
				{
					if (c == 'N') { y++; } else if (c == 'S') { y--; } else if (c == 'E') { x++; } else { x--; }

					if (a[y][x]) {
						a[y][x] = 0;
						cnt++;
					}
				}
			}

			if (cnt == n) {
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
		}
	}
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n;
ll D, A;
struct monsters
{
    ll x, h;
    bool operator<(const monsters &X) const
    {
        return x < X.x;
    }
} a[N];
ll mark[N];

void solve()
{
    scanf("%d%lld%lld", &n, &D, &A);
    for (int i = 1; i <= n; ++i)
        scanf("%lld%lld", &a[i].x, &a[i].h);
    sort(a + 1, a + n + 1);
    int las = 1;
    int i = 1;
    ll ans = 0;
    ll delta = 0;
    while (las <= n)
    {
        while ((a[i + 1].x - a[las].x > 2ll * D || i == n) && las <= n)
        {
            ll cnt = max(0ll, a[las].h / A + (a[las].h % A > 0));
            mark[i] += -cnt * A;
            ans += cnt;
            delta += cnt * A;
            a[las].h -= delta;
            delta += mark[las];
            las++;
            while (las <= n)
            {
                a[las].h -= delta;
                delta += mark[las];
                mark[las] = 0;
                if (a[las].h > 0)
                    break;
                las++;
            }
        }
        i = min(i + 1, n);
    }
    cout << ans << '\n';
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 8064
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, tpoint, hpoint int
	fmt.Scan(&n)
	taro := make([]string, n)
	hanako := make([]string, n)
	for i:=0; i<n; i++{
		fmt.Scan(&taro[i], &hanako[i])
		taro[i] = strings.ToLower(taro[i])
		hanako[i] = strings.ToLower(hanako[i])

		if taro[i] > hanako[i]{
			tpoint += 3
		}else if taro[i] == hanako[i]{
			tpoint++
			hpoint++
		}else{
			hpoint += 3
		}
	}

	fmt.Println(tpoint, hpoint)
}


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

typedef long long LL;
#define MP make_pair
#define N 100010

int c[N], vis[N];

int main()
{
	/*s1 + s2 - 1 + s3 - 2 +...
	s1 + s2 +...sk - (0 + 1 + 2 + ...k - 1) = n
	0 + 1 + ... k - 1 = n
	k * (k - 1) / 2 = n*/
	
	int n;
	scanf("%d", &n);
	int k = 1;
	while (k * (k - 1) / 2 < n) ++k;
	if (k * (k - 1) / 2 > n) return puts("No"), 0;
	puts("Yes");
	//k * (k - 1) = 2 * n
	/*n = 6, k = 4
	1 2 3
	1     4 5
      2   4   6
        3   5 6
	n = 10, k = 5
	1 2 3 4
	1       5 6 7
	  2     5     8 9
	    3     6   8   10 
		  4     7   9 10 */
    printf("%d\n", k);
    for (int i = 1; i <= k; ++i)
    {
    	printf("%d", k - 1);
    	int cnt = k - 1;
    	vector<int> lis;
    	for (int j = 1; j <= n && cnt; ++j)
    	{
    		if (c[j] == -1) continue;
    		if (c[j] == 0)
    		{
    			c[j] = i;
    			--cnt;
    			printf(" %d", j); 
    		}
    		else if (c[j])
			{
				if (vis[c[j]]) continue;
				vis[c[j]] = i;
				lis.push_back(c[j]);
				--cnt;
				printf(" %d", j);
				c[j] = -1;
			}
    	}
    	for (auto v: lis) vis[v] = 0;
    	puts("");
    }
	
	
	return 0;
}

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

struct Node{
  int key;
  Node *prev, *next;
};

Node *nil;

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->prev = nil;
  nil->next = nil;
}

void insert(int key){
  Node *p = (Node *)malloc(sizeof(Node));
  p->key = key;
  p->next = nil->next;
  nil->next->prev = p;
  nil->next = p;
  p->prev = nil;
}

Node* searchNode(int key){
  Node *p = nil->next;
  while(p->key != key && p != nil){
    p = p->next;
  }
  return p;
};

void deleteNode(Node *p){
  if(p == nil) return;
  p->next->prev = p->prev;
  p->prev->next = p->next;
  free(p);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteElem(int key){
  deleteNode(searchNode(key));
}

void printList(){
  Node *p = nil->next;
  int i=0;
  while(p!=nil){
    if(i) cout << " ";
    cout << p->key;
    p = p->next;
    i++;
  }
  cout << endl;
}

int main(){
  int n, x;
  string command;
  init();
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> command;
    if(command == "insert"){
      cin >> x;
      insert(x);
    }else if(command == "delete"){
      cin >> x;
      deleteElem(x);
    }else if(command == "deleteFirst"){
      deleteFirst();
    }else if(command == "deleteLast"){
      deleteLast();
    }
  }
  printList();
  return 0;
}



Measured memory_bytes: 34328
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

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

int w, h;

int dist[100][100];
const int INF = 100000000;

int main() {
  while(true) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    vector<int> m[100];
    rep(i, 2 * h - 1) {
      if(i % 2 == 0) {
        rep(j, w - 1) {
          int x;
          cin >> x;
          m[i].push_back(x);
        }
      } else {
        rep(j, w) {
          int x;
          cin >> x;
          m[i].push_back(x);
        }
      }
    }

    rep(i, h) {
      rep(j, w) {
        dist[i][j] = INF;
      }
    }
    // cout << dist[3][8] << endl;

    dist[0][0] = 0;

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

    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));

    while(que.size()) {
      pair<int, int> p = que.front();
      que.pop();
      int x = p.first;
      int y = p.second;
      // cout << x << " " << y << endl;

      for(int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(0 <= nx && nx < h && 0 <= ny && ny < w && dist[nx][ny] == INF) {
          if(i == 0 && m[2*x+1][y] != 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.push(make_pair(nx, ny));
          }
          if(i == 3 && m[2*x-1][y] != 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.push(make_pair(nx, ny));
          }
          if(i == 2 && m[2*x][y-1] != 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.push(make_pair(nx, ny));
          }
          if(i == 1 && m[2*x][y] != 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.push(make_pair(nx, ny));
          }
        }
      }
    }

    // cout << m[1][1] << m[2][1] << m[3][1] << m[2][0] << endl;
    // cout << dist[2][1] << endl;
    
    // cout << m[3][4] << m[4][4] << m[5][4] << m[4][3] << endl;
    if(dist[h-1][w-1] != INF)cout << dist[h-1][w-1] + 1 << endl;
    else cout << 0 << endl;

    // while(que.size()) {
    //   que.pop();
    // }


    // rep(i, 2 * h - 1) {
    //   int size = m[i].size();
    //   rep(j, size) {
    //     m[i].pop_back();
    //   }
    // }
    // cout << m[0][0] << endl;

  }



  return 0;
}


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

int main() {
	int N;
	cin >> N;
	int dist=0;
	vector <int> W(N);
	for (int i=0;i<N;i++){
		cin >> W.at(i);
		dist+=W.at(i);
	}
	int S1,S2;
	S1=0;
	S2=0;
	for (int i=0;i<N-1;i++){
		for (int j=0;j<=i;j++){
			S1+=W.at(j);
		}
		for (int j=i+1;j<N;j++){
			S2+=W.at(j);
		}
		dist = min (dist, abs(S1-S2) );
		S1=0;
		S2=0;
	}
	cout << dist<<endl;
}

Measured memory_bytes: 256
n = STDIN.gets.chomp.to_i
s = []
n.times { |i| s.push(STDIN.gets.chomp.chars.sort.join) }

h = Hash.new(0)
s.each do |str|
  h[str] += 1
end

result = 0
h.values.each do |v|
  result += v*(v-1)/2
end

puts result

Measured memory_bytes: 34812
import java.math.BigDecimal;
import java.util.Scanner;
public class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
    double a;

            a = sc.nextDouble();

            System.out.println(BigDecimal.valueOf(a*a*Math.PI).toPlainString()+" "+ BigDecimal.valueOf( a * 2 * Math.PI).toPlainString());



    }
}



Measured memory_bytes: 28280
x = gets.to_i
array = [1]

for i in 2..31 do
  n = i*i
  array << n
  while n <= 1000 do
    n = n*i
    array << n
  end
end

array.sort!

for i in 0..111 do
  if x < array[i]
    res = array[i-1]
    break
  end
end

puts res


Measured memory_bytes: 1788
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.trim()).split("\n");
var N1 = Number(Arr[0])
var arr1 = Arr[1].split(" ").map(Number);
var arr2 = Arr[3].split(" ").map(Number);

const linearSearch = (key, arr) => {
  for (let i = 0; i < N1; i++) {
      if (arr[i] === key) return 1;
  }
  return 0;
}
console.log(arr2.map(e => linearSearch(e, arr1)).reduce((a, b) => a + b, 0));



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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int k;
    cin >> k;
    Int x = 0;
    for (Int i = 1; i <= 1000000; i++) {
        x = (x * 10 + 7) % k;
        if (x == 0) {
            print(i);
            return 0;
        }
    }
    print(-1);
    return 0;
}


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

long long wt[105],value[105],dp[105][100005];   ///dp[i][j] means maximum profit for taking exactly j kg product from i to n index

int main()
{
    long long i,j,k,cap,ans=0,n;
    cin>>n>>cap;
    for(i=1 ; i<=n ; i++)   cin>>wt[i]>>value[i];

    for(j=0 ; j<=cap ; j++) dp[n+1][j] = 0;

    for(i=n ; i>=1 ; i--){
        for(j=0 ; j<=cap ; j++){
            if(wt[i] > j)
                dp[i][j] = dp[i+1][j];
            else
                dp[i][j] = max(dp[i+1][j] , value[i]+dp[i+1][j-wt[i]]);
        }
    }

    for(j=0 ; j<=cap ; j++)
        ans = max(ans , dp[1][j]);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 82516
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  p;
struct edge{int to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな

signed main(){
    int n;cin>>n;
    int num[214514];
    int key[214514];
    rep(i,0,n){
        cin>>num[i];key[i]=num[i];
    }
    sort(key,key+n);
    int sm=key[n/2-1],bi=key[n/2];
    rep(i,0,n){
        if(num[i]<=sm)cout<<bi<<endl;
        else if(num[i]>=bi)cout<<sm<<endl;
    }
    return 0;
}

Measured memory_bytes: 5376
import re

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

S = input()
K = int(input())

con = list(nchars(S, 1))
#print(con)
if len(con)==1:
    print(int(len(S)*K/2))

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[-1][0]:
        c3 = int(len(con[0]+con[-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[-1])/2)

    c4 = int(cons[-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long 
#define mod 1000000007

using namespace std;

char grid[10004][10004];
int dp[1004][1004]={0};
ll gridsolve(int i,int j,int n,int m){
    
    //base case
    if(i==n && j==m)
    {   
        return 1;
    }
    if(n<i || j>m || grid[i][j]=='#'){
        return 0;
    }


    if(dp[i][j]!=-1) return dp[i][j]%mod;
    

    int o1= gridsolve(i+1,j,n,m)%mod; 
    int o2= gridsolve(i,j+1,n,m)%mod; 
    
    return dp[i][j]=(o1+o2)%mod;
}

int main() {
    int n,m;
    cin>>n>>m;
    //char grid[n][m];
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
    {   for(int j=0;j<m;j++)
        {   cin>>grid[i][j];    }
    }
    cout<<gridsolve(0,0,n-1,m-1)<<endl;
    return 0;
}


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

string solve(string num, string op){

  if(op.size() == 7){
    int s = (int) (op[0]-'0');
    rep(i,3){
      if  (op[2*i+1]=='+') s += (int) (op[2*(i+1)] - '0');
      else                 s -= (int) (op[2*(i+1)] - '0');
    }
    return (s==7) ? op : "";
  }

  string buf = op;
  buf.push_back('+');
  buf.push_back(num[0]);
  string ans1 = solve(num.substr(1), buf);

  buf = op;
  buf.push_back('-');
  buf.push_back(num[0]);
  string ans2 = solve(num.substr(1), buf);

  return (ans1.size() >= ans2.size())? ans1 : ans2 ;
}

int main(){
  string s;
  cin >> s;
  string op;
  op.push_back(s[0]);
  cout << solve(s.substr(1),op) <<"=7"<< endl;
}



Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

# 0-indexでやる

D = int(readline())
C = list(map(int,readline().split())) # 満足度の下がりやすさ
S = [None] * D
sortS = [None] * D
for i in range(D):
  s = list(map(int,readline().split()))
  S[i] = s.copy()
  for j in range(len(s)):
    s[j] = (s[j],j)
  sortS[i] = sorted(s, key = lambda x:x[0], reverse = True)

def make_ans(D,C,limiter = 4, threshold = 2, balance = 0.5, check_limit = False):
  ans = []
  last_submit = [0] * 26
  for i in range(D):
    info = sortS[i]
    
    if check_limit:
    
      # limiter回以上提出がないものがあれば、threshold回を超えたもののうちCの値が高いものを提出
      if i - min(last_submit) >= limiter:
        ind = -1
        for j in range(len(last_submit)):
          if i - last_submit[j] >= threshold:
            if ind == -1:
              ind = j
            else:
              if C[ind] < C[j]:
                ind = j
        ans += [ind]
        last_submit[ind] = i
        continue
      
    topval = info[0][0]
    for j in range(len(info)):
      val = info[j][0]
      if check_limit:
        if val < topval * (balance):
          continue # 最高値の半分になるのであればやめよう
      index = info[j][1]
      if i - last_submit[index] < 26:
        continue
      ans += [index]
      last_submit[index] = i
      break
    else:
      ans += [info[0][1]]
  return ans

def calc_score(arr):
  point = 0
  last_submit = [0] * 26
  for i in range(len(arr)):
    # i日目
    point += S[i][arr[i]]
    for j in range(len(last_submit)):
      point -= (i - last_submit[j]) * C[j]
  return point
      
ans = make_ans(D,C)
#print(ans)
best = calc_score(ans)
for limiter in range(36,52):
  for threshold in range(26, limiter):
    for balance in (0.25, 0.5, 0.75):
      new_ans = make_ans(D,C,limiter,threshold,balance,True)
      new_score = calc_score(new_ans)
      if new_score > best:
        ans = new_ans
        best = new_score
  
def show(arr):
  for a in arr:
    print(a + 1)
    
show(ans)


Measured memory_bytes: 10264
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
lli power(lli x, lli y, lli p)   
{  
    lli res = 1;     // Initialize result  ! 
    x = x % p; // Update x if it is more than or  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
} 

int main()
{
	lli n;
	cin>>n;
	lli t=n/500;n=n%500;
	lli ani=t*1000;
	t=n/5;ani+=t*5;
	cout<<ani;
	
	
	
	
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  pair<pair<string, int>, int> data[N];
  string S;
  int p;
  
  for (int i = 0; i < N; i++){
    cin >> S >> p;
    
    data[i] = make_pair(make_pair(S,-1*p),i);
  }
  
  sort(data,data+N);
  
  for (int i = 0; i < N; i++){
    cout << data[i].second+1 <<endl;
  }
}

Measured memory_bytes: 256
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(), x.end()
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int n;
ll mi = 1000005, mx = -1000005, idmi = -1, idmx = -1;
vector<ll> a;
vector<P> ans;
void solve()
{
    if (mi >= 0 && mx >= 0)
    {
        cout << n - 1 << endl;
        for (int i = 1; i <= n - 1; i++)
            cout << i << " " << i + 1 << endl;
    }
    else if (mi <= 0 && mx <= 0)
    {
        cout << n - 1 << endl;
        for (int i = n - 1; i >= 1; i--)
            cout << i + 1 << " " << i << endl;
    }
    else
    {
        if (mx >= -mi)
        {
            rep(i, n)
            {
                if (a[i] < 0)
                    ans.emplace_back(idmx, i + 1);
            }
            for (int i = 1; i <= n - 1; i++)
                ans.emplace_back(i, i + 1);
        }
        else
        {
            rep(i, n)
            {
                if (a[i] > 0)
                    ans.emplace_back(idmi, i + 1);
            }
            for (int i = n - 1; i >= 1; i--)
                ans.emplace_back(i+1, i);
        }
        cout<<ans.size()<<endl;
        rep(i,ans.size()){
            cout<<ans[i].first<<" "<<ans[i].second<<endl;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    a.resize(n);
    rep(i, n)
    {
        cin >> a[i];
        if (mx < a[i])
        {
            mx = a[i];
            idmx = i + 1;
        }
        if (mi > a[i])
        {
            mi = a[i];
            idmi = i + 1;
        }
    }
    solve();
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  rep(i,9){
    rep(j,9){
      if(i*j==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
now = int(input())
ans = 0
if now == 1:
    ans = 4
elif now == 2:
    ans = 4
else:
    for i in range(1000000):
        if now == 4:
            ans = i + 4
            break
        if now % 2 == 0:
            now = now // 2
        else:
            now = 3 * now + 1
print(ans)

Measured memory_bytes: 3060