akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

void tamesiwari(long long *p){
	p[0] = 2;
	int count = 1;
	for(int i = 3; i < 110000; i+=2){
		bool f = true;
		for(int j = 3; i >= j*j; j+=2){
			if(i%j == 0){
				f = false;
				break;
			}
		}
		if(f){
			p[count] = i;
			count++;
		}
		if(count == 10000)break;
	}
}

int main(){
	long long p[10000] = {0};
	tamesiwari(p);
	int n;
	while(cin >> n && n != 0){
		int sum = 0;
		for(int i = 0; i < n; i++){
			sum += p[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
N, M = map(int, input().split())
H = list(map(int, input().split()))
heighest = [0] * N
for i in range(M):
    a, b = map(int, input().split())
    heighest[a-1] = max(heighest[a-1], H[b-1])
    heighest[b-1] = max(heighest[b-1], H[a-1])

cnt = 0

for i, j  in zip(heighest, H):
    if i < j:
        cnt += 1
print(cnt)


Measured memory_bytes: 20044
#include <stdio.h>
#include <string.h>

int main(){
	char chp[257], str[257];
	int  n, i, len, a, b;
	
	scanf("%d ", &n);
	
	while(n--){
	    for(a = 0; a < 257; a++) str[a] = 0;
	
	    fgets(chp, sizeof(chp), stdin);
	    
	    len = strlen(chp);
	    
	    for(a = 1; a < 26; a += 2)
	        for(b = 0; b < 26; b++)
	            if(strstr(str, "this") == NULL &&
	               strstr(str, "that") == NULL)
	                for(i = 0; i < len; i++)
	                    if(chp[i] >= 'a' && chp[i] <= 'z')
	                        str[i] = ((a * (chp[i] - 'a') + b) % 26) + 'a';
	                    else
	                        str[i] = chp[i];
	    
	    printf("%s", str);
	}
	
	return 0;
}

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


int main (void){

    string  s;
    cin >> s;
    string tmp1 = s, tmp2 = s;

    int n = s.size();
    int count1=0, count2=0;

    for (int i = 0; i < n-1;i++){
        if(s[i+1]==tmp1[i]){
            count1++;
            if(s[i+1]=='1'){
                tmp1[i + 1] = '0';
            }
            else{
                tmp1[i + 1] = '1';
            }
        }
    }
    for (int i = n - 1; i > 0; i--){
        if (s[i-1] == tmp2[i])
        {
            count2++;
            if (s[i-1] == '1')
            {
                tmp2[i - 1] = '0';
            }
            else
            {
                tmp2[i - 1] = '1';
            }
        }
    }

    cout << min(count1, count2) << endl;
    return 0;
}

Measured memory_bytes: 512
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

flag_plus = False
flag_minus = False
plus_list = []
minus_list = []
zero_list = []
for i in A:
	if i < 0:
		flag_minus = True
		minus_list.append(i)
	elif i > 0:
		flag_plus = True
		plus_list.append(i)
	else:
		zero_list.append(0)

# print(plus_list)
# print(minus_list)
if flag_plus and flag_minus:  # 正も負もある
	print(sum([abs(x) for x in A]))
	tmp1 = minus_list.pop(0)
	tmp2 = plus_list.pop(0)
	if plus_list:
		print(tmp1, plus_list[0])
		tmp1 = tmp1 - plus_list[0]  # tmp1 はマイナスの集約
		for i in range(1, len(plus_list)):  # マイナスにひく
			print(tmp1, plus_list[i])
			tmp1 = tmp1 - plus_list[i]

	if minus_list:
		print(tmp2, minus_list[0])
		tmp2 = tmp2 - minus_list[0]  # tmp2は プラスの集約
		for i in range(1, len(minus_list)):
			print(tmp2, minus_list[i])
			tmp2 = tmp2 - minus_list[i]
	for i in range(len(zero_list)):
		print(tmp2, 0)
	print(tmp2, tmp1)


elif flag_plus and (not flag_minus):  # 正のみ
	A_min = min(A)
	print(sum(A)-2*A_min)
	A.remove(A_min)
	print(A_min, A[0])
	tmp = A_min - A[0]
	for i in range(1, N-1):
		if i != N-2:
			print(tmp, A[i])
			tmp = tmp - A[i]
		else:
			print(A[i], tmp)
elif (not flag_plus) and flag_minus:  # 負のみ
	A_max = max(A)
	print(sum([abs(x) for x in A])+2*A_max)
	A.remove(A_max)
	print(A_max, A[0])
	tmp = A_max - A[0]
	for i in range(1, N-1):
		print(tmp, A[i])
		tmp = tmp-A[i]
else:  # 正も負もなし(全部0)
	print(0)
	for i in range(N-1):
		print(0, 0)


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll H, W;
    ll cost[101][101];
    for(i = 0; i < 101; i++) {
        for(j = 0; j < 101; j++)
            cost[i][j] = INF;
    }
    cin >> H >> W;
    string s[H];
    for(i = 0; i < H; i++) {
        cin >> s[i];
    }
    bool ch = 0;
    if(s[0][0] == '#') {
        ch = 1;
        cost[0][0] = 1;
    } else {
        cost[0][0] = 0;
    }
    for(i = 0; i < H; i++) {
        for(j = 0; j < W; j++) {
            if(i > 0) {
                if(s[i][j] == s[i - 1][j]) {
                    cost[i][j] = min(cost[i][j], cost[i - 1][j]);
                } else if(s[i - 1][j] == '#') {
                    cost[i][j] = min(cost[i][j], cost[i - 1][j]);
                } else {
                    cost[i][j] = min(cost[i][j], cost[i - 1][j] + 1);
                }
            }
            if(j > 0) {
                if(s[i][j] == s[i][j - 1]) {
                    cost[i][j] = min(cost[i][j], cost[i][j - 1]);
                } else if(s[i][j - 1] == '#') {
                    cost[i][j] = min(cost[i][j], cost[i][j - 1]);
                } else {
                    cost[i][j] = min(cost[i][j], cost[i][j - 1] + 1);
                }
            }
        }
    }
    cout << cost[H - 1][W - 1] << endl;
    /*for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cout << cost[i][j];
        }
        cout << endl;
    }*/
    return 0;
}

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

vector<ll> dis(1e5,-1);
vector<map<ll,ll>> box(1e5);

void dfs(ll v, ll d) {
  dis[v]=d%2;
  for(auto p: box[v]) {
    if(dis[p.first]<0) dfs(p.first, p.second+d);
  }
}

int main() {
  ll zero=0;
  ll n;
  cin >> n;
  for(int i=0;i<n-1;i++) {
    ll u,v,w;
    cin >> u >> v >> w;
    u--;
    v--;
    box[u][v]=w%2;
    box[v][u]=w%2;
  }
  dfs(0,1);
  for(ll i=0;i<n;i++) {
    cout << dis[i] << endl;
  }
}

Measured memory_bytes: 19840
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const n = s[0];
  const m = s[1];

  const ans = (n - 1) * (m - 1);

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  ll a;double b;cin>>a>>b;
  ll c=b*100+0.5;
  ll ans=a*c/100;
  cout<<ans<<endl;
}

Measured memory_bytes: 3724
def read_input():
    a, b = input().split()
    return a, b

def submit():
    a, b = read_input()

    if a == 'H':
        if b == 'H':
            print('H')
        else:
            print('D')
    else:
        if b == 'H':
            print('D')
        else:
            print('H')


if __name__ == '__main__':
    submit()


Measured memory_bytes: 38256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long x = sc.nextLong();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    long ans = 0;
    for(int i = 1; i < n; i++) {
      if(a[i - 1] <= x) {
        ans += Math.max(0, (a[i - 1] + a[i] - x));
        a[i] -= Math.max(0, (a[i - 1] + a[i] - x));
      } else {
        ans += Math.max(0, (a[i - 1] + a[i] - x));
        a[i] = 0;
      }
    }
    System.out.println(ans);
  }
}

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

int main(void){
    string S, T;
    cin >> S >> T;

    ll ans = 0;
    int size = S.length();
    rep(i, size){
        if (S[i] != T[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3864
#include<stdio.h>
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i, j;
	int a[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int b[200005];
	for (; k > 0; k--)
	{
		j = 0;
		for (i = 0; i < n; i++)
			if (a[i] < n)
				j++;
		if (j == 0)
			break;
		for (i = 0; i < n; i++)
			b[i] = 0;
		for (i = 0; i < n; i++)
		{
			if (i - a[i] >= 0)
				b[i - a[i]]++;
			else
				b[0]++;
			if (a[i] + i + 1 < n)
				b[a[i] + i + 1]--;
		}
		a[0] = b[0];
		for (i = 0; i < n - 1; i++)
			a[i + 1] = b[i + 1] + a[i];
	}
	for (i = 0; i < n - 1; i++)
		printf("%d ", a[i]);
	printf("%d\n", a[n - 1]);
	return 0;
}

Measured memory_bytes: 3292
int main(void)
{
	int n, k;
	char s[51];

    scanf("%d %d", &n, &k);
	scanf("%s", s);
	s[n] = '\0';
	s[k-1] = s[k-1] -  'A' + 'a';

	printf("%s \n", s);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;


long long pow5(int x){
  long long ret = 1;
  for(int i = 0; i < 5; i++){
    ret *= x;
  }
  return ret;
}

int main(){

  int X;
  cin >> X;
  
  for(int i = -1000; i <=1000; i++){
    for(int j = -1000; j <= 1000; j++){
      long long val = pow5(i) - pow5(j);
      if(val == X){
	cout << i << " " << j << endl;
	return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3568
//sieu nhan
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inp "test.inp"
#define out "test.out"
#define oo 100005
#define inf 1e15
#define mod 1000000007
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define y1 hungdzno1
int n,k;
string s;
void nhap(){
  cin>>n>>k>>s;
}
void xuly(){
  s[k-1]=s[k-1]+32;
  cout<<s;
}
main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //freopen(inp,"r",stdin);
  //freopen(out,"w",stdout);
  nhap();
  xuly();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll v[e];

//beginner 1999 129
/// count : 4
int n, k;
ll ans = -1e18;

void solve(int l, int r)
{
    vector<ll>cur;
    for(int i=1; i<=l; i++){
        cur.pb(v[i]);
    }
    for(int i=r; i<=n; i++){
        cur.pb(v[i]);
    }
    ll can = k - 1LL*cur.size();
    if(can < 0) return ;
    ll sum = 0;
    sort(cur.begin(), cur.end());
    for(int i=0; i<cur.size(); i++){
        if(can > 0 && cur[i] < 0){
            can --;
        }
        else{
            sum += cur[i];
        }
    }
    if(sum > ans){
        ans = sum;
        //cout << l <<" "<<r<<"\n";
    }
    return ;
}

int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> v[i];
    }
    for(int i=0; i<=n; i++){
        for(int j=i+1; j<=n+1; j++){
            solve(i, j);
        }
    }
    //solve(3, n)
    cout << ans;
}


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

using namespace std;
using ll = long long;

#define FOR(i,m,n) for(ll (i)=(m); (i)<(ll)(n); ++(i))
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin,(a).end

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n, k; cin >> n >> k;
  vector<bool> a(n, false);
  REP(i,k){
    ll d; cin >> d;
    REP(j, d){
      ll b; cin >> b;
      a[b-1] = true;
    }
  }
  ll cnt = 0;
  for(auto x : a){
    if(!x) ++cnt;
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3648
//2718 佐々木 稜平 問3
import java.util.Scanner;
public class Main{
   
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        for(int cnt=0;cnt<N;cnt++){
            int x =sc.nextInt();
            int y =sc.nextInt();
            int b =sc.nextInt();
            int p =sc.nextInt();
            int gokei = x*b+y*p;
            if(b<5){
                b=5;
            }
            if(p<2){
                p=2;
            }
            int waribiki =(x*b+y*p)*8/10;
            if(gokei<=waribiki){
            System.out.println(gokei);
            }else{
                System.out.println(waribiki);
            }
        }
    }
    public static void main(String[] args){
       Main obj = new Main();
       obj.solve();
    }
}

Measured memory_bytes: 23300
N, L = map(int, input().split())
A = [L+i-1 for i in range(1, N+1)]
S = sum(A)
diff = float('inf')
ans = 0
for i in range(N):
    x = S - A[i]
    d = abs(S - x)
    if d < diff:
        diff = d
        ans = x
print(ans)

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

int main() {
  int n;
  cin >> n;
  string f;
  getline(cin,f);
  while(n--) {
    string s;
    getline(cin,s);
    while(1) {
      int i=s.find("Hoshino");
      if(i==-1) break;
      s=s.substr(0,i)+"Hoshina"+s.substr(i+7);
    }
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[200005],s[200005],ans;
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) s[i]=max(s[i-1],a[i]);
	for(int i=1;i<=n;i++) ans+=a[i]-s[i];
	cout<<-ans;
	return 0;
}

Measured memory_bytes: 6672
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
using pii = pair<int, int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N;
int A[MX];
int B[MX];
vector<pii> PAB;

void input()
{
  cin >> N;
  rep(i, 1, N)
  {
    int a, b;
    cin >> a >> b;
    A[i] = a, B[i] = b;
    PAB.emplace_back(a + b, i);
  }
}
void solve()
{
  sort(all(PAB));
  reverse(all(PAB));

  int ans = 0;
  rep(i, 0, N-1)
  {
    if (i&1LL)
    {
      ans -= B[PAB[i].second];
    }
    else
    {
      ans += A[PAB[i].second];
    }
    //debug2(i,ans);
  }

  cout << ans << endl;
}
signed main()
{
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	cin >> n;

	int ans = 0;
	int prev = 1 << 30;
	int len = -1;

	rep(i,n) {
		int h;
		cin >> h;

		if (prev >= h) {
			len++;
			ans = max(ans, len);
		}
		else {
			len = 0;
		}
		prev = h;
	}


	cout << ans << endl;



	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

set<li> edge[100100];
li n;
li res[100100];
li c[100100];

PI edges[100100];

int main() {
    cin >> n;
    rep(i, n - 1) {
        li a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[i] = {a, b};
        edge[a].insert(b);
        edge[b].insert(a);
    }
    rin{
        cin >> c[i];
    }
    sort(c, c + n);

    queue<li> leaves;
    rin{
        if (sz(edge[i]) == 1) {
            leaves.push(i);
        }
    }

    li now = 0;
    while (!leaves.empty()) {
        li leaf = leaves.front();
        leaves.pop();
        li next = *edge[leaf].begin();
        edge[leaf].clear();
        edge[next].erase(leaf);
        if (sz(edge[next]) == 1) {
            leaves.push(next);
        }
        res[leaf] = c[now];
        now++;
    }

    // calc
    li ans = 0;
    rep(i, n - 1) {
        ans += min(res[edges[i].F], res[edges[i].S]);
    }
    cout << ans << endl;
    rin{
        cout << res[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
char c[4];
int main(){
  rep(i,4)scan(c[i]);
  if(c[0]==c[1]&&c[1]==c[2])prin("Yes");
  else if(c[1]==c[2]&&c[2]==c[3])prin("Yes");
  else prin("No");
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int m,d,i,mod,n,total,num[]={31,29,31,30,31,30,31,31,30,31,30,31};
	char table[7][20]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
	while(1){
		scanf("%d %d",&m,&d);
		if(m==0) break;
		total=0;
		for(i=0;i<m-1;i++) total+=num[i];
		total+=d;
		mod=total%7;
		printf("%s\n",table[mod]);
	}
	return 0;
}

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

#define N 2000000
#define K 10000

int main(void){
    int i, n, C[K + 1];
    unsigned short *A, *B;
    
    scanf("%d", &n);
    
    A = malloc(sizeof(short)*n+1);
    B = malloc(sizeof(short)*n+1);
    
    for (i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
    }
    
    for (i = 0; i <= K; i++) {
        C[i] = 0;
    }
    
    for (i = 1; i <= n; i++) {
        C[A[i]]++;
    }
    
    for (i = 1; i <= K; i++) {
        C[i] += C[i - 1];
    }
    
    for (i = n; i >= 1; i--) {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
    
    for (i = 1; i < n; i++) {
        printf("%d ", B[i]);
    }
    printf("%d\n", B[i]);
    
    return 0;
}




Measured memory_bytes: 9596
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double

int main(void){
  ll n;
  cin>>n;
  ll ans=llMAX;
  for(ll now=1;now<=sqrt(n)+1;now++){
    if(n%now==0){
      ans=min(ans,(now-1)+(n/now - 1));
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
vector<double>p(3000,0);
vector<vector<double>>dp(3000, vector<double>(3000,-1));

double probab(ll i,ll cnt)
{
    if(i==n)
    {
        if(cnt>n/2)
        return 1;
        return 0;
    }
    if(dp[i][cnt]!=-1)
        return dp[i][cnt];
    else
    {
        dp[i][cnt]=probab(i+1,cnt+1)*p[i]+probab(i+1,cnt)*(1-p[i]);
    }
    return dp[i][cnt];
    
}

int main()
{
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>p[i];
    }
    if(n==1)
        cout<<p[0]<<endl;
    else
    {
        cout<<setprecision(10)<<probab(0,0)<<endl;
    }
    return 0;
}

Measured memory_bytes: 74052
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = input()

# 勝つ手を選んだときはTrueになる。制約で出せなかったときにFalseに更新。
hands = [True] * N

scores = 0

for i in range(len(T)):
  if i >= K:
    # K回前と同じてを出したいのかかつ出せるのか判定
    if T[i-K] == T[i] and hands[i-K]:
      hands[i] = False
      continue
      
  if T[i] == "r":
    scores += P
  elif T[i] == "s":
    scores += R
  elif T[i] == "p":
    scores += S
    
print(scores)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endre getchar();getchar();return 0
#define moder 998244353
#define inf 5000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int n, a, b, k, ans;
int comemo[364364];
void init() {
	comemo[0] = 1;
	REP(i, n + 1) {
		comemo[i] = comemo[i - 1] * i%moder;
	}
}
int solvecomb(int x, int y) {
	return comemo[x] * mod_pow(comemo[x - y], moder - 2, moder) % moder*mod_pow(comemo[y], moder - 2, moder) % moder;
}
signed main() {
	cin >> n >> a >> b >> k;
	init();
	rep(i, n + 1) {
		if ((k - a * i) % b != 0 || (k - a * i) / b > n || (k - a * i) / b < 0)continue;
		int memo = (k - a * i) / b;
		ans += solvecomb(n, i)*solvecomb(n, memo) % moder;
		ans %= moder;
	}
	cout << ans << endl;
	endre;
}


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

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

    vector<int> vec(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        vec.at(a-1) += 1;
        vec.at(b-1) += 1;
    }

    rep(i, n) {
        cout << vec.at(i) << endl;
    }
}

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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,sz[N];

char s[N];

pair<int,int> p[N];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		a[i]=1e5;
	for(int i=0;i<n-1;i++)
		scanf("%d",&b[i]),a[i]=min(a[i],b[i]),a[i+1],a[i+1]=min(a[i+1],b[i]);
	for(int i=0;i<n;i++)
		ans+=a[i];
	printf("%d\n",ans);
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
#AGC25 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ans = inf
for a in range(1,n):
    b = n - a
    ans = min(ans,sum(list(map(int,list(str(a))))) + sum(list(map(int,list(str(b))))))
print(ans)


Measured memory_bytes: 41960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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; }
const long long INF = 1LL << 60;

int main()
{
    int A,B,C,X,Y;
    cin >> A>>B>>C>>X>>Y;
    
    int sum_min=1<<30;
    for (int i = 0; i <= max(X,Y); i++){
        int a = X-i;
        int b = Y-i;
        int c = i*2;
        a = max(0,a);
        b = max(0,b);
        int sum = a*A+b*B+c*C;
        //printf("i=%d a:%d b:%d c:%d sum:%d\n", i, a,b,c,sum);
        if(sum_min>sum) sum_min=sum;
      	//cout<<sum_min<<endl;
    }
    cout << sum_min << endl;   

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
	
  	if (n==25){
    printf("Christmas");
    }if(n==22){
      printf("Christmas Eve Eve Eve");
    }if(n==23){
printf("Christmas Eve Eve");
}if(n==24){
printf("Christmas Eve");
}
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
char s[110][110];
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int main() {
	int s, w;
	cin >> s >> w;
	if (w >= s)puts("unsafe");
	else {
		puts("safe");
	}
	return 0;
}


Measured memory_bytes: 3644
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n;
  map<string,int> M;
  rep(i,n){
    string s;
    cin>>s;
    M[s]++;  
  }
  cin>>m;
  rep(i,m){
    string t;
    cin>>t;
    M[t]--; 
  }
  int ans=0;
  for(auto x:M){
    chmax(ans,x.second);
  }
  cout<<ans<<'\n';
  return(0);
}

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

int main(){
ll N,K;
cin>>N>>K;

vector<double> p(N);

for(ll i=0;i<N;i++){
  cin>>p[i];
}
for(ll i=0;i<N;i++){
  p[i] = (1+p[i])/2.0;
// cout<<p[i]<<endl;
}
vector<double> rui(N+1);
rui[0] = 0;
for(ll i=1;i<=N;i++){
 rui[i] = rui[i-1] + p[i-1];
}
double sum=0;
double cc=0;
for(ll i=1;;i++){
  if(i+K-1<=N){
   sum = max((rui[i+K-1]-rui[i-1]),sum);
   //cout<<sum<<endl;
  }
  else{
    break;
  }
}

printf("%.20lf\n",(sum));

}


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

void p(const vector<vector<int> > &G) {
  for (int i = 1; i < G.size(); i++) {
    for (int j = 0; j < G[i].size(); j++) {
      cout << G[i][j] << ' ';
    }
    cout << endl;
  }
}

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

  vector<vector<int> > G(N + 1);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;

    G[A].push_back(B);
    G[B].push_back(A);
  }

  vector<int> P(N * 2 - 1);
  vector<bool> T(N + 1);
  fill(T.begin(), T.end(), false);
  int e1 = N - 1;
  int e2 = N;
  P[e1] = 1;
  P[e2] = G[1][0];
  T[P[e1]] = true;
  T[P[e2]] = true;

  bool flg = false;
  while (!flg) {
    flg = true;
    for (int i = 0; i < G[P[e1]].size(); i++) {
      if (!T[G[P[e1]][i]]) {
	P[e1 - 1] = G[P[e1]][i];
	T[P[e1 - 1]] = true;
	e1--;
	flg = false;
	break;
      }
    }
    for (int i = 0; i < G[P[e2]].size(); i++) {
      if (!T[G[P[e2]][i]]) {
	P[e2 + 1] = G[P[e2]][i];
	T[P[e2 + 1]] = true;
	e2++;
	flg = false;
	break;
      }
    }
  }

  cout << e2 - e1 + 1 << endl;
  for (int i = e1; i <= e2; i++) {
    cout << P[i];
    if (i != e2) {
      cout << ' ';
    }
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 7040
n,k,q = map(int,input().split())

cnt = [k for i in range(n)]

for i in range(q):
    a = int(input())    
    cnt[a-1] += 1

for i in range(n):
    cnt[i] -= q
    if cnt[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 7804
#include<stdio.h>

int main(void)
{
   int a, b, x, s, z;

   scanf("%d%d%d", &a, &b, &x);

   s = x - a;
   z = b - s;

   if((s>=0)&&(z>=0)) printf("YES\n");
   else printf("NO\n");

   return 0;
}

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

int main(){
	int n,q,i,d,sum,tmp;
	cin>>n>>q;
	vector<int> times(n);
	vector<string> names(n);
	for(i=0; i<n; i++){
		cin>>names[i]>>times[i];
	}

	sum=0;
	for(i=0; i<n; i++){
		d=q-times[i];
		if(d>=0){
			sum+=times[i];
			cout<<names[i]<<" "<<sum<<endl;
		}else{
			sum+=q;
			tmp=d*(-1);
			times.push_back(tmp);
			names.push_back(names[i]);
			n++;
		}
	}
	return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

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

  int s, w;
  cin >> s >> w;
  if(w >= s){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }

  return 0;
}


Measured memory_bytes: 3640
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String st = br.readLine();
            String[] s = st.split(" ",0);
            int a = (Integer.parseInt(s[0])+11)%13;
            int  b = (Integer.parseInt(s[1])+11)%13;
            if(a>b) {
                System.out.println("Alice");
            }else if(a<b){
                System.out.println("Bob");
            }else{
                System.out.println("Draw");
            }
        }catch(Exception ex){
            System.exit(0);
        }
    }
}

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

int main(){
	string a,b,c;
	cin >> a >> b >> c;
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	ld a, b, h, m;
	cin>>a>>b>>h>>m;
	ld mn=360/60*m, hr=360/12*h+m/2;
	ld agl=min(abs(mn-hr),abs(360-mn+hr));
	cout<<fixed<<setprecision(9)<<sqrtl(a*a+b*b-2*a*b*cos(agl*PI/180))<<endl;
}

Measured memory_bytes: 4184
#include <bits/stdc++.h>
#include <string>
using namespace std;
int a[20];

int main(){
	int i;
	for(i = 0; i < 6; i++){
		cin >> a[i];
	}
	sort(a, a + 5);
	if(a[4] - a[0] <= a[5])
		cout << "Yay!";
	else
		cout << ":(";
	return 0;
} 


Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())

theta_m = 2*math.pi*m/60.0
theta_h = 2*math.pi * (h+m/60.0)/12.0
ans = (a**2+b**2-2*a*b*math.cos(theta_h-theta_m))**(1/2.0)
print(ans)


Measured memory_bytes: 62436
import sys

x, n = map(int, input().split())
p = list(map(int,input().split()))

p.sort()

if x not in p:
    print(x)
    sys.exit()

for i in range(0, 100):
    if (x - i) not in p:
        print(x - i)
        sys.exit()
    if (x + i) not in p:
        print(x + i)
        sys.exit()

Measured memory_bytes: 9188
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  int happy = 0;
  int uneq = 0;
  rep(i,n-1){
    if(s.at(i) == s.at(i+1)){
      happy++;
    }
    if(s.at(i) != s.at(i+1)){
      uneq++;
    }
  }
  rep(i,k){
    if(happy == n-1) break;
    if(uneq >= 2){
      happy += 2;
    }else if(uneq == 1){
      happy ++;
    }
    uneq-=2;
    if(uneq <= 0) break;
  }
  cout << happy << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  int n;cin >> n;
  vector<ll> a(n), sum(n+1);
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    sum[i+1]=sum[i]+a[i];
  }
  ll ans = INF;
  for(int i = 1; i < n; ++i){
    ll x = sum[i];
    ll y = sum[n]-sum[i];
    ll tmp = abs(x-y);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H, W, K;
string c[6];
string c2[6];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W >> K;
	rep(y, 0, H) cin >> c[y];

	int ans = 0;
	rep(mskH, 0, 1 << H) rep(mskW, 0, 1 << W) {
		rep(y, 0, H) c2[y] = c[y];
		rep(y, 0, H) if (mskH & (1 << y)) rep(x, 0, W) c2[y][x] = 'R';
		rep(x, 0, W) if (mskW & (1 << x)) rep(y, 0, H) c2[y][x] = 'R';

		int cnt = 0;
		rep(x, 0, W) rep(y, 0, H) if (c2[y][x] == '#') cnt++;
		if (cnt == K) ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};

typedef vector<vector<Edge>> Graph;

signed main(void) {
	ll l, r;
	cin >> l >> r;

	ll ans = INT_MAX;
	rep(i, l, r + 1) {
		rep(j, i + 1, r + 1) {
			chmin(ans, 1LL*i * j % 2019);

			if ((j != i + 1) && (j % 2019) == ((i + 1) % 2019)) {
				break;
			}
		}

		if ((i != l) && (i % 2019) == (l % 2019)) {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(3);
  cin>>a[0]>>a[1]>>a[2];
  int c=0;
  while(true){
    sort(a.begin(),a.end());
    if(a[0]==a[1]&&a[1]==a[2]){
      cout<<c;
      return 0;
    }else if(a[1]==a[2]){
      a[0]+=2;
      c++;
    }else{
      a[0]++;
      a[1]++;
      c++;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
    int A,B,C,D;

    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);


    while(1){
        C = C - B;
        A = A - D;
        if(C <= 0){
            printf("Yes\n");
            break;
        }
        else if(A <= 0){
            printf("No\n");
            break;
        }
        
    }
    return 0;

}


Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,a;
string s,t;

int main() {
  cin >> n;
  map<int,int> mp;;
  rep(i,n){
  cin >> a; mp[a]++;
  } 
  int ans=0;
  for(auto m:mp)if(m.second&1) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 4992
/**akshaykumar99**/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=2e5+1;
 
typedef long long ll;
typedef long double ld;

int main() 
{
   IOS();
   
	ll n,i,j;
   cin>>n;
   vector<ll> v(n),vv(n),a(n);
   f(i,0,n)
      a[i]=i+1;
   f(i,0,n)
      cin>>v[i];
   f(i,0,n)
      cin>>vv[i];
   ll x,xx,r=1;
   do{
   	if(a==v)
         x=r;
      if(a==vv)
         xx=r;
      r++;
   }  
   while(next_permutation(all(a)));
   cout<<abs(x-xx)<<'\n';
    return 0;
}

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

int main(){
    ll n,all=0,ans=0;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        all+=a[i];
    }
    rep(i,n-1){
        all-=a[i];
        
        ans+=(a[i]%mod)*(all%mod);
        ans%=mod;
    }
    cout<<ans;
}

Measured memory_bytes: 4828
def hantei(s, p):
    for c in p:
        i = s.find(c)
        if i < 0:
            return False
        s = "" if i+1 >= len(s) else s[i+1:]
    return True


def main():
    n = int(input())
    s = input()

    ps = ["%03d" % i for i in range(1000)]
    seen = set()
    ans = 0
    for p in ps:
        if p not in seen and hantei(s, p):
            ans += 1
            seen.add(p)
    print(ans)


if __name__ == '__main__':
    main()




Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

//vector<ll> g[202020];
//fill(score, score+202020, 0);
vector<ll> v[505];

//i've not understood.
int main(){
  string S;
  cin >> S;
  int N = S.size(), MOD = 1000000007;

  ll dp[100010][4] = {};
  for(int i = N; i >= 0; --i){
    for(int j = 3; j >= 0; --j){
      if(i == N){
        dp[i][j] = (j == 3 ? 1 : 0);
      }else{
        dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3LL : 1LL);
        if(j < 3 && (S[i] == '?' || S[i] == "ABC"[j])){
          dp[i][j] += dp[i+1][j+1];
        }
        dp[i][j] %= MOD;
      }
    }
  }
  /*
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= 3; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  
  cout << dp[0][0] << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    vector<int> vi[2];
    vi[0].resize(1000, 0);
    vi[1].resize(1000, 0);
    int ini = 100 * (S[0] - '0') + 10 * (S[1] - '0') + S[2] - '0';
    vi[0][ini] = 1;
    for (int n = 3; n < N; ++n) {
        for (int i = 0; i < 1000; ++i) {
            if (vi[1-n%2][i]) {
                int s = S[n] - '0';
                vi[n%2][i] = 1;
                vi[n%2][(i%100)*10+s] = 1;
                vi[n%2][(i/10)*10+s] = 1;
                vi[n%2][(i/100)*100+(i%10)*10+s] = 1;
            }
        }
    }
    cout << accumulate(vi[1-N%2].begin(), vi[1-N%2].end(), 0) << endl;

    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

Node * find(Node *u, int k){
    while (u!=NIL && k != u->key){
        if(k < u->key)
            u = u->left;
        else
            u = u->right;
    }
    return u;
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *) malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL)
        return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL)
        return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if(com == "find"){
            scanf("%d", &x);
            Node *t = find(root, x);
            if(t!=NIL)
                printf("yes\n");
            else
                printf("no\n");
        }
    }

    return 0;
}

Measured memory_bytes: 21980
N = gets.chomp.to_i
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
d = gets.chomp.to_i
e = gets.chomp.to_i

a2 = (N-1)/a+1
b2 = (N-1)/b+1
c2 = (N-1)/c+1
d2 = (N-1)/d+1
e2 = (N-1)/e+1

max_t = a2
if b2 > max_t
  max_t = b2
end
if c2 > max_t
  max_t = c2
end
if d2 > max_t
  max_t = d2
end
if e2 > max_t
  max_t = e2
end

answer = max_t + 4
puts answer

Measured memory_bytes: 1788