akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

ll res[200200];
int dist[200200];

int main(){

  int n,q;
  cin >> n >> q;
  vector<vector<int>> v(n);
  FILLl(res,200200,0);
  FILL(dist,200200,-1);
  REP(i,n-1){
    int x,y;cin >> x >> y;
    x--,y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  REP(i,q){
    int x,y;cin >> x >> y;
    x--;
    res[x] += y;
  }
  queue<int> que;
  que.push(0);
  dist[0] = 0;
  while(!que.empty()){
    int ov = que.front();que.pop();
    for(auto nv : v[ov]){
      if(dist[nv] != -1)continue;
      res[nv] += res[ov];
      dist[nv] = dist[ov] + 1;
      que.push(nv);
    }
  }
  REP(i,n)cout << res[i] << " ";




  

  return 0;
}


Measured memory_bytes: 17140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, from, to) for (int i = from; i < to; i++)
#define sortv(x) sort(x.begin(), x.end())
#define dump(x) cerr << #x << " = " << x << endl
typedef vector<int> vi;
typedef long long ll;
int main()
{
  int K;
  string s;
  cin >> s >> K;
  set<string> st;
  rep(i, 0, s.size())
  {
    rep(j, 0, K)
    {
      if (i + j >= s.size())
        break;
      string t = s.substr(i, j + 1);
      st.insert(t);
      dump(t);
    }
  }
  auto itr = st.begin();
  rep(i, 0, K - 1) itr++;
  cout << *itr << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#define MAX 100000
 
int A[MAX], n;
 
int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}
 
int main(void) {
  int i, q;
 
  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);
 
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");
 
  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(int A, int B, const string& S){
  if(S.size() != A+B+1) return false;
  if(S[A] != '-') return false;

  rep(i,S.size()){
    if(i==A) continue;

    if('0' <= S[i] && S[i] <= '9'){
      ;
    }else{
      return false;
    }
  }
  return true;
}

int main(){
  int A, B;
  cin >> A >> B;
  string S;
  cin >> S;

  if(check(A, B, S)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

int main() {
	int n,k;
  	string s;
  	char a;
 	cin >> n >> s >> k;
  	a = s.at(k-1);
  	for (int i=0;i<n;i++) {
      if (s.at(i) == a) {
        continue;
      } else {
        
        s.at(i) = '*';
      }
    }
    cout << s << endl;
  	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  ll b=0;
  ll c=100;
  for(ll i=0;c<a;i++){
    c=c/100+c;
    b+=1;
  }
  cout<<b<<endl;
  
}

Measured memory_bytes: 3636
N=int(input())
candies=[list(map(int,input().split())) for _ in range(2)]
ans=candies[0][0]+sum(candies[1])
tmp=ans

if N>=2:
  for i in range(1,N):
    tmp=tmp-candies[1][i-1]+candies[0][i]
    ans=max(ans,tmp)
else:
  ans=candies[0][0]+candies[1][0]

print(ans)

Measured memory_bytes: 3064
def main():
    K,N = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]

    d = []
    n = len(A)
    for i, a in enumerate(A):
        if i == 0:
            d.append(min(A[0] + K - A[1], A[n-1] - A[0]))
        elif i == n-1:
            d.append(min(A[n-1]-A[0], K-A[n-1]+A[N-2]))
        else:
            d.append(min(K-A[i]+A[i-1], A[i]+K-A[i+1]))

    print(min(d))


if __name__ == '__main__':
    main()

Measured memory_bytes: 26444
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,s1[10001],s2[10001],s3[10001];
	int i,j,len,len2,x,flg;
	char buf[10001];
	scanf("%d",&n);
	for(j=0;j<n;j++)	{
		for(i=0;i<81;i++)	{
			s1[i]=0;	s2[i]=0;	s3[i]=0;
		}
		scanf("%s",buf);
		len=strlen(buf);
		for(i=len-1;i>=0;i--)	s1[len-1-i]=buf[i]-'0';
		scanf("%s",buf);
		len2=strlen(buf);
		for(i=len2-1;i>=0;i--)	s2[len2-1-i]=buf[i]-'0';		
		for(i=0;i<80;i++)	{
			x=s1[i]+s2[i]+s3[i];
			s3[i]=x%10;
			s3[i+1]=x/10;
		}
		if(s3[80]!=0 || len>80 || len2>80)	{
			printf("overflow\n");
		}
		else {
			flg=0;
			for(i=79;i>=0;i--)	{
				if(flg==1 || s3[i]!=0)	{
					printf("%d",s3[i]);
					flg=1;
				}
			}
			if(flg==0)	{
				printf("0");
			}
			printf("\n");
		}
	}
	return 0;
}


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

using namespace std;

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG(x) cout << "> " << #x << ": " << x << endl;

typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
const int inf = 1e9+7;
const ll longinf = 1LL<<60;

// Start Coding...

void solve() {
    string S;
    cin >> S;
    if (S[0] == S[1] && S[1] == S[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return;
}

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

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

int     main() {
        string X;
        cin >>X;
        int t=0;
        int s=0;
        for (int i=0; i<X.size(); i++)
                if ('S'==X.at(i))
                        s++;
                else if (s>0)
                        s--;
                else
                        t++;
        cout <<t+s <<endl;
        return 0;
}

Measured memory_bytes: 640
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
for i in range(n):
    x = int(input())
    for j in range(3):
        if x in a[j]:
            a[j][a[j].index(x)]=0
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]==0 or a[0][i]==a[1][i]==a[2][i]==0 or a[0][0]==a[1][1]==a[2][2]==0 or a[0][2]==a[1][1]==a[2][0]==0:
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int A = Integer.parseInt(S[0]);
    int P = Integer.parseInt(S[1]);
    
    P += A*3;
    System.out.println(P/2);
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define  INF 1ll<<60
signed main(){
	int N;
	cin>>N;
	vector<int>vet(N);
	int maior=0,maiormom=0;
	for(int i=0;i<N;i++){
		cin>>vet[i];
		if(i>=1){
			if(vet[i-1]>=vet[i]){
				maiormom++;
			}
			else{
				maior=max(maiormom,maior);
				maiormom=0;
			}
		}
	}
	maior=max(maiormom,maior);
	cout<<maior<<endl;
}

Measured memory_bytes: 1024
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// 枝定義
struct Edge
{
	int	to;
	ll	dist;
	Edge(){}
	Edge(int to, ll dist): to(to), dist(dist){}
};

// グラフ定義(二次元配列)
template <class E>
using Graph = vector<vector<E>>;
 
// ダイクストラ
template<class D, D infVal>
struct Dijkstra 
{
	// res[i] = sからiまでの最短距離
	vector<D> res;
    
	template<class E>
	Dijkstra(const Graph<E> &G, int s) 
	{
		int V = (int)G.size();
		res = vector<D>(V, infVal);
        
		using P = pair<D, int>;
		priority_queue<P, vector<P>, greater<P>> que;
		que.push(P(0, s));
		res[s] = 0;
        
		while (!que.empty()) {
			P p = que.top(); que.pop();
			
			// 違う最短距離がキューにあるのでスキップ
			if (res[p.second] < p.first) {
				continue;
			}

			// 最短距離を更新
			for (E edge : G[p.second]) {
				D nextDist = p.first + edge.dist;
                if (nextDist < res[edge.to]) {
					res[edge.to] = nextDist;
					que.push(P(nextDist, edge.to));
				}
			}
		}
	}
};


int main()
{
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;

	Graph<Edge>	Ge(n), Gs(n);
	REP(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--, v--;
		Ge[u].emplace_back(Edge(v, a));
		Ge[v].emplace_back(Edge(u, a));
		Gs[u].emplace_back(Edge(v, b));
		Gs[v].emplace_back(Edge(u, b));
	}
	
	Dijkstra<ll, (ll)2e18> en(Ge, s);
	Dijkstra<ll, (ll)2e18> sn(Gs, t);

	vector<ll> ans(n, 0);
	ans[n - 1] = en.res[n - 1] + sn.res[n - 1];
	for (int i = n - 2; 0 <= i; i--) {
		ans[i] = min(ans[i + 1], en.res[i] + sn.res[i]);
	}
	REP(i, n) cout << (ll)10e14 - ans[i] << endl;
	return 0;
}


Measured memory_bytes: 19012
fun main(args: Array<String>) {
  val n = readInt()
  val A = (1..n).map { readInt() }
  val sortedA = A.sortedDescending()
  val n1 = sortedA[0]
  val n2 = sortedA[1]
  for (i in 0 until n) {
    val a = A[i]
    println(if (a == n1) n2 else n1)
  }
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


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

int main() {
  int a, b;
  cin >> a >> b;
  int sum = a + b;
  int diff = a - b;
  int mul = a * b;
  vector<int> vec{sum, diff, mul};

  int max = *max_element(vec.begin(), vec.end());

  cout << max << endl;
}

Measured memory_bytes: 256
// ------------------------------
//   Author: Subhashis Suara
// ------------------------------

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, x, cnt = 0, minT = 101;
    cin >> n >> m >> x;
    int toll[m];
    for (int i = 0; i < m; i++)
        cin >> toll[i];
    
    for (int i = 0; i < x; i++)
        for (int j = 0; j < m; j++)
            if (i + 1 == toll[j])
                cnt++;
    // cout << cnt << "\n";
    minT = min(minT, cnt);
    cnt = 0;
    for (int i = x; i < n; i++)
        for (int j = 0; j < m; j++)
            if (i + 1 == toll[j])
                cnt++;
    // cout << cnt << "\n";
    minT = min(minT, cnt);
    cout << minT << "\n";
    return 0;
}


Measured memory_bytes: 3624
# ２人で同じ個数になるように分ける。
# ３つの袋が同じ数かつ偶数の場合も分けれる。

a_box, b_box, c_box = map(int, input().split())

if a_box == b_box + c_box:
    print('Yes')
elif b_box == a_box + c_box:
    print('Yes')
elif c_box == a_box + b_box:
    print('Yes')
elif a_box == b_box == c_box and (a_box + b_box + c_box) % 2 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9184
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int a,b;
char s[105];
int main()
{
	scanf("%d%d",&a,&b);
	scanf("%s",s+1);
	if(strlen(s+1)!=a+b+1)
	{
		puts("No");
		return 0;
	}
	for(int i=1;i<=a+b+1;i++)
	{
		if(i!=a+1)
		{
			if(s[i]>'9'||s[i]<'0')
			{
				puts("No");
				return 0;
			}
		}
		else
		{
			if(s[i]!='-')
			{
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a, b, c = sc.nextLong

    if (a + b + c >= 22) println("bust")
    else println("win")
  }
}


Measured memory_bytes: 25524
<?php
list($n, $d, $a) = ints();
for ($i = 0; $i < $n; ++$i) list($x[], $h[]) = ints();
array_multisort($x, SORT_ASC, $h);
$cusum = array_fill(0, $n + 1, 0);
$cnt = 0;
// x で爆発させると x + 2d まで爆発が届くと考えても同じ
// 左のモンスターから順番に倒していく
for ($i = 0; $i < $n; ++$i) {
    $cusum[$i + 1] += $cusum[$i];
    $h[$i] -= $cusum[$i + 1];
    if ($h[$i] <= 0) continue;

    // この座標での爆発回数計算
    $tcnt = intdiv($h[$i], $a) + min(1, $h[$i] % $a);

    // 二分探索で爆発が届く最も右の座標を検索
    $ok = $i;
    $ng = $n;
    while (abs($ok - $ng) > 1) {
        $mid = intdiv($ok + $ng, 2);
        if ($x[$mid] - $x[$i] <= 2 * $d) $ok = $mid;
        else $ng = $mid;
    }
    if ($ok !== $i) {
        // imos法で今回の爆発で減らした体力量を管理
        $cusum[$i + 1] += $a * $tcnt;
        if ($ok + 2 <= $n) $cusum[$ok + 2] -= $a * $tcnt;
    }

    $cnt += $tcnt;
}
echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 55300
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int(i)=int (a);i<=int (b);i++)
#define ff(i,a,b) for(int (i)=int (a);i<int (b);i++)
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define pii pair<int,int>
const int N=1e6+6;
pii a[N];
int n,m;
bool cmp(pii a,pii b){
	return a.se<b.se;
}
int main(){
	cin>>n>>m;
	ff(i,0,m){
		cin>>a[i].fi>>a[i].se;
	}
	sort(a,a+m,cmp);
	int last=0,ans=0;
	ff(i,0,m){
		if(a[i].fi>=last){
			last=a[i].se;
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5+6;
const int M = 998244353;
const int inf = 1e9;
ll iv[N],f1[N],f2[N];
ll nck(int n, int k) {
	return f1[n]*f2[k]%M*f2[n-k]%M;
}
int cnt(int x){
    int ret = 0;
    while(x){
        ret+=x%10;
        x/=10;
    }
    return ret;
}
void solve(){
    int n;
    cin>>n;
    int mn = inf;
    for(int i=1;i<n;i++){
        mn = min(mn,cnt(i)+cnt(n-i));
    }
    cout<<mn<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>    // std::binary_search, std::sort
#include <vector>       // std::vector
using namespace std;

using QWORD = unsigned long long;
using SQWORD = long long;
using DWORD = unsigned int;
using SDWORD = int;
using WORD = unsigned short;
using SWORD = short;
using BYTE = unsigned char;
using SBYTE = char;
using DOUBLE = double;
using FLOAT = float;

#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)

#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0xFFFFFFFFFFFFFFFF)

#define MAX_QWORD  (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD  (0xFFFFFFFF)
#define MAX_WORD   (0xFFFF)
#define MAX_BYTE   (0xFF)


#define ArrayLength(a)  (sizeof(a) / sizeof(a[0]))

static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }

#define BYTE_BITS   (8)
#define WORD_BITS   (16)
#define DWORD_BITS  (32)
#define QWORD_BITS  (64)

using M_BOOL = bool;
#define M_TRUE (true)
#define M_FALSE (false)
#define DIVISOR (1000000007)

#define MAX_FACTORY (60)
static DWORD adwFactoryNum[MAX_FACTORY];
static DWORD adwFactoryCumMul[MAX_FACTORY];
static DWORD s_dwFactoryNum = 0;

static inline void inputString(char *pcStr)
{
    char *pcCur = pcStr;
    for (;;) {
        char c = getchar();
        if (('\n' == c) || (EOF == c)) {
            break;
        }
        *pcCur = c;
        pcCur++;
    }
    *pcCur = '\0';
}

static inline SDWORD inputSDWORD(void)
{
    SDWORD lNumber = 0;
    SDWORD lMultiplier = 1;
    M_BOOL bRead = M_FALSE;
    for (;;) {
        char c = getchar();
        if (!bRead) {
            if ('-' == c) {
                lMultiplier = -1;
            }
        }
        if (('0' <= c) && (c <= '9')) {
            lNumber *= 10;
            lNumber += (c - '0');
            bRead = M_TRUE;
        } else {
            if (bRead) {
                return lNumber * lMultiplier;
            }
        }
    }
}


int main()
{
    DWORD dwInput_r;
    DWORD dwInput_g;
    DWORD dwInput_b;

    dwInput_r = inputSDWORD();
    dwInput_g = inputSDWORD();
    dwInput_b = inputSDWORD();

    DWORD dwNumber = 100 * dwInput_r + 10 * dwInput_g + dwInput_b;

    if (dwNumber % 4 == 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    string A = string(a, to_string(b)[0]);
    string B = string(b, to_string(a)[0]);
    if(A<=B) {
        cout << A << endl;
    }
    else{
        cout << B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << 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; }

void solve() {
	int x; cin >> x;
    int cnt500 = x / 500, cnt5 = (x % 500) / 5;
    cout << 1000 * cnt500 + 5 * cnt5 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int > vi;
int dfs(int);
vi E[100000];
vi D;
vl A;
int maxD;
bool ok;
int main() {
	int n;
	cin >> n;
	A.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	D.resize(n,-1);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	D[0] = 1;
	stack<int> st;
	st.push(0);
	while (!st.empty()) {
		int v = st.top(); st.pop();
		for (int i = 0; i < E[v].size(); i++) {
			int nv = E[v][i];
			if (D[nv] > 0)continue;
			D[nv] = D[v] + 1;
			st.push(nv);
		}
	}
	ok = true;
	if (E[0].size() == 1 && dfs(0) != A[0]) {
		cout << "NO" << endl;
		return 0;
	}
	if (E[0].size()>1&&dfs(0) != 0) {
		cout << "NO" << endl;
		return 0;
	}
	if (!ok) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
}
int dfs(int v) {
	int Enumber = A[v] * 2;
	if (E[v].size() == 1&&D[v]>D[E[v][0]]) {
		return A[v];
	}
	for (int i = 0; i < E[v].size(); i++) {
		int nv = E[v][i];
		if (D[nv] < D[v])continue;
		int dfnv = dfs(nv);
		Enumber -= dfnv;
		if (dfnv > A[v])ok = ok && false;
	}
	if (Enumber < 0||Enumber>A[v])ok = ok && false;
	//cout << "v=" << v << "  " << Enumber << endl;
	return Enumber;
}


Measured memory_bytes: 13568
num = int(input())
val = input().split()
waru = [0] * len(val)

for i in range(num):
  while True:
    v = int(val[i])
    if v % 2 == 0:
      val[i] = str(int(v / 2))
      waru[i] += 1
    else:
      break
      
min = min(waru)

print(min)

Measured memory_bytes: 3060
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
    int n; cin>>n;
    map<string, int> a;
    for(int i=0; i<n; ++i) {
        string s; cin>>s;
        ++a[s];
    }
    vector<pair<int, string>> v;
    for(auto& e: a) v.emplace_back(-e.second, e.first);
    sort(begin(v), end(v));
    for(auto& e: v) if (e.first==v[0].first) cout<<e.second<<'\n';
}


Measured memory_bytes: 28916
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <utility>
#include <cmath>
#include <functional>
#include <iomanip>

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

#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define out(v) cout<<v<<"\n"
const int MOD = 1e9+7;
const int INF = numeric_limits<int>::max();
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; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

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

  int tmp = 1;
  int ans = 1;
  rep(i, N) {
    int a; cin >> a;
    if (a % 2 == 0)
      tmp *= 2;
    ans *= 3;
  }
  out(ans - tmp);

  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  cout << a + (b/2) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			String line;
			String[] strArray = new String[3];
			boolean cntFlg = true;

			while (cntFlg == true){
				
				line = br.readLine();
				strArray = line.split("\\s");
				
				switch (strArray[1].charAt(0)) {
				case '+':
					System.out.println(Integer.parseInt(strArray[0])
							+ Integer.parseInt(strArray[2]));
					break;
				case '-':
					System.out.println(Integer.parseInt(strArray[0])
							- Integer.parseInt(strArray[2]));
					break;
				case '*':
					System.out.println(Integer.parseInt(strArray[0])
							* Integer.parseInt(strArray[2]));
					break;
				case '/':
					System.out.println(Integer.parseInt(strArray[0])
							/ Integer.parseInt(strArray[2]));
					break;
				case '?':
					cntFlg = false;
					break;
				default:
					break;
				}
			}
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}

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

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

    set<int> a;
    int ae;
    bool failed=false;
    for (int i=0; i<n; i++) {
        cin >> ae;
        if (a.find(ae) != a.end()) failed=true;
        a.insert(ae);
    }

    if (failed) cout << "NO" << endl;
    else cout << "YES" << endl;
}

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

int main(){
  int n, max, i = 0;
  cin >> n;
  max = n;
  int k[max], p[max];
  while(n > i){
    cin >> k[i] >> p[i];
    if(k[i] >= p[i]){
      int ans = k[i] % p[i];
      if(ans == 0){
        cout << p[i] << endl;
      }else{
        cout << ans << endl;
      }
    }else if(k[i] < p[i]){
      cout << k[i] << endl;
    }
    i++;
  }
  return 0;
}


Measured memory_bytes: 3092
N,K=map(int,input().split())
d=list(map(int,input().split()))

dr=len(d)
for i in range(N,100000):
    s=list(str(i))
    num=0
    for j in d:
        if(str(j) in s):
            break
        else:
            num+=1
    if(num==dr):
        print(i)
        break

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> wanum(n, 0);
	vector<bool> isac(n, false);
	for(int i = 0; i < m; i++){
		int p;
		string s;
		cin >> p  >> s;
		p--;
		if(isac[p]) continue;
		if(s == "AC"){
			isac[p] = true;
		} else {
			wanum[p]++;
		}
	}
	int acnum = 0;
	int wasum = 0;
	for(int i = 0; i < n; i++){
		if(isac[i]) {
			acnum++;
			wasum += wanum[i];
		}
	}
	cout << acnum << " " << wasum << endl;
}

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

using namespace std;

int main(){
string str;
cin>>str;
map<char,int>is;

for(int i = 0;i<str.size();i++){
    is[str[i]]++;
}
int cnt=0;
for(auto i : is){
     if(i.second%2==0){
            cnt++;
     }
}
if(cnt==is.size()) puts("Yes");
else puts("No");
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


template< typename T >
struct SparseTable {
  vector< vector< T > > st;
  vector< int > lookup;

  SparseTable(const vector< T > &v) {
    int b = 0;
    while((1 << b) <= v.size()) ++b;
    st.assign(b, vector< T >(1 << b));
    for(int i = 0; i < v.size(); i++) {
      st[0][i] = v[i];
    }
    for(int i = 1; i < b; i++) {
      for(int j = 0; j + (1 << i) <= (1 << b); j++) {
        st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
    lookup.resize(v.size() + 1);
    for(int i = 2; i < lookup.size(); i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  inline T rmq(int l, int r) {
    int b = lookup[r - l];
    return min(st[b][l], st[b][r - (1 << b)]);
  }
};

int n;
bool f(int k,SparseTable<int> &st,vector<int> &a){
    unordered_map<int,P> ma;
    int bf = 0;
    for (int i = 0; i < n; i++) {
        int t = a[i];
        if(ma.find(t) != ma.end()){
            if(st.rmq(ma[t].sc,i) < t) ma[t] = mp(0,i);
        }
        if(t < bf && ma[t].fs == 0) ma[t] = mp(1,i); 
        ma[t].fs++;
        ma[t].sc=i;
        while(ma[t].fs == k + 1){
            ma[t].fs = 1;
            if(ma.find(t-1) != ma.end()){
                if(st.rmq(ma[t-1].sc,i) < t - 1) ma[t - 1] = mp(1,i);
                else ma[t - 1].sc = i;
            }
            else ma[t - 1] = mp(1,i);
            ma[t-1].fs++;
            t--;
            if(t<=0||k==1) return false;
        }
        bf = a[i];
    }
    return true;
};

int main(){
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SparseTable<int> st(a);
    int l = 0, r = INF;
    while(abs(r - l) > 1){
        int m =  l + (r - l) / 2;
        if(f(m,st,a)) r = m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 32680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,ans = 0,l,r;
    cin >> n;
    rep(i, n){
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from fractions import gcd
    n = int(input())
    t = [int(input()) for _ in range(n)]

    ans = 1
    for elem in t:
        ans = (ans * elem) // gcd(ans, elem)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 64364
d, g = gets.to_s.split.map{|i|i.to_i}
s, c = Array.new(d){ gets.to_s.split.map{|i|i.to_i} }.transpose

ans = 2 ** 29
(2**d).times do |b|
  
  tot = 0
  n   = 0
  d.times do |i|
    if 1 == b[i]
      tot += c[i] + s[i] * 100 * (i+1)
      n += s[i]
    end
  end
  
  if tot < g
    (d-1).downto(0) do |i|
      next if 1 == b[i]
      s[i].times do |j|
        break if tot >= g
        tot += 100 * (i+1)
        n += 1
      end
    end
  end
  
  ans = n if ans > n
end

puts ans


Measured memory_bytes: 1788
function main() {
  var
  i = 0, j,
  wh, startXY, goalXY, n,
  board;
  for (;;) {
    wh = input[i++].split(' ').map(Number);
    if (!wh[0] && !wh[1]) break;
    
    board = initBoard(wh[0], wh[1]);
    
    startXY = input[i++].split(' ').map(Number);
    goalXY  = input[i++].split(' ').map(Number);
    n = Number(input[i++]);
    for (j = 0; j < n; j++) {
      putBlock.bind(null, board).apply(null, input[i++].split(' ').map(Number));
    }
    
    console.log(canGoToGoal(board, startXY, goalXY) ? 'OK' : 'NG');
  }
}

function initBoard(w, h) {
  var
  i, j,
  board = [];
  for (i = 0; i < w; i++) {
    board.push([]);
    for (j = 0; j < h; j++) {
      board[i][j] = 0;
    }
  }
  return board;
}

function putBlock(board, c, d, x, y) {
  var
  i, j,
  b = [[4,2], [2,4]][d];
  for (i = 0; i < b[0]; i++) {
    for (j = 0; j < b[1]; j++) {
      board[x - 1 + i][y - 1 + j] = c;
    }
  }
}

function canGoToGoal(board, startXY, goalXY) {
  var
  to = [[-1,-1], [ 0,-1], [ 1, -1],
        [-1, 0],          [ 1,  0],
        [-1, 1], [ 0, 1], [ 1,  1]],
  sx = startXY[0] - 1, sy = startXY[1] - 1,
  gx = goalXY[0] - 1, gy = goalXY[1] - 1,
  m = {}, c = board[sx][sy];
  
  if (c === 0) return false;
  
  return (function search(x, y) {
    var
    i;
    if ([x, y] in m) return m[[x, y]];
    if (x < 0 || board.length <= x || board[x][y] !== c) return m[[x, y]] = false;
    if (x === gx && y === gy) return m[[x, y]] = true;
    
    m[[x, y]] = false;
    
    for (i = 0; i < 8; i++) {
      if (!([x + to[i][0], y + to[i][1]] in m)) {
        if (search(x + to[i][0], y + to[i][1])) return m[[x, y]] = true;
      }
    }
    
    return m[[x, y]] = false;
  })(sx, sy);
}

/*
function canGoToGoal(board, startXY, goalXY) {
  var
  queue = [],
  to = [[-1,-1], [ 0,-1], [ 1, -1],
        [-1, 0],          [ 1,  0],
        [-1, 1], [ 0, 1], [ 1,  1]],
  sx = startXY[0] - 1, sy = startXY[1] - 1,
  gx = goalXY[0] - 1, gy = goalXY[1] - 1,
  xym, x, y,
  m = {},
  c = board[sx][sy];
  
  if (c === 0) return false;
  
  queue.push([sx, sy, {}]);
  
  for (;queue.length >= 1;) {
    xy = queue.shift();
    x = xy[0]; y = xy[1];
    m[[x, y]] = true;
    
    if (x < 0 || board.length <= x || c !== board[x][y]) continue;
    if (x === gx && y === gy) return true;
    
    for (i = 0; i < 8; i++) {
      if (!m[[x + to[i][0], y + to[i][1]]]) {
        queue.push([x + to[i][0], y + to[i][1]]);
      }
    }
  }
  
  return false;
}
*/

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 12872
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc137/tasks/abc137_d

import heapq

# n: 日雇いアルバイトの案件数
# m: m日後までに稼げるお金を最大化
n, m = map(int, input().split())

# (期限から) m日以内に開始しなければ終わらない仕事
money_schedule = [[] for _ in range(m)]
for i in range(n):
    # a日後にb円振り込まれる
    a, b = map(int, input().split())
    if m < a:
        continue
    money_schedule[a - 1].append(b)

job_pool = []
heapq.heapify(job_pool)
income = 0
for available_jobs in money_schedule:
    for salary in available_jobs:
        heapq.heappush(job_pool, -salary)

    if 0 < len(job_pool):
        income -= heapq.heappop(job_pool)

print(income)


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

/// Lib
///

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n; cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; ++i){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int l = d[n/2 - 1];
    int r = d[n/2];
    int ans = r-l;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
M,K=map(int,input().split())
if M==0:
    if K==0:
        print("0 0")
    else:
        print(-1)
elif M==1:
    if K==0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if K==0:
        ans=[str(i//2) for i in range(2**(M+1))]
        print(" ".join(ans))
    elif 1<=K<2**M:
        L=[0 for i in range(2**M)]
        X=[]
        for i in range(2**M):
            if L[i]==0:
                X.append((i,i^K))
                L[i]=1
                L[i^K]=1
        st=[]
        for i in range(2**(M-2)):
            a,b=X[2*i]
            c,d=X[2*i+1]
            tmp=[a,c,d,a,b,d,c,b]
            st.append(" ".join([str(i) for i in tmp]))
        print(" ".join(st))
    else:
        print(-1)

Measured memory_bytes: 24496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    static int[] dp;
    static int[] input;

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


        String[] line = reader.readLine().split(" ");

        int n = Integer.parseInt(line[0]);
        int k = Integer.parseInt(line[1]);


        input = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        dp = new int[input.length];
        List<Integer> backwards;
        dp[0] = 0;

        for (int i = 1; i < n; i++) {

            backwards = new ArrayList<>();
            for (int j = i - 1, c = 0; j >= 0 && c < k; j--, c++) {
                backwards.add(Math.abs(input[i] - input[j]) + dp[j]);
            }

            dp[i] = backwards.stream().min(Integer::compare).get();

        }

        System.out.println(dp[n - 1]);
    }




}


Measured memory_bytes: 100352
def isCLKWISE(ph):
    return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = []
for i in n:
    P.append([int(x) for x in input().split()])
      
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33740
/* author   : mpily :-()
title : Competing.cpp
time :Sat Apr 18 13:22:36 2020

*/
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int>arr(n+1);
	for(int i = 1; i < n; ++i){
		int temp;
		cin>>temp;
		arr[temp]++;
		
	}
	for(int i = 1; i <= n; ++i){
		cout<<arr[i]<<" \n";
	}
	return 0;
}

Measured memory_bytes: 4048
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def grid_1(): 
    H, W = wczytaj_liste()
    siatka = []
    for i in range (H): 
        siatka.append(input())
    czy_mozna = True
    ile_mozliwosci = [[0 for i in range(W)] for j in range(H)]
    
    for i in range(W): 
        if siatka[0][i] == '.' and czy_mozna:
            ile_mozliwosci[0][i]= 1
        else: 
            czy_mozna = False
    czy_mozna = True
    for j in range(H):
        if siatka[j][0]=='.' and czy_mozna: 
            ile_mozliwosci[j][0]=1
        else: 
            czy_mozna = False
    for i in range(1,W):
        for j in range (1,H):
            if siatka[j][i] == '.':
                ile_mozliwosci[j][i] = (ile_mozliwosci[j-1][i]+ile_mozliwosci[j][i-1]) %(10**9+7)
            else:
                ile_mozliwosci[j][i] = 0
    print(ile_mozliwosci[H-1][W-1])
    
grid_1()


Measured memory_bytes: 53724
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+1;

int n, p, q, a[N], b[N], c[N], g[N], h[N], l[N], r[N], ans[N];

bool compare(int i, int j) {
	return a[i] != a[j] ? (a[i] > a[j]) : (b[i] > b[j]); }

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cin >> n >> q;
    for (p = 1; p*p <= n; ++p);
    for (int i = 0; i < n; ++i)
    	cin >> c[i];
    for (int m = p-1, i = 0; i < q; ++i)
        cin >> l[i] >> r[i], a[i] = --l[i]/m, b[i] = --r[i]/m, h[i] = i;
	sort(h,h+q,compare), ++g[c[0]];
    for (int i, u, v, w = 0, z = 0, j = 0, k = 1; j < q; ++j, ans[i] = k) {
    	for (i = h[j], u = l[i], v = r[i]; z > v; --z)
        	if (--g[c[z]] == 0)
        		--k;
    	for (; z < v; ++g[c[z]])
        	if (g[c[++z]] == 0)
        		++k;
    	for (; w < u; ++w)
        	if (--g[c[w]] == 0)
        		--k;
    	for (; w > u; ++g[c[w]])
        	if (g[c[--w]] == 0)
        		++k; }
    for (int i = 0; i < q; ++i)
        cout << ans[i] << '\n'; }


Measured memory_bytes: 19388
use proconio::input;

fn main() {
    input! {
        n: i32,
        li: [String;n]
};
println!("AC x {}", li.iter().filter(|&n| *n == "AC").count());
println!("WA x {}", li.iter().filter(|&n| *n == "WA").count());
println!("TLE x {}", li.iter().filter(|&n| *n == "TLE").count());
println!("RE x {}", li.iter().filter(|&n| *n == "RE").count());
}


Measured memory_bytes: 7788
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.IntMap as M

data HeapPolicy = MinHeap | MaxHeap

data HeapT p a = Empty p
               | HeapT p Int a (HeapT p a) (HeapT p a)

type Heap a = HeapT HeapPolicy a

empty :: HeapPolicy -> Heap a
empty = Empty

rank :: Heap a -> Int
rank (Empty _)         = 0
rank (HeapT _ r _ _ _) = r

constract :: HeapPolicy -> a -> Heap a -> Heap a -> Heap a
constract p x a b
  | rank a >= rank b = HeapT p (rank b + 1) x a b
  | otherwise        = HeapT p (rank a + 1) x b a

merge :: Ord a => Heap a -> Heap a -> Heap a
merge h (Empty _) = h
merge (Empty _) h = h
merge h1@(HeapT MinHeap _ x l1 r1) h2@(HeapT MinHeap _ y l2 r2)
  | x < y     = constract MinHeap x l1 (merge r1 h2)
  | otherwise = constract MinHeap y l2 (merge r2 h1)
merge h1@(HeapT MaxHeap _ x l1 r1) h2@(HeapT MaxHeap _ y l2 r2)
  | x > y     = constract MaxHeap x l1 (merge r1 h2)
  | otherwise = constract MaxHeap y l2 (merge r2 h1)
merge _ _     = error "invalid pattern match!"

push :: Ord a => a -> Heap a -> Heap a
push x h@(Empty p)         = merge (HeapT p 1 x (Empty p) (Empty p)) h
push x h@(HeapT p _ _ _ _) = merge (HeapT p 1 x (Empty p) (Empty p)) h

pop :: Ord a => Heap a -> Heap a
pop (Empty _)         = error "empty heap!"
pop (HeapT _ _ _ a b) = merge a b

top :: Heap a -> a
top (Empty _)         = error "empty heap!"
top (HeapT _ _ x _ _) = x

isEmpty :: Heap a -> Bool
isEmpty (Empty _) = True
isEmpty _         = False

mapFromList :: [(Int,Int)] -> M.IntMap [Int]
mapFromList [] = M.empty
mapFromList ((k,v):xs) =
    M.insertWith (\[a] b -> a:b) k [v] (mapFromList xs)

solve :: Int -> M.IntMap [Int] -> Int
solve m xs = f 1 (empty MaxHeap)
  where
    f :: Int -> Heap Int -> Int
    f i h
      | i > m = 0
      | otherwise =
          let h' = case M.lookup i xs of
                     Just ls  -> foldr push h ls
                     Nothing -> h
           in if isEmpty h'
                 then f (i+1) h'
                 else top h' + f (i+1) (pop h')

main :: IO ()
main = do
    [_,m] <- map read . words <$> getLine :: IO [Int]
    xs <- map ((\[a,b] -> (a,b))
        . map (fst . fromJust . BS.readInt) . BS.words)
        . BS.lines <$> BS.getContents
    print . solve m $ mapFromList xs


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

int main(void)
{
    string a, b;

    int cnt=0;

    cin >> a >> b;

    for(int i=0; i<a.size(); i++)
    {
        if(a[i]!=b[i])
            cnt++;
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
 
ll mod = 1e9+7;
 
ll max(ll a, ll b ) {
	if(a>b)
		return a;
	else return b;
}
ll min(ll a, ll b ) {
	if(a<b)
		return a;
	else return b;
}
 
ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
ll inv(ll a) {
	ll x, y;
	ll g = gcd(a, mod, x, y);
	x = (x % mod + mod) % mod;
	return x;
}
ll binpow(ll a, ll b, ll m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a%m;
        a = a * a%m;
        b >>= 1;
    }
    return res;
}

int main() {
	ll ttt;
	//cin>>ttt;
	ttt = 1;
	while(ttt--) {
		string n; cin>>n;
		ll ans = 0;
		for(int i=0; i<n.size(); i++) {
			ans += n[i] - '0';
		}
		if(ans%9==0) cout<<"Yes";
		else cout<<"No";
 	}	
	return 0;
}


Measured memory_bytes: 3724
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>

using namespace std;

int n,k,p;

bool rev;

string s;

int main()
{
	cin >> n >> k >> s;
	int cnt = 0;
	for (int i = 1;i <= k && p < n;i++)
	{
		cnt++;
		if (s[p] == 'A' + rev)
		{
			s[p] = 'B' - rev;
			continue;
		}
		rev ^= 1;
		p++;
	}
	if (p == n)
	{
		if (n & 1)
		{
			k -= cnt;
			cout << char('A' + (k & 1));
		}
		else
			cout << 'B';
	}
	for (int i = p;i < n;i++)
		cout << char(((s[i] - 'A') ^ rev) + 'A');
	for (int i = (p == n);i < p;i++)
		cout << char('A' + ((p - 1 - i) & 1));
	cout << endl;
	return 0;
}

Measured memory_bytes: 772
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException{
		int h,w;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		while(true){
			str = br.readLine().split(" ");
			h = Integer.parseInt(str[0]);
			w = Integer.parseInt(str[1]);

			if(h==0 && w==0)break;

			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(i != 0 && i != h - 1 && j != 0 && j != w - 1){
						builder.append(".");
					}else{
						builder.append("#");
					}
				}
				builder.append("\n");
			}
			builder.append("\n");
		}
		builder.delete(builder.length() - 1, builder.length());

		System.out.println(builder.toString());
		br.close();
	}
}

Measured memory_bytes: 25252
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 

vector<int>dx={0,1,0,-1},dy={1,0,-1,0};
const int N=60,inf=1e18;
int a[N],B[N],S[N];
int G[N][N];

int32_t main()
{
	IOS
	int r,x,d;cin>>r>>d>>x;;
	int prev=x;
	for(int i=2;i<=11;i++)
	{
		prev=r*prev-d;
		cout<<prev<<" ";
	}
	cout<<endl;
	

}


Measured memory_bytes: 256