akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * The Secret Number
 */
public class Main {

	static final String EMPTY = "";

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int W, H;
			W = parseInt(line.substring(0, line.indexOf(' ')));
			H = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((W | H) == 0) break;

			char[][] numc;
			String[][] nums;

			numc = new char[H + 1][W + 1];
			nums = new String[H + 1][W + 1];

			for (int i = 0; i < numc.length; i++) {
				Arrays.fill(numc[i], 'X');
			}

			for (int i = 0; i < H; i++) {
				line = br.readLine();
				for (int j = 0; j < W; j++) {
					char c = line.charAt(j);
					numc[i][j] = (c <= '9' ? c : 'X');
				}
			}

			//solve
			for (int i = H - 1; i >= 0; i--) {
				for (int j = W - 1; j >= 0; j--) {
					if (numc[i][j] != 'X') {
						String s1 = (numc[i + 1][j] != 'X' ? nums[i + 1][j] : EMPTY);
						String s2 = (numc[i][j + 1] != 'X' ? nums[i][j + 1] : EMPTY);
						nums[i][j] = numc[i][j] + large(s1, s2);
					}
				}
			}

			String max = EMPTY;

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (numc[i][j] != '0' && numc[i][j] != 'X') {
						max = large(max, nums[i][j]);
					}
				}
			}

			System.out.println(max);

		} //end while

	} //end main

	static String large(String s1, String s2) {

		if (s1.length() > s2.length()) return s1;
		if (s1.length() < s2.length()) return s2;
		if (s1.equals(s2)) return s1;

		String ret = EMPTY;
		for (int i = 0; i < s1.length(); i++) {
			if (s1.charAt(i) > s2.charAt(i)) {
				ret = s1;
				break;
			} else if (s1.charAt(i) < s2.charAt(i)) {
				ret = s2;
				break;
			}
		}
		return ret;
	}
}

Measured memory_bytes: 47752
use std::io;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let stdin = io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();

    buf.split(" ")
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


fn main() {

    let (n, mut hit) = {
        let v = read::<usize>();
        (v[0], v[1] as i64)
    };

    let mut vec = Vec::new();
    for _ in 0..n {
        let v = read::<i64>();
        vec.push((v[0], true));
        vec.push((v[1], false));
    }
    vec.sort();

    let mut ans = 0;

    for i in (0..vec.len()).rev() {
        let (atk, inf) = vec[i];
        if inf {
            ans += (hit + atk -1) / atk;
            break;
        } else {
            ans += 1;
            hit -= atk;
        }

        if hit <= 0 {
            break;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 9284
#include<stdio.h>

void perfect(int n,int a[])
{
    int i;
    int tem[200]={0};

    for(i=0;i<n*2;i++){
        tem[i]=a[i];
    }

    for(i=0;i<n*2;i++){
        a[i]=tem[i/2+n*(i%2)];
    }
}

void cat(int k,int n,int a[])
{
    int i;
    int tem[200]={0};

    for(i=0;i<n*2;i++){
        tem[i]=a[i];
    }

    for(i=k;i<n*2;i++){
        a[i-k]=tem[i];
    }
    for(i=0;i<k;i++){
        a[2*n-k+i]=tem[i];
    }

}

int main()
{
    int n,m,i;
    int card[200];
    int k[1000]={0};

    scanf("%d %d",&n,&m);

    for(i=0;i<200;i++) card[i]=i+1;
    for(i=0;i<m;i++) scanf("%d",&k[i]);

    for(i=0;i<m;i++){
        if(k[i]) cat(k[i],n,card);
        else perfect(n,card);
    }

    for(i=0;i<n*2;i++) printf("%d\n",card[i]);

    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<class T1, class T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template<class T1, class T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout);
const int MAXN = 10005;



int n;
int c[MAXN];
vector<int> g[MAXN];
int d[MAXN];
int uk = 0;


void dfs(int u, int pr = -1) {
	d[u] = c[uk];
	uk++;
	for (auto h: g[u]) {
		if (h != pr) {
			dfs(h, u);
		}
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read("input");
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		sum += c[i];
	}
	sort(c, c + n);
	sum -= c[n - 1];
	reverse(c, c + n);
	dfs(0);
	cout << sum << endl;
	for (int i = 0; i < n; i++) {
		cout << d[i] << ' ';
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 1408
while True:
  n,x = map(int,input().split())
  if n==x==0:
    break
  else:
    count=0
    for i in range(1,n+1):
      for j in range(i+1,n+1):
        for k in range(j+1,n+1):
          if i+j+k==x:
            count=count+1
    print(count)


Measured memory_bytes: 5596
n,m=[int(_) for _ in input().split()]

x=[int(_) for _ in input().split()]
y=[int(_) for _ in input().split()]

sumx=0
sumy=0
for i in range(n):
  sumx+=(2*i-n+1)*x[i]
  sumx%=1000000007
  #print(sumx)
for i in range(m):
  sumy+=(2*i-m+1)*y[i]
  sumy%=1000000007
  #print(sumy)
print((sumx*sumy)%1000000007)

Measured memory_bytes: 19452
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for i in range(n)]

    def getParent(self):
        return [self.find(i) for i in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if (root_x == root_y):
            return
        elif self.rank[root_x] > self.rank[root_y]:
            self.parent[root_y] = root_x

        elif self.rank[root_y] > self.rank[root_x]:
            self.parent[root_x] = root_y

        else:
            self.parent[root_x] = root_y
            self.rank[root_y] += 1

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def memsInGroup(self, x):
        """
        O(N)かかります
        """
        root = self.find(x)
        return [i for i in range(N) if root == self.find(i)]

    def sizeOfGroup(self, x):
        return len(self.memsInGroup(x))

if __name__ == "__main__":
    N, Q = map(int, input().split())
    test = UnionFind(N)

    for i in range(Q):
        query = list(map(int, input().split()))
        u, v = query[1], query[2]
        if query[0] == 0:
            test.unite(u-1, v-1)
        else:
            isSame = test.isSame(u-1, v-1)
            if isSame:
                print(1)
            else:
                print(0)


Measured memory_bytes: 93752
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))

for i in range(N):
  for j in range(3):
    if A[j] == b[i]:
      A[j] = 0
    if B[j] == b[i]:
      B[j] = 0
    if C[j] == b[i]:
      C[j] = 0
      
if max(A) == 0 or max(B) == 0 or max(C) == 0:
  print("Yes")
elif A[0] == 0 and B[0] == 0 and C[0] == 0:
  print("Yes")
elif A[1] == 0 and B[1] == 0 and C[1] == 0:
  print("Yes")
elif A[2] == 0 and B[2] == 0 and C[2] == 0:
  print("Yes")
elif A[0] == 0 and B[1] == 0 and C[2] == 0:
  print("Yes")
elif A[2] == 0 and B[1] == 0 and C[0] == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <cstdio>
#include <cctype>

int main(){
	char ch;
	
	while(1){
		scanf("%c", &ch);
		
		if(islower(ch)) printf("%c", toupper(ch));
		else if(isupper(ch)) printf("%c", tolower(ch));
		else printf("%c", ch);
		
		if(ch=='\n') break;
	}

	return 0;
}



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

int main() {
    long long A,B,C,K,sum=0, left;
    cin >> A >>B >> C >> K;
    if (A>=K) {
        cout << K;
        return 0;
    }
    else {
        sum=A;
        K-=A;
    }
    if (B>=K){
        cout << sum;
        return 0;
    }
    else {
        K-=B;
    }
    sum += K*-1;
    cout << sum;
}


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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define STR(s) string s;cin>>s

int main(){
  INT(h); INT(w); int ans = 0;
  vector<string> a;
  REP(h){STR(ai); a.PB(ai);}
  vector<int> v(w, -1);
  vector<vector<int>> vv(h, v);
  queue<pair<int, int>> q;
  REP(i, h){
    REP(j, w){
      if (a[i][j] == '#'){
        vv[i][j] = 0;
        q.push(MP(i, j));
      }
    }
  }
  while(!q.empty()){
    pair<int, int> p = q.front(); q.pop();
    int i = p.first, j = p.second;
    ans = max(ans, vv[i][j]);
    if (0 < i && vv[i - 1][j] < 0){
      vv[i - 1][j] = vv[i][j] + 1;
      q.push(MP(i - 1, j));
    }
    if (i < h - 1 && vv[i + 1][j] < 0){
      vv[i + 1][j] = vv[i][j] + 1;
      q.push(MP(i + 1, j));
    }
    if (0 < j && vv[i][j - 1] < 0){
      vv[i][j - 1] = vv[i][j] + 1;
      q.push(MP(i, j - 1));
    }
    if (j < w - 1 && vv[i][j + 1] < 0){
      vv[i][j + 1] = vv[i][j] + 1;
      q.push(MP(i, j + 1));
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 3e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;


vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}
lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}
int dx[4]={-1,0,0,1}, dy[4]={0,1,-1,0};

// ---- コーディングはここから！ ('-')7



void solve(){
	string s; cin>>s; int d; cin>>d;
	vvl dp(d,vl(2,0));
	dp[0][0]=1;
	fore(i,0,sz(s)){
		vvl aux(d,vl(2,0));
		fore(j,0,d)fore(k,0,2)fore(ii,0,10){
		if(ii>(s[i]-'0') and k==0)break;
		aux[(j + ii)%d][k or ii<(s[i]-'0')]=SUM(aux[(j + ii)%d][k or ii<(s[i]-'0')],dp[j][k]);
		}
		dp=aux;
	}
	cout<<SUM(dp[0][0],dp[0][1]-1)<<ENDL;


}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


Measured memory_bytes: 3684
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

LL vis[805][805] = {0};
char ch[805][805];
LL n,m,k,ans = INF;
LL dx[4] = {0,0,1,-1};
LL dy[4] = {1,-1,0,0};

struct node{
	LL x,y,stp;
}h,t; queue <node> q;
void bfs(LL x,LL y){
	t.x = x; t.y = y; t.stp = 0; q.push(t);
	while(!q.empty()){
		h = q.front(); q.pop();
		if(h.stp > k) continue;
		vis[h.x][h.y] = 1;
		ans = min(ans,min(min(h.x - 1,h.y - 1),min(n - h.x,m - h.y)));
		for(LL i = 0;i < 4;i ++){
			LL tx = h.x + dx[i],ty = h.y + dy[i];
			if(!tx || !ty || tx > n || ty > m) continue;
			if(vis[tx][ty] || ch[tx][ty] == '#') continue;
			vis[tx][ty] = 1;
			t.x = tx; t.y = ty; t.stp = h.stp + 1;
			q.push(t);
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL sx = 0,sy = 0;
	cin >> n >> m >> k;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= m;j ++){
			cin >> ch[i][j];
			if(ch[i][j] == 'S'){ sx = i; sy = j; }
		}
	}
	bfs(sx,sy);
	cout << (ans + k - 1) / k + 1 << endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int ara[n-1],ara2[n];
    int i;
    for(i=0;i<n;i++){
        ara2[i] = 0;
    }
    for(i=0;i<n-1;i++){
        cin >> ara[i];
        ara2[ara[i]-1]++;
    }
    for(i=0;i<n;i++){
        cout << ara2[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 5144
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
monsters = [tuple(map(int, input().split())) for _ in range(N)]
heapify(monsters)

max_H = 10**9
ans = 0
damage = 0
while monsters:
    x, h = heappop(monsters)
    if h <= max_H:
        h -= damage
        if h <= 0:
            continue
        bomb = (h+A-1) // A
        damage += bomb * A
        ans += bomb
        heappush(monsters, (x+2*D, max_H+bomb*A))
    else:
        damage -= h-max_H
print(ans)


Measured memory_bytes: 34308
#include<math.h>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define    ll   long long int
#define    py   printf("Yes\n")
#define    pn   printf("No\n")
#define    in   cin>>
using namespace std;

int main()
{
  string s,t;
  in s>>t;
  bool flag=false;
  for(int i=0;i<s.size();i++)
  {
    if(s==t)
    {
      flag=true;
      break;
    }
    s=s.back()+s.substr(0,s.size()-1);
  }
  if(flag)py;
  else pn;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a == b){
    for(int i=0;i<a;i++){
    printf("%d",a);
    }
  }
  if(a > b){
    for(int i=0;i<a;i++){
	printf("%d",b);
    }
  }
  if(b > a){
    for(int i=0;i<b;i++){
	printf("%d",a);
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

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

vector<string> vec;
vector<vector<int>> dist;

void bfs(int x, int y){
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  REP(i, H) REP(j, W) dist[i][j] = -1;
  dist[x][y] = 0;

  while(!q.empty()){
    x = q.front().first;
    y = q.front().second; q.pop();

    chmax(ans, dist[x][y]);

    REP(i, 4){
      int xx = x+dx[i];
      int yy = y+dy[i];
      if(OUT(0, xx, H)) continue;
      if(OUT(0, yy, W)) continue;
      if(vec[xx][yy] == '#') continue;
      if(dist[xx][yy] != -1) continue;
      dist[xx][yy] = dist[x][y]+1;
      q.push(make_pair(xx, yy));
    }
  }
}

signed main() {
  cin >> H >> W;
  vec = vector<string>(H);
  dist = vector<vector<int>>(H, vector<int>(W));
  REP(i, H) cin >> vec[i];

  REP(i, H) REP(j, W) if(vec[i][j] == '.') bfs(i, j);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

main = do
  [x,y] <- getInts
  print $ (x-1)*(y-1)

-- util
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine


Measured memory_bytes: 380
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0;i<S.size();++i) {
		if ('1' == S[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <array>
using namespace std;

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

    int a[100000] = {0,};

    for (int i=0; i<N; i++)
        cin >> a[i];

    int counter = 1;
    int ai = a[0];
    while (0 <= N && ai != 2 && ai != -1) {
        int n = ai-1;
        ai = a[n];
        a[n] = -1;
        counter++;
        N--;
    }

    if (ai == 2) {
        cout << counter << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <fstream>
 
using namespace std;
 
#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;

vector<int> ans_list[4];

int main(){

  int kind[] = {10,50,100,500};

  while(true){
    
    int sum;
    int num[4];
    
    cin >> sum;
    if(sum == 0)
      break;

    cin >> num[0] >> num[1] >> num[2] >> num[3];

    int coin = 0;
    int ans[4];
    int amount = 0;
    fill(ans, ans+4, INF);

    for(int i = 0; i < 4; i++){
      coin += num[i];
      amount += kind[i]*num[i];
    }
    

    int coin_ans = INF;

    int S = amount - sum;

    

    for(int i = 3; i >= 0; i--){
      num[i] -= S/kind[i];
      S %= kind[i];
      
    }

    ans_list[0].push_back(num[0]);
    ans_list[1].push_back(num[1]);
    ans_list[2].push_back(num[2]);
    ans_list[3].push_back(num[3]);


    /*
    for(int i = 0; i <= num[0]; i++){
      for(int j = 0; j <= num[1]; j++){
	for(int k = 0; k <= num[2]; k++){
	  for(int l = 0; l <= num[3]; l++){
	    int tmp = 10*i + 50*j + 100*k + 500*l;
	    int C = coin;
	    if(tmp >= sum){
	      int M = tmp - sum;
	      cout << tmp << " " << M << endl;
	      if(i >= 1 && M % 50 != 0)
		continue;
	      M = M/50 * 50;
	      if(j >= 1 && M % 100 != 0)
		continue;
	      M = M/100 * 100;
	      if(k >= 1 && M % 500 != 0)
		continue;
	      M = tmp - sum;
	      C -= (i+j+k+l);
	      C += M%50;
	      M = M/50*50;
	      C += M%100;
	      M = M/100*100;
	      C += M%500;
	      if(C < coin_ans){
		coin_ans = C;
		ans[0] = i;
		ans[1] = j;
		ans[2] = k;
		ans[3] = l;
	      }
	    }
	  }
	}
      }
    }

    

    ans_list[0].push_back(ans[0]);
    ans_list[1].push_back(ans[1]);
    ans_list[2].push_back(ans[2]);
    ans_list[3].push_back(ans[3]);

    */
    
  }

  for(int i = 0; i < ans_list[0].size(); i++){
    for(int j = 0; j < 4; j++){
      if(ans_list[j][i] > 0)
	cout << kind[j] << " " << ans_list[j][i] << endl;
    }
    if(i < ans_list[0].size()-1)
      cout << endl;
  }

  return 0;

}

Measured memory_bytes: 1264
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}


char s[33000];
int main(void) {

  string s;
  string f, b;
  cin >> s;
  int q;
  cin >> q;
  int p = 1;
  rep(ert, q) {
    int T;
    cin >> T;
    if (T == 1) p *= -1;
    else {
      int F;
      char c;
      cin >> F >> c;
      F *= 2; F -= 3;
      F *= p;
      if (F == -1) f.push_back(c);
      else b.push_back(c);
    }
  }
  if (p == -1) {
    reverse(s.begin(), s.end());
    reverse(b.begin(), b.end());
    cout << b << s << f << endl;
  } else {
    reverse(f.begin(), f.end());
    cout << f << s << b << endl;
  }
}


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

#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))

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

    using P = pair<int, int>;
    std::vector<P> pairs;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        pairs.emplace_back(a,b);
    }

    auto compare = [](const P& left, const P& right) {
                       return left.second > right.second;
                   };

    int start = 1;
    int count = 0;
    for (;;) {
        std::priority_queue<P, std::vector<P>, decltype(compare)> queue(compare);

        for (auto& p : pairs) {
            if (p.first >= start) {
                queue.push(p);
            }
        }

        if (queue.empty()) {
            break;
        }

        const P& p = queue.top();
        count++;
        start = p.second;
    }

    printf("%d\n", count);

    return 0;
}


/*
 * Local Variables:
 * compile-command: "CXXFLAGS='-std=c++14' make main"
 * End:
 */


Measured memory_bytes: 2896
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }
    let divides = ["maerd", "remaerd", "esare", "resare"];
    let s = s.chars().rev().collect::<String>();
    let mut i = 0;
    while i < s.len() {
        if let Some(n) = divides
            .iter()
            .position(|divide| (&s[i..]).starts_with(divide))
        {
            i += divides[n].len();
        } else {
            println!("NO");
            return;
        }
    }
    println!("YES")
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp
{
    class Program
    {
        static int W, H;
        static void Main(string[] args)
        {
            int[] ar = ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
            W = ar[0];
            H = ar[1];
            int N = ar[2];
            int[] r = new int[W * H];
            for (int i = 0; i < N; i++)
            {
                ar = ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
                int x = ar[0];
                int y = ar[1];
                int a = ar[2];
                switch (a)
                {
                    case 1:
                        Draw(ref r, 0, x, 0, H);
                        break;
                    case 2:
                        Draw(ref r, x, W, 0, H);
                        break;
                    case 3:
                        Draw(ref r, 0, W, 0, y);
                        break;
                    case 4:
                        Draw(ref r, 0, W, y, H);
                        break;

                }
            }
            int cnt = r.Count(_ => _ == 0);
            WriteLine(cnt);
            ReadLine();
        }
        static void Draw(ref int[] r, int x1, int x2, int y1, int y2)
        {
            for (int x = x1; x < x2; x++)
                for (int y = y1; y < y2; y++)
                    r[x + (y * W)] = 1;
        }
    }
}


Measured memory_bytes: 13396
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)

d = float('inf')
i = 0
while i + k - 1 < n:
    d = min(h[i + k - 1] - h[i], d)
    i += 1

print(d)


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

int main(){
	int no, *term;
	cin >> no;
	term = new int[no];
	for (int i = 0; i < no; i++){
		cin >> term[i];
	}
	for (int i = no - 1; i > 0; i--){
		cout << term[i] << " ";
	}
	cout << term[0] << endl;
	
	return 0;
}

Measured memory_bytes: 1188
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;


#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iterator>

using COST_T = uint32_t;
constexpr uint32_t N_MAX = 200000;
constexpr COST_T INF = 1000 * 1000 * 1000 + 1000;//std::numeric_limits<double>::infinity()

#if defined(_MSC_VER) && defined(_DEBUG)
//static_assert(false, "リリースでコンパイルしないと遅いよ！！");
#endif

struct edge {
	uint32_t to;
	COST_T cost;
	edge() {}
	edge(uint32_t to_, COST_T cost_)
		:to(to_), cost(cost_) {}
};
std::vector<edge> graph[N_MAX];

//ダイクストラ
COST_T D[N_MAX];
void Dijkstra(uint32_t s)
{
	using P = std::pair<COST_T, uint32_t>;//cost pos
	std::priority_queue<P, std::vector<P>, std::greater<>> que;
	std::fill(std::begin(D), std::end(D), INF);

	D[s] = 0;
	que.emplace(0, s);
	while (!que.empty())
	{
		auto p = que.top(); que.pop();
		const auto& nowpos = p.second;
		const auto& nowcost = p.first;
		if (D[nowpos] < nowcost) { continue; }

		//for (int32_t to = 0; to < N; ++to)
		//{
		//	auto cost = nowcost + graph[nowpos][to];
		//	if (cost < D[to]) {
		//		D[to] = cost;
		//		que.emplace(D[to], to);
		//	}
		//}

		for (const auto& e : graph[nowpos])
		{
			auto cost = nowcost + e.cost;
			if (cost < D[e.to]) {
				D[e.to] = cost;
				que.emplace(cost, e.to);
			}
		}

	}
}



int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int M;
	in >> N>>M;
	for (int i = 0; i < M; ++i)
	{
		int a, b;
		in >> a >> b;
		--a; --b;
		graph[a].emplace_back(b, 1);
		graph[b].emplace_back(a, 1);
	}
	Dijkstra(0);
	if (D[N - 1] > 2) {
		out << "IM";
	}
	out << "POSSIBLE" << endl;

	return 0;
}
#endif


Measured memory_bytes: 15080
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

// edit

void solve() {
    
    int N, M;
    cin >> N >> M;
    
    vector<vector<int>> G(N);
    
    REP(i, M){
        int a,b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    queue<int> que;
    vector<int> dist(N, INF);
    vector<int> prev(N, -1);
    
    dist[0] = 0;
    que.push(0);
    
    while(!que.empty()){
        int top = que.front();
        que.pop();
        
        for(auto e : G[top]){
//            if(dist[e] > dist[top] + 1){
//                dist[e] = dist[top] + 1;
//
//            }
            if(chmin(dist[e], dist[top] + 1)){
                que.push(e);
                prev[e] = top;
            }
        }
    }
    
    cout << "Yes" << endl;
    for(int i = 1; i < prev.size(); ++i){
        cout << prev[i] + 1 << endl;
    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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

int main(){
	int tempTime;
	int totalTime = 0;
	int minute = 0;
	int second = 0;
	for(int i=0;i<4;i++){
		cin >> tempTime;
		totalTime += tempTime;
	}
	second = totalTime % 60;
	minute = (totalTime - second)/60;
	cout << minute << '\n';
	cout << second <<'\n';
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int A, B;
int main() {
	cin >> A >> B;
	cout << max(A - 2 * B, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"

void func(vector<int> &v){
	reverse(v.begin(), v.end());
}

int main(){
	/*ios::sync_with_stdio(false);
    cin.tie(NULL);*/
   set<int> s;
   int a, b, c;
   cin >> a;
   s.insert(a);
   cin >> b;
   s.insert(b);
   cin >> c;
   s.insert(c);

   cout << s.size();
   endl;

   bye;
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
l = [int(input()) for _ in range(n)]
s = set()
tmp = 1
cnt = 0
while tmp not in s:
  s.add(tmp)
  tmp = l[tmp-1]
  cnt += 1
  if tmp == 2:
    break
else:
  cnt = -1
print(cnt)

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

int main(){
  int N,K,count=0;
    cin>>N>>K;
    vector<int>H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
    if(H[i]>=K){
      count++;
    }
  }
  cout<<count;
}

Measured memory_bytes: 640
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let a: Vec<usize> = sc.vec(N);
    let mut ans = 0;
    for i in 0..N {
        if (i+1) % 2 != 0 && a[i] % 2 != 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a;
 cin >> a;
 int d = a/10;
 int e = a%10;
 if(d==9||e==9){
     cout << "Yes" << endl;
 }else{
     cout << "No" << endl;
 }
return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#define rnt register int
using namespace std;
int x,n;
int max,mx,max_wz;
int main()
{
	scanf("%d",&n);
	for(rnt i=1;i<=n;i=-~i)
	{
		scanf("%d",&x);
		if(x>max)
		{
			mx=max;
			max=x;max_wz=i;
			continue;
		}
		if(x>mx)
		{
			mx=x;
			continue;
		}
	}
	if(max==mx)
	{
		for(rnt i=1;i<=n;i++)
			printf("%d\n",max);
		return 0;
	}
	else
	{
		for(rnt i=1;i<=n;i++)
			if(i==max_wz)
				printf("%d\n",mx);
			else
				printf("%d\n",max);
		return 0;
	}
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define sc scanf
using namespace std;
const int N=3e5+5;
const int mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
template <typename it>int o(it a){cout<<a<<endl;return 0;}
int n,m;
int s[N],t[N];
ll dp[2005][2005]={0};
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>s[i];
    for(int i=1;i<=m;i++)cin>>t[i];
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if(s[i]==t[j])dp[i][j]=(dp[i-1][j]+dp[i][j-1]+1)%mod;
    else dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
    o((dp[n][m]+1)%mod);
}

Measured memory_bytes: 33024
S=list(input())
S_odd=S[0::2]
S_even=S[1::2]

flag=True
for s_odd in S_odd:
    if not s_odd in ['R','U','D']:
        flag=False
        break
for s_even in S_even:
    if not s_even in ['L','U','D']:
        flag=False
        break
if flag==True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
class Monster:
    def __init__(self, health, strength):
        self.health = health
        self.strength = strength

a = list(map(int, input().split()))

t_monster = Monster(*a[:2])
a_monster = Monster(*a[2:])

i = 0
while t_monster.health > 0 and a_monster.health > 0:
    if i % 2 == 0:
        a_monster.health -= t_monster.strength
    else:
        t_monster.health -= a_monster.strength
    i += 1

if t_monster.health > 0:
    print("Yes")
else:
    print("No")


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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};


void Main()
{
	int D;
	cin>>D;
	vec(c,26);
	vin(c);

	vecvec(v,D,26);
	vec(maxi, D);
	rep(i, D){
		int _max = -1;
		rep(j,26){
			cin>>v[i][j];
			if(v[i][j]>_max){
				_max = v[i][j]; maxi[i]=j;
			}
		}
	}

	dout<<_n2;
	rep(i,D){
		cout<<maxi[i]+1<<_n;
	}
}



int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


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

char map[21][21];
int count;
int x, y;

void dfs(int nx, int ny){
  map[ny][nx] = '#';
  count++;
  if (nx+1 < x && map[ny][nx+1] == '.'){
    dfs(nx+1, ny);
  }
  if (nx > 0 && map[ny][nx-1] == '.'){
    dfs(nx-1, ny);
  }
  if (ny+1 < y && map[ny+1][nx] == '.'){
    dfs(nx, ny+1);
  }
  if (ny > 0 && map[ny-1][nx] == '.'){
    dfs(nx, ny-1);
  }
  return;
}

int main(){
  while (1){
    cin >> x >> y;
    if (!(x || y)) break;
    int ix, iy;
    count = 0;
    for (int i = 0; i < y; i++){
      for (int j = 0; j < x; j++){
	cin >> map[i][j];
	if (map[i][j] == '@'){ix = j; iy = i;}
      }
    }
    dfs(ix, iy);
    cout << count << endl;
  }
}

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

using namespace std;

int main(){
    long long int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    if(C*2<=A && C*2<=B){
        cout << max(X,Y)*C*2 << endl;
    }else if(C*2<=A+B && X<=Y){
        if(C*2<B){
            cout << max(X,Y)*C*2 << endl;
        }else{
            cout << X*C*2 + (Y-X)*B << endl;
        }
    }else if (C*2<=A+B && Y<=X){
        if(C*2<A){
            cout << max(X,Y)*C*2 << endl;
        }else{
            cout << Y*C*2 + (X-Y)*A << endl;
        }
    }else{
        cout << A*X + B*Y << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using lubl=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,m;std::cin>>n>>m;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    lint sum=std::accumulate(ALL(a),0ll);
    lint k=(sum+4*m-1)/(4*m);
    std::cout<<(m<=std::count_if(ALL(a),[k](lint x){return k<=x;})
        ?"Yes":"No")<<'\n';
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

K = getN()
S = input()
n = len(S)

if n <= K:
    print(S)
else:
    print(S[:K] + '...')

Measured memory_bytes: 67980
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

char s[200001];
char t[200001];

int main()
{
	while (scanf("%s%s", s, t) != EOF) {
		int i;
		int slen;
		int cnt;
		slen = strlen(s);
		cnt = 0;
		for (i = 0; i < slen; i ++) {
			if (s[i] != t[i]) {
				cnt ++;
			}
		}
		printf("%d\n", cnt);
	}
	return (0);
}


Measured memory_bytes: 2076
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long a = x%11;
    if(a>=1 && a<=6){
    	System.out.println((x/11)*2+1);
    }else if(a>=7 && a != 0){
    	System.out.println((x/11)*2+2);
    }else{
    	System.out.println((x/11)*2);
    }
  }
}

Measured memory_bytes: 9804
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll n,i,t,m,mx=0,T,ans=0,r,k=0,p=0,q,x,y,l;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    x=a*c,y=a*d,l=b*c,r=b*d;
    ans=max(x,y);
    ans=max(ans,l);
    ans=max(ans,r);
    cout<<ans<<endl;

}







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

int main() {
    int N;
    cin>>N;
    map<int,int> mp;
    for(int i=0;i<N;i++){
        int s;
        cin>>s;
        mp[s]++;
        if(mp[s]==2){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout << "YES"<<endl;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <cstdio>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>

const int Type_Max = 12345;


int Data[Type_Max];

int Map[123][123];

int main()
{

	int H, W;
	int N;

	scanf("%d%d%d", &H, &W, &N);

	for (int a = 0; a < N; ++a)
	{
		scanf("%d", &Data[a]);
	}

	int counter = 0;

	for (int a = 0; a < N; ++a)
	{

		for (int b = 0; b < Data[a]; ++b)
		{
			Map[counter / W][counter % W] = a + 1;
			counter++;
		}

	}

	for (int y = 0; y < H; ++y)
	{

		if (y % 2 == 0)
		{
			printf("%d", Map[y][0]);
			for (int x = 1; x < W; ++x)
			{
				printf(" %d", Map[y][x]);
			}

			puts("");
		}
		else
		{

			printf("%d", Map[y][W - 1]);
			for (int x = W - 1; 0 < x; --x)
			{
				printf(" %d", Map[y][x - 1]);
			}

			puts("");
		}


	}

	return 0;
}

Measured memory_bytes: 384
n = int(input())
p = [ int(i) for i in input().split(" ")]
q = [ int(i) for i in input().split(" ")]

def permutation(list):
  if len(list) == 0:
    return []
  
  if len(list) == 1:
    return [list]

  result = []

  for i in range(len(list)):
    base = list[i]
    can = list[:i] + list[i+1:]
    for p in permutation(can):
      result.append([base] + p) 
  
  return result

result = sorted(permutation([i for i in range(1, n+1)]))
print( abs(result.index(q) - result.index(p)))


Measured memory_bytes: 9972
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int m = 0;
  for (char c : s) {
    m += (int) (c - '0');
    m %= 9;
  }
  cout << (m == 0 ? "Yes" : "No") << '\n';
  return 0;
}


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

using namespace std;

int main(void)
{
	int h, w;
	const int INF = 10e8;
	cin >> h >> w;
	bool d[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char c;
			cin >> c;
			if (c == '.')
				d[i][j] = true; // road
			else
				d[i][j] = false; // wall
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (d[i][j] == false)
				continue;
			int map[h][w];
			queue<pair<int, int>> q;
			q.push(make_pair(i, j));

			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
					map[i][j] = INF;
			map[i][j] = 0;

			while (!q.empty()) {
				pair<int, int> p = q.front();
				int x = p.first;
				int y = p.second;

				q.pop();
				if (x > 0) {
					if (d[x-1][y]) {
						if (map[x][y]+1 < map[x-1][y]) {
							map[x-1][y] = map[x][y]+1;
							q.push(make_pair(x-1, y));
						}
					}
				}
				if (y > 0) {
					if (d[x][y-1]) {
						if (map[x][y]+1 < map[x][y-1]) {
							map[x][y-1] = map[x][y]+1;
							q.push(make_pair(x, y-1));
						}
					}
				}
				if (x < h-1) {
					if (d[x+1][y]) {
						if (map[x][y]+1 < map[x+1][y]) {
							map[x+1][y] = map[x][y]+1;
							q.push(make_pair(x+1, y));
						}
					}
				}
				if (y < w-1) {
					if (d[x][y+1]) {
						if (map[x][y]+1 < map[x][y+1]) {
							map[x][y+1] = map[x][y]+1;
							q.push(make_pair(x, y+1));
						}
					}
				}

			}
			int max = 0;
			for (int x = 0; x < h; x++) {
				for (int y = 0; y < w; y++) {
					if (map[x][y] > max && map[x][y] != INF)
						max = map[x][y];
				}
			}
			//cout << max << endl;
			if (max > ans)
				ans = max;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int a[3][3];
    bool flags[3][3] = {false};
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n, q;
    cin >> n;
    rep(i, n)
    {
        cin >> q;
        rep(j, 3) rep(k, 3) flags[j][k] |= (a[j][k] == q);
    }

    bool flag = false;
    rep(i, 3)
    {
        flag |= (flags[i][0] & flags[i][1] & flags[i][2]);
        flag |= (flags[0][i] & flags[1][i] & flags[2][i]);
    }
    flag |= (flags[0][0] & flags[1][1] & flags[2][2]);
    flag |= (flags[2][0] & flags[1][1] & flags[0][2]);

    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256