akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
a = ['x'*(w+2)]
for i in range(h):
  a.append('x'+input()+'x')
a.append('x'*(w+2))
for i in range(1,h+1):
  for j in range(1,w+1):
    count = 0
    if a[i][j] == '.':
      if a[i-1][j-1] == '#':
        count += 1
      if a[i-1][j] == '#':
        count += 1
      if a[i-1][j+1] == '#':
        count += 1
      if a[i][j-1] == '#':
        count += 1
      if a[i][j+1] == '#':
        count += 1
      if a[i+1][j-1] == '#':
        count += 1
      if a[i+1][j+1] == '#':
        count += 1
      if a[i+1][j] == '#':
        count += 1
      a[i]=a[i].replace('.',str(count),1)
for i in a:
  if i == '':
    pass
  else:
    i = i.replace('x','')
    i = i.strip()
    print(i)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void){
    ll N,T;cin>>N>>T;
    ll result = 0;
    ll t[N+1];
    t[0] = 0;
    for (int i = 1; i <= N; i++) cin>>t[i];
    for (int i = 1; i <= N; i++) {
        result += min(t[i] - t[i-1], T);
    }
    // T[N]押したあとを考慮
    result += T;
    cout << result << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

void dfs(vector<bool> &vs, vector<vector<ll>> &edges, ll &count, ll index) {
    count++;
    vs[index] = true;
    iter(i, edges[index]) {
        if(!vs[i]) dfs(vs, edges, count, i);
    }
}

int main(void) {
    ll N, M;
    ll ans = 0;
    cin >> N >> M;
    vector<pair<ll, ll>> edges;
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        edges.emplace_back(a, b);
    }
    rep(i, M) {
        ll count = 0;
        vector<bool> vs(M);
        vector<vector<ll>> ed(N);
        rep(j, M) {
            if(i == j) continue;
            ed[edges[j].first].push_back(edges[j].second);
            ed[edges[j].second].push_back(edges[j].first);
        }
        dfs(vs, ed, count, 0);
        if(count != N) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
const int maxn=1;

inline char gc(){
	return getchar();
	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
    ll x=0;char c=gc();bool neg=0;
    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    return neg?(~x+1):x;
}

int N,M,x,y;

int main(){
    //freopen("","r",stdin);
    N=rd(),M=rd(),x=rd(),y=rd();
    printf("%.6lf ",(double)N*M/2);
    if(x*2==N&&y*2==M) printf("1\n");
    else printf("0\n");
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def mod_combination(n, k, mod = 10 ** 9 + 7):
    def extended_gcd(a, b):
        if b == 0:
            return (a, 1, 0)
        d, x, y = extended_gcd(b, a % b)
        return (d, y, x - (a // b) * y)
    p, q = 1, 1
    for i in range(n - k + 1, n + 1):
        p = (p * i) % mod
    for i in range(2, k + 1):
        q = (q * i) % mod
    return p * (extended_gcd(q, mod)[1] % mod) % mod

def main():
  x, y = na()
  if (x + y) % 3 != 0 or x * 2 < y or y * 2 < x:
    print(0)
    return
  n = (x + y) // 3
  print(mod_combination(n, y - n))
 

if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n, a[100001], b[100001], d[100001];

int main(void)
{
    lin sa = 0, sb = 0;

    cin >> n;
    rep(i,n)
    {
        cin >> a[i];
        sa += a[i];
    }
    rep(i,n)
    {
        cin >> b[i];
        sb += b[i];
    }

    if(sb > sa)
    {
        cout << -1 << endl;
        return 0;
    }

    rep(i,n)
    {
        d[i] = a[i] - b[i];
    }

    sort(d, d+n);

    lin res = 0;
    lin ds = 0;
    rep(i,n)
    {
        if(d[i] >= 0)
            break;

        res++;
        ds += d[i];
    }

    for(int i = n-1; i >= 0; i--)
    {
        if(ds >= 0)
            break;

        res++;
        ds += d[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2560
from collections import Counter

def dfs(r, c, g, color):
    s = [r]
    color[r] = c
    while len(s) != 0:
        u = s.pop()
        for i in range(len(g[u])):
            v = g[u][i]
            if color[v] is None:
                color[v] = c
                s.append(v)


def assignColor(n, g, color):
    color_id = 1
    for u in range(n):
        if color[u] is None:
            dfs(u, color_id, g, color)
            color_id += 1


N, K, L = [int(v) for v in input().split()]
road = [[] for i in range(N)]
train = [[] for i in range(N)]
for i in range(K):
    p, q = [int(v) - 1 for v in input().split()]
    road[p].append(q)
    road[q].append(p)
for i in range(L):
    r, s = [int(v) - 1 for v in input().split()]
    train[r].append(s)
    train[s].append(r)

road_color = [None] * N
train_color = [None] * N
assignColor(N, road, road_color)
assignColor(N, train, train_color)

color_pairs = [(c1, c2) for c1, c2 in zip(road_color, train_color)]
pairs_cnt = Counter(color_pairs)
ans = [str(pairs_cnt[p]) for p in color_pairs]

print(' '.join(ans))


Measured memory_bytes: 98916
import java.util.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;
	
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0; i < n; ++i)
			a[i] = Integer.parseInt(sc.next());
		sc.close();
		int cnt = bubbleSort(a);
		printArray(a);
		System.out.println(cnt);
	}
	
	public static void printArray(int[] a){
		int n = a.length;
		for(int i = 0; i < n; ++i){
			if(i != 0) System.out.print(" ");
			System.out.print(a[i]);
		}
		System.out.println();
	}
	
	public static int bubbleSort(int[] a){
		int n = a.length, ret = 0;
		boolean flag = true;
		for(int i = 0; flag && (i < n); ++i){
			flag = false;
			for(int j = n-1; j > i; --j){
				if(a[j-1] > a[j]){
					{//swap(a[j-1], a[j]の代わり
						a[j-1] ^= a[j];
						a[j] ^= a[j-1];
						a[j-1] ^= a[j];
					}
					flag = true; ++ret;
				}
			}
		}
		return ret;
	}
}



Measured memory_bytes: 26328
#include <iostream>
#include <string>

using namespace std;

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

  return 0;
}



Measured memory_bytes: 3084
s = input()
flg_A, flg_Z = 1, 1
N = len(s)
for i in range(N):
    if flg_A:
        if s[i] == 'A':
            idx_A = i
            flg_A = 0
    if flg_Z:
        if s[N-1-i] == 'Z':
            idx_Z = N-1-i
            flg_Z = 0

print(idx_Z - idx_A + 1)


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
    int a, b, c; cin >> a >> b >> c;
    cout << (a == b && b == c ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int result = 0;
        for(int i = 0; i < N; i++){
            int a = sc.nextInt();
            while(a % 2 == 0){
                result++;
                a /= 2;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 34284
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long N;
    cin>>N;
    vector<long> a(N);
    for(int i=0;i<N;i++) cin>>a.at(i);
    
    long ans1=0,ans2=0,sum1=0,sum2=0;
    long x=0;
    for(int i=0;i<N;i++){
        if(i%2==0){
            if(sum1+a.at(i)>0) {
                sum1+=a.at(i);
                x=a.at(i);
            }
            else {
                ans1+=(1-sum1-a.at(i));
                x=a.at(i)+(1-sum1-a.at(i));
                sum1=1;
            }
        }else{
            if(sum1+a.at(i)<0) {
                sum1+=a.at(i);
                x=a.at(i);
            }
            else {
                ans1+=(sum1+a.at(i)-(-1));
                x=a.at(i)-(sum1+a.at(i)-(-1));
                sum1=-1;
            }
        }
      // cout<<x<<" ";
    }
    
    for(int i=0;i<N;i++){
        if(i%2!=0){
            if(sum2+a.at(i)>0) sum2+=a.at(i);
            else {
                ans2+=(1-sum2-a.at(i));
                sum2=1;
            }
        }else{
            if(sum2+a.at(i)<0) sum2+=a.at(i);
            else {
                ans2+=(sum2+a.at(i)-(-1));
                sum2=-1;
            }
        }
        //cout<<ans2<<endl;
    }
    
   cout<<min(ans1,ans2)<<endl;
}

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

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

int main() {
  int a,b,c;
  int h=0, t=0;
  while(scanf("%d,%d,%d",&a,&b,&c)==3) {
    if (a==b) h++;
    if (a*a+b*b==c*c) t++;
  }
  printf("%d\n%d\n",t,h);
}

Measured memory_bytes: 0
from collections import deque
n = int(input())
lun = deque([i for i in range(1, 10)])
cnt = 0
while cnt < n:
    cnt += 1
    a = lun.popleft()
    if a % 10 != 0:
        lun.append(10*a + a % 10 - 1)
    lun.append(10*a + a % 10)
    if a % 10 != 9:
        lun.append(10*a + a % 10 + 1)
print(a)


Measured memory_bytes: 40816
from itertools import *
n=104730;a=list(range(n));a[:2]=0,0
for i in range(2,323):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(range(n),a))
print('\n'.join(str(sum(p[:int(e)]))for e in iter(input,'0')))


Measured memory_bytes: 10468
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s =  sc.next();
		String[] w = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
		for(int i = 0 ; i < 7 ; i++) {
			if(s.equals(w[i])) {
				System.out.println(7 - i);
			}
		}
		
    
    }
}

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

long long gcd(long long a, long long b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

int main()
{
    long long a,b;
    cin>>a>>b;

    long long k=gcd(a,b);

    vector<long long>v;

    for(int i=2;i<=sqrt(k);i++)
    {
        if(k%i==0)
        {
            v.push_back(i);
            while(k%i==0)
            {
                k/=i;
            }
        }
    }

    if(k>2)
    {
        v.push_back(k);
    }

    cout<<v.size()+1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

int x, y, z, K;
ll a[1010], b[1010], c[1010];
vector<ll> v;

int main() {
    cin >> x >> y >> z >> K;
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(a, a+x, greater<ll>());
    sort(b, b+y, greater<ll>());
    sort(c, c+z, greater<ll>());

    rep(i, x) {
        rep(j, y) {
            rep(k, z) {
                if ((i+1)*(j+1)*(k+1) <= K) v.push_back(a[i]+b[j]+c[k]);
            }
        }
    }

    sort(v.begin(), v.end(), greater<ll>());
    rep(i, K) cout << v[i] << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using Tuple = tuple<int, int, int>;

ll modnum = 1e9+7;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    vector<ll> count(k+10, 0);
    for(ll i=k; i > 0; i--) {
        ll num = k/i;
        ll tmp = modpow(num, n, modnum);
        count[i] = tmp;
        ll ii = i*2;
        while(ii <= k) {
            count[i] -= count[ii];
            ii += i;
        }
    }

    EFOR(i,1, k) {
        ans += i*count[i]%modnum;
        ans %= modnum;
    }

    cout << ans << endl;
    return 0;
}

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

int ruijou(int);

main(){
  int m, n, player[1001], s, i, j, p;

  while(1){
    scanf("%d %d", &m, &n);
    if(m==0 && n==0) break;
    getchar();

    for(i=0;i<=m;i++) player[i]=0;
    
    queue<int> member;
    for(i=1;i<=m;i++) member.push(i);

    for(j=1;j<=n;j++){
      if(member.size()<=1){
	string a;
	getline(cin,a);
      }
      else{
	p=member.front(),member.pop();
	int f=1;
	string temp;
	getline(cin,temp);
	i=temp.size();
	
	if(i==4 && temp=="Fizz"){
	  if(j%3==0 && j%5!=0) f=0;
	}
	else if(i==4 && temp=="Buzz"){
	  if(j%5==0 && j%3!=0) f=0;
	}
	else if(i==8 && temp=="FizzBuzz"){
	  if(j%3==0 && j%5==0) f=0;
	}
	else{
	  int flag=0;
	  for(int count=0;count<i;count++){
	    if(temp[count]<'0' || temp[count]>'9'){
	      flag=1;
	      break;
	    }
	  }
	  if(flag==0){
	    s=0;
	    for(int count=0;count<i;count++){
	      s+=(temp[count]-'0')*ruijou(i-count-1);
	    }
	    if(j%3!=0 && j%5!=0 && j==s){
	      f=0;
	    }
	  }
	}
	if(f==0) member.push(p);
	else player[p]=1;
      }
    }
 
    for(i=1;i<=m;i++){
      if(player[i]==0){
	printf("%d", i);
	break;
      }
    }
    for(j=i+1;j<=m;j++){
      if(player[j]==0){
	printf(" %d", j);
      }
    }
    printf("\n");
  }
  return 0;
}

int ruijou(int a){
  int sum=1;
  for(int i=0;i<a;i++){
    sum*=10;
  }
  return sum;
}

Measured memory_bytes: 980
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
int N;
int field = 0;
const int CARDS = 100;
const int MAX_PLAYERS = 10;
vector<int> Hand(MAX_PLAYERS);
vector<char> Draw(CARDS);
while (1) {
field = 0;
cin >> N;
if(N == 0) {
break;
}
Hand.clear();
Draw.clear();
vector<int>::iterator HandI = Hand.begin();
vector<char>::iterator DrawI = Draw.begin();
for(int i = 0; i < CARDS; i++) {
char card;
cin >> card;
Draw.push_back(card);
}
for (int i = 0; i < N; i++) {
Hand.push_back(0);
}
for (DrawI = Draw.begin(); DrawI != Draw.end(); ++DrawI) {
if (*DrawI == 'S') {
++*HandI;
field += *HandI;
*HandI = 0;
}
else if (*DrawI == 'L') {
++*HandI;
*HandI += field;
field = 0;
}
else {
++*HandI;
}
++HandI;
if(HandI == Hand.end()) {
HandI = Hand.begin();
}
}
sort (Hand.begin(), Hand.end());
for (HandI = Hand.begin(); HandI != Hand.end(); ++HandI) {
cout << *HandI << " ";
}
cout << field <<"\n";
}
return 0;
}

Measured memory_bytes: 1216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Handsel
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int a, b;
		a = parseInt(line.substring(0, line.indexOf(' ')));
		b = parseInt(line.substring(line.indexOf(' ') + 1));

		System.out.println((a + b) / 2);
	}
}

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

using namespace std;

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

    vector<int> a(n);

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

    long long ans = 0;

    long long r = 0;
    int s = 0;
    for(int l = 0; l < n; l++) {
        while(r < n && (s & a[r]) == 0) {
            s ^= a[r];
            r++;
        }

        ans += r - l;

        s ^= a[l];
    }

    cout << ans << endl;
}

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

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

using ll = long long;

ll pow(ll x, ll y) {
    if (y == 0LL) return 1LL;
    ll X = 1LL;
    for (ll i = 0LL; i < y; i++) {
      X *= x;
      X %= 2019;
    }
    return X;
}

ll dp[200100];
ll dpp[2100];

int main() {
  string S;
  cin >> S;
  ll l = S.size();
  ll f = S.at(0) - '0';
  dp[l+1] = 0LL;
  dpp[0] = 1LL;
  ll s = 10LL;
  for(ll i = l; i >=1; i--) {
    ll t = S.at(i-1) - '0';
    dp[i] = (dp[i+1] + t*s)%2019LL;
    s *= 10LL;
    s %= 2019LL;
    dpp[dp[i]]++;
  }
  ll ans = 0LL;
  for(ll i = 0; i < 2100; i++) {
    ans += dpp[i] * (dpp[i] -1) /2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5340
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x,sum;
    cin>>x>>a>>b;
    sum=x+a;
    if(b>sum)
        cout<<"dangerous"<<endl;
    else
    {
        if(sum>=b&&x>b)
            cout<<"delicious"<<endl;
        else
            cout<<"safe"<<endl;
    }
}

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

namespace ConsoleApp1 {
    class Program {
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            int H = int.Parse(input[0]);  //数値で受け取りたい場合は変換する
            int W = int.Parse(input[1]);
            string[] mapStr = new string[H];
            for (int i = 0; i < H; i++) {
                mapStr[i] = Console.ReadLine();
            }
            int[,] shortRouteMap = new int[H, W];
            int blackNum = 0;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    shortRouteMap[i, j] = -1;
                    if (mapStr[i].Substring(j, 1) == "#") {
                        blackNum++;
                    }
                }
            }
            shortRouteMap[0, 0] = 0;
            for (int i = 0; i < H * W; i++) {
                for (int j = 0; j < H; j++) {
                    for (int h = 0; h < W; h++) {
                        int num = shortRouteMap[j, h];
                        if (num < 0 && mapStr[j].Substring(h, 1) == ".") {
                            int mawariMin = 100000;
                            if (j > 0) {
                                if (shortRouteMap[j - 1, h] >= 0 && shortRouteMap[j - 1, h] < mawariMin) {
                                    mawariMin = shortRouteMap[j - 1, h];
                                }
                            }
                            if (j < H - 1) {
                                if (shortRouteMap[j + 1, h] >= 0 && shortRouteMap[j + 1, h] < mawariMin) {
                                    mawariMin = shortRouteMap[j + 1, h];
                                }
                            }
                            if (h > 0) {
                                if (shortRouteMap[j, h - 1] >= 0 && shortRouteMap[j, h - 1] < mawariMin) {
                                    mawariMin = shortRouteMap[j, h - 1];
                                }
                            }
                            if (h < W - 1) {
                                if (shortRouteMap[j, h + 1] >= 0 && shortRouteMap[j, h + 1] < mawariMin) {
                                    mawariMin = shortRouteMap[j, h + 1];
                                }
                            }
                            if (mawariMin != 100000) {
                                shortRouteMap[j, h] = mawariMin + 1;
                            }
                        }
                    }
                }
            }
            int answer = -1;
            if (shortRouteMap[H - 1, W - 1] > 0) {
                answer = H * W - (shortRouteMap[H - 1, W - 1] + 1) - blackNum;
            }
            // Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
            Console.WriteLine(answer.ToString());
        }
    }
}

Measured memory_bytes: 15276
#include<stdio.h>
#include<iostream>
#include<stack>
#include<algorithm>
#define MAX 1400
 
using namespace std;
 
struct Rectangle{int height; int pos;};
 
int getLargestRectangle(int size, int buffer[]){
    stack<Rectangle> S;
    int maxv = 0;
    buffer[size] = 0;
 
    for(int i = 0; i <= size; i++){
        Rectangle rect;
        rect.height = buffer[i];
        rect.pos = i;
        if(S.empty()){
            S.push(rect);
        }else{
            if(S.top().height < rect.height){
                S.push(rect);
            }else if(S.top().height > rect.height){
                int target = i;
                while(!S.empty() && S.top().height >= rect.height){
                    Rectangle pre = S.top(); S.pop();
                    int area = pre.height * (i - pre.pos);
                    maxv= max(maxv, area);
                    target = pre.pos;
                }
                rect.pos = target;
                S.push(rect);
            }
        }
    }
    return maxv;
}
 
int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];
 
int getLargestRectangle(){
    for(int j = 0; j < W; j++){
        for(int i = 0; i < H; i++){
            if(buffer[i][j]){
                T[i][j] = 0;
            }else{
                T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
            }
        }
    }
 
    int maxv = 0;
    for(int i = 0; i < H; i++){
        maxv = max(maxv, getLargestRectangle(W, T[i]));
    }
 
    return maxv;
}
 
int main(){
    scanf("%d %d", &H, &W);
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            scanf("%d", &buffer[i][j]);
        }
    }
    cout << getLargestRectangle() << endl;
 
    return 0;
}


Measured memory_bytes: 18436
#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(){

int k;
cin >> k;
vector<ll> a;
for (int i = 1; i <= 9; i++){
    a.push_back(i);
}

while(1){
    if(k<=a.size()){
        cout << a[k-1] << endl;
        return 0;
    }
    k -= a.size();
    vector<ll> old;
    swap(old, a);
    for(ll x: old){
        for(int i=-1; i<=1; i++){
            int d=x%10+i;
            if(d<0 || d>9) continue;
            ll nx=10*x+d;
            a.push_back(nx);
        }
    }
}



}

Measured memory_bytes: 1712
#include<stdio.h>
int main()
{
    int a,b,c,count=1;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        c=a+b;
        while(c>=10)
        {
            c=c/10;
            count++;
        }
        printf("%d\n",count);
        count=1;
    }
    return 0;
}



Measured memory_bytes: 2036
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
sN = str(N)

if '7' in sN:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9476
#include<bits/stdc++.h>
#define F(a,b,c,d) for (register int a=b;a<=c;a+=d)
#define FD(a,b,c,d) for (register int a=b;a>=c;a-=d)
using namespace std;
int d[1000],f[100100],cnt=1;
int main(){
	int n,m;
	cin>>n;
	d[1]=1;
	for (int i=6;i<=n;i*=6)
	{
		cnt++;
		d[cnt]=i;
	}
	for (int i=9;i<=n;i*=9)
	{
		cnt++;
		d[cnt]=i;
	}
	memset(f,1,sizeof(f));
	f[0]=0;
	for (int i=1;i<=cnt;i++)
	{
		for (int j=d[i];j<=n;j++)
		{
			f[j]=min(f[j],f[j-d[i]]+1);
		}
	}
	cout<<f[n]<<endl;
	return 0;
}



Measured memory_bytes: 640
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

int mat[4][4];
int flag = 0;
int a[4];
int b[4];

int main()
{
	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			scanf("%d", &mat[i][j]);
		}
	}

	for(int i = -1000; i <= 1000; i++)
	{
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		a[0] = i;
		b[0] = mat[0][0] - a[0];
		b[1] = mat[0][1] - a[0];
		b[2] = mat[0][2] - a[0];
		a[1] = mat[1][0] - b[0];
		a[2] = mat[2][0] - b[0];
	
		flag = 0;
		if(a[1] + b[1] != mat[1][1])
		{
			flag = 1;
		}
		if(a[2] + b[2] != mat[2][2])
		{
			flag = 1;
		}
		if(a[1] + b[2] != mat[1][2])
		{
			flag = 1;
		}
		if(a[2] + b[1] != mat[2][1])
		{
			flag = 1;
		}

		if(!flag)
		{
			printf("Yes\n");
			return 0;
		}
	}
	
	printf("No\n");
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<string,int>P;
typedef vector<P>V;
int main(void){
	int n,m;
	string s[101],t[101];
	V v1,v2;
	int flg[101];
	int i,j;
	int cnt;
	int MAX;
	cin>>n;
	for(i=0;i<n;i++)	cin>>s[i];
	cin>>m;
	for(i=0;i<m;i++)	cin>>t[i];
	for(i=0;i<n;i++)	flg[i]=0;
	for(i=0;i<n-1;i++){
		cnt=0;
		if(flg[i]==0){
			for(j=i+1;j<n;j++){
				if(flg[j]==0){
					if(s[i]==s[j]){
						cnt++;
						flg[j]=1;
					}
				}
			}
			v1.push_back(P(s[i],cnt+1));
		}
	}
	if(flg[n-1]==0)	v1.push_back(P(s[n-1],1));
	//cout<<endl;
	// for(i=0;i<(int)v1.size();i++)	cout<<v1[i].F<<" "<<v1[i].S<<endl;	cout<<endl;
	for(i=0;i<m;i++)	flg[i]=0;
	for(i=0;i<m-1;i++){
		if(flg[i]==0){
			cnt=0;
			for(j=i+1;j<m;j++){
				if(flg[j]==0){
					if(t[i]==t[j]){
						cnt++;
						flg[j]=1;
					}
				}
			}
			v2.push_back(P(t[i],cnt+1));
		}
	}
	if(flg[m-1]==0)	v2.push_back(P(t[m-1],1));
	//for(i=0;i<(int)v2.size();i++)	cout<<v2[i].F<<" "<<v2[i].S<<endl;
	for(i=0;i<(int)v1.size();i++)	flg[i]=-1;
	for(i=0;i<(int)v1.size();i++){
		for(j=0;j<(int)v2.size();j++){
			if(v1[i].F==v2[j].F){
				flg[i]=j;
				break;
			}
		}
	}
	MAX=0;
	for(i=0;i<(int)v1.size();i++){
		if(flg[i]==-1){
			MAX=max(MAX,v1[i].S);
		}
		else{
			MAX=max(MAX,v1[i].S-v2[flg[i]].S);
		}
	}
	cout<<MAX<<endl;
	return 0;
}
		

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string c;
int n;

bool palindrom (string s) {
  for (int i = 0; i <= n / 2; i++)
    if (s[i] != s[n - i - 1])
      return false;
  return true;
}

bool palindromst (string s) {
  for (int i = 0; i <= ((n - 1) / 2) / 2; i++)
    if (s[i] != s[(n - 1) / 2 - i - 1])
      return false;
  return true;
}

bool palindromdr (string s) {
  for (int i = (n + 3) / 2 - 1, j = n - 1; i <= j; i++, j--)
    if (s[i] != s[j])
      return false;
  return true;
}
bool rezolva (string s) {
  if (not palindrom (s))
    return false;
  if (not palindromst (s))
    return false;
  if (not palindromdr (s))
    return false;
  return true;
}

int main()
{
  cin >> c;
  n = c.size ();
  if (rezolva (c))
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	string S, T, U;
	int A, B;
	cin >> S >> T >> A >> B >> U;

	if( U == S ) {
		A -= 1;
	}
	else if( U == T ) {
		B -= 1;
	}

	cout << A << ' ' << B << endl;

	return 0;
}


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


int main() {
    int n,x;
    cin >> n >> x;
    while (n!=0 || x!=0) {
        int c = 0;
        for (int i = 1; i <= n; i++){
            for (int j = i+1; j <= n; j++) {
                for (int k = j+1; k <= n; k++) {
                    if (i+j+k == x) c++;
                }
            }
        
        }
        cout << c << endl;
        cin >> n >> x;

    }
    return 0;

}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll n, m;
 	cin >> n >> m;
 	ll ans = 0;
 	if (n >= 2) {
 		ans = ans + ((n * (n - 1)) / 2);
 	}
 	if (m >= 2) {
 		ans = ans + ((m * (m - 1)) / 2);
 	}
 	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;

    string s;
    cin>>s;
    int len = s.size();
    for(int i=0;i<len;i++){
        char aaa =(char)(s.at(i)+n);
        if(aaa>='A'+26)
            aaa-=26;

        s.at(i)=aaa;
    }

    cout<<s<<endl;

    return 0;
}  




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}


int main()
{
	fast

	int n;
	cin>>n;

	vector<double> v(n);
	cout<<fixed<<setprecision(10);

	double sum = 0;

	forn(i,0,n)
	{
		cin>>v[i];

		sum += (double)1/v[i];
	}

	cout<<(double)1/sum;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define inf 1e9
typedef pair<int,int> pii;
typedef pair <long long,long long> pll;
typedef long long ll; 
typedef long double ld; 
const ll mod = 1e9+7;
struct flower{
	ll hi; ll bty;
};
ll solve(vector< flower > &v, int n )
{	vector <ll> dp(n+1);
	map <ll,ll> meaningful;
	dp[1] = v[1].bty;
	meaningful[v[1].hi] = dp[1];
	ll ans = dp[1];
	for(ll i = 2; i<=n ; i++)
	{
		dp[i] = v[i].bty;
		auto it = meaningful.lower_bound(v[i].hi + 1);
		if(it != meaningful.begin()){
			it--;
			dp[i] += it->se;
		}
		meaningful[v[i].hi] = dp[i];
		it = meaningful.upper_bound(v[i].hi);
		while(it != meaningful.end() && it->se <= dp[i] ){
			auto tmp = it;
			tmp++;
			meaningful.erase(it);
			it = tmp;
		}
		ans = max(ans,dp[i]);
	}
    return ans;
} 
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n; cin >> n;
	vector < flower > v(n+1);
	for(ll i = 1; i <= n; i++)
		cin >> v[i].hi;
	for(ll i = 1; i<= n; i++)
		cin >> v[i].bty;
	cout << solve( v , n );
	return 0;
}


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

const int N = 1e6 + 5;
typedef long long LL;

struct node {
	int val, low;
} a[N];
string s;
int tot, n, m, sum;

bool cmp1(node a, node b) {
	return a.val > b.val;
}

bool cmp2(node a, node b) {
	return a.low > b.low;
}

bool cmp3(node a, node b) {
	return -a.val + a.low < -b.val + b.low; 
}


int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		cin>>s;
		a[i].val = a[i].low = 0;
		for(int j = 0; j < (int) s.size(); j++) {
			if(s[j] == '(') tot++, a[i].val++;
			else tot--, a[i].val--;
			a[i].low = min(a[i].val, a[i].low);
		}
 	}
 	if(tot) {
 		cout<<"No"<<endl;
 		return 0;
 	} 
 	sort(a + 1, a + n + 1, cmp1);
 	for(int i = 1; i <= n; i++)
 		if(a[i].val <= 0) {
 			m = i - 1;
 			break;
 		}
 	sort(a + 1, a + m + 1, cmp2);
 	for(int i = 1; i <= m; i++) {
 		if(sum + a[i].low < 0) {
 			cout<<"No"<<endl;
 			return 0;
 		}
 		sum += a[i].val;
 	}
 	sort(a + m + 1, a + n + 1, cmp3);
 	 for(int i = m + 1; i <= n; i++) {
 		if(sum + a[i].low < 0) {
 			cout<<"No"<<endl;
 			return 0;
 		}
 		sum += a[i].val;
 	}
 	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 11368
#include "bits/stdc++.h"

using namespace std;

typedef long double db;
typedef long long ll;
typedef pair<db, db> pd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;


#define printlist(ans) for(auto x: ans) cout << x << ' '; cout << endl;
#define printstring(ans)  for(auto x: ans) cout << x; cout << endl;


#define mod 1000000007
#define maxn 100005

ll tst;
void cleanData();

ll n, m, k, a[maxn];

void solve() {
	cin >> n >> m;
	set<ll> st;
	for (ll i = 0; i < n; i++)
	{
		st.insert(i);
	}
	
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (ll i = 0; i < m; i++)
	{
		ll x, y;
		cin >> x >> y;
		x--, y--;
		if(a[x] <= a[y])
			st.erase(x);
		if(a[y] <= a[x])
			st.erase(y);
	}

	cout << st.size();
}

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

	tst = 1;
	//cin >> tst;
	while (tst--) {
		solve();
	}

    cout << endl << endl;
	return 0;
}

void cleanData() {}


Measured memory_bytes: 9128
/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7, MAXN = 1e5 + 10;

int n, c, k, a[MAXN], ans, j;

int main(){
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    ios_base::sync_with_stdio(0);
    cin >> n >> c >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i){
        j = i;
        while (j < n && a[j + 1] <= a[i] + k && j - i < c - 1)
          ++j;
        i = j;
        ++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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

	int ans = 1;
	for (int i = 1; i <= N; i*=2) {
		ans = i;
	}
	cout << ans << endl;
}


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

typedef long long ll;
#define MOD 1000000007

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    vector<vector<ll>> dp(h, vector<ll>(w, 0ll));
    for (int i = 0; i < h; i++)
        cin >> grid[i];
    dp[0][0] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == 0 && j == 0)
                continue;
            if (grid[i][j] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] =
                    ((i > 0 ? dp[i - 1][j] : 0) + (j > 0 ? dp[i][j - 1] : 0)) %
                    MOD;
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}

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

int main() {
  string s;
  set<char> sc;
  cin >> s;
  REP(i, s.length()) {
    if (sc.find(s[i]) != sc.end()) {
      cout << "no" << endl;
      return 0;
    }
    sc.insert(s[i]);
  }
  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int N;
	static int K;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		String S = sc.next();
		String[] s = S.split("");
		s[K-1] = s[K-1].toLowerCase();

		for (int i = 0; i < s.length; i++) {
			System.out.print(s[i]);
		}

	}
}

Measured memory_bytes: 22612
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;
static const int MOD = 10000007;
static const int MAX = 100005;


int N;
int P[MAX];
typedef struct orderp {
  int key;
  // int value;

  bool operator < ( const orderp& right ) const {
    return P[key] > P[right.key];
  }
} ord;


void printset(multiset<ord> st) {
  cout << st.size() << ":";
  for (multiset<ord>::iterator it = st.begin(); it != st.end(); it++) {
    cout << " " << (*it).key;
  }
  cout << " \n";
}
void printsetint(multiset<int> st) {
  cout << st.size() << ":";
  for (multiset<int>::iterator it = st.begin(); it != st.end(); it++) {
    cout << " " << (*it);
  }
  cout << " \n";
}


int main(){
  cin >> N;

  multiset<ord> kt;
  multiset<int> st;

  st.insert(-1);
  st.insert(-1);
  st.insert(N);
  st.insert(N);
  rep(i, N) {
    int p;
    cin >> p;
    P[i] = p;
  }
  rep(i, N) {
    kt.insert({i});
  }
  // printset(kt);
  lli ans = 0;
  for ( auto k : kt) {
    auto itr = st.lower_bound(k.key);
    lli idx1 = *itr;
    itr++;
    lli idx2 = *itr;
    itr--;
    itr--;
    lli idx3 = *itr;
    itr--;
    lli idx4 = *itr;
    // cout << k.key << " idx: " << idx1 << " " << idx2 << " " << idx3 << " " << idx4 << endl;
    ans += P[k.key]*(idx2 - idx1)*(k.key - idx3);
    ans += P[k.key]*(idx1 - k.key)*(idx3 - idx4);
    st.insert(k.key);
    // printsetint(st);
  }
  cout << ans << endl;

}


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

using namespace std;

const int mod = 1000000007;

int solve()
{
  int n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) return 0;
  long long res = 1;
  if (n == m) {
    for (int i = 1; i <= n; i++) {
      res *= i;
      res %= mod;
    }
    res *= res;
    res %= mod;
    res *= 2;
    res %= mod;
  } else {
     for (int i = 1; i <= n; i++) {
      res *= i;
      res %= mod;
    }
    for (int i = 1; i <= m; i++) {
      res *= i;
      res %= mod;
    }
  }
  return res;
}

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

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

int main() {
  int n, k;


  while(cin >> n >> k, n+k) {
    vector<int> s(k);
    int b;

    for(int i = 0; i < k; i++) {
      cin >> s[i];
    }

    for(int i = 0; i < n; i++) {
      for(int j = 0; j < k; j++) {
	cin >> b;
	s[j] -= b;
      }
    }

    bool ans = true;
    for(int i = 0; i < k; i++) {
      if(s[i] < 0) ans = false;
    }
    
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];
    ll res=1000;
    rep(i, n-1){
        res = max(res, res/a[i]*a[i+1]+res%a[i]);
    }
    cout << res << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
      //#define ll long long
      using namespace std;
      #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
      #define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
      #define ll long long
      #define pb push_back
      #define pll pair<ll,ll>
      #define ff first
      #define ss second
     
      #define N 2000001
      #define M 998244353
      #define INF 1000000000000000
int main()
{
 // SPEED;
 ll n;

 cin>>n;
  ll  a[n],p=0,i;
  
  for(i=0;i<n;i++)
  {
    cin>>a[i];p=p^a[i];
  }
  for(i=0;i<n;i++)
  {
    cout<<(p^a[i])<<" ";
  }
 

}

Measured memory_bytes: 5180
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=1e5+20;

char str[maxn];
int vis[maxn];
int n;

inline void init()
{
	scanf("%s",str+1);
	n=strlen(str+1);
	REP(i,1,n)vis[i]=str[i]-'0';
	REP(i,1,n)if(vis[i] && !vis[n-i])puts("-1"),exit(0);
	if(!vis[1])puts("-1"),exit(0);
}

int g[maxn],tot;

inline void doing()
{
	g[0]=1;
	int lst=0;
	REP(i,2,n/2)if(vis[i])
	{
		if(!lst)
		{
			++tot;lst=tot;
			REP(j,1,i-1)printf("%d %d\n",lst,++tot);
		}else
		{
			int now=++tot;
			printf("%d %d\n",now,lst);
			REP(j,tot+1,i)printf("%d %d\n",now,++tot);
			lst=now;
		}
	}
	int now=++tot;
	if(lst)printf("%d %d\n",now,lst);
	REP(j,tot,n-1)printf("%d %d\n",now,++tot);
}

int main()
{
	init();
	doing();
	return 0;
}



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



int main(){
	int n,W;
	cin>>n>>W;
	vector<int> w(n),v(n);
	int value=0;
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
		value+=v[i];
	}
	vector<long long int > dp(value+1,(1e18L+5));
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=value-v[i];j>=0;j--){
			//if(j>=v[i])
				dp[j+v[i]]=min(dp[j+v[i]],w[i]+dp[j]);
		}
	}
	int ans=0;
	for(int i=0;i<=value;i++){
		if(dp[i]<=W){
			ans=max(ans,i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024