akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int t;
  cin >> t;
  int h = t / 3600;
  int m = (t - h * 3600) / 60;
  int s = t % 60;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}



Measured memory_bytes: 3136
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] In = Console.ReadLine().Split(' ');
            int[] W = new int[n];
            int sum = 0;
            for(int i=0; i < n; i++)
            {
                W[i] = int.Parse(In[i]);
                sum += W[i];
            }
            int min = Int32.MaxValue;
            int temp = 0;
            for(int i = 0; i < n; i++)
            {
                temp += W[i];
                sum -= W[i];
                int ab = (int)Math.Abs(sum - temp);
                if (min > ab) min = ab;
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 27372
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    N = list(map(int,input().split()))
    A1 = N[0] * N[1]
    ans = N[2]
    if A1 < ans:
        print(A1)
    else: print(ans)
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 27064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;




int main(){
	char A[110];
	char B[110];

	scanf("%s%s", A, B );
	printf("%s%s\n", B, A);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
int w, h, n;
char mas[20][20];
  
typedef pair< int , int > Pi;
typedef pair< Pi , Pi > Piii;
Pi p;
  
struct sell{
  int d; //値引き額
  int s; //開始時刻
  int e; //終了時刻
};
sell shop[10];
  
int min_cost[20][20][1 << 10];
  
int bfs(){
  queue< Piii > que; // Pii( (買った商品, 今の時間), 座標)
  const int dy[] = { 1, 0, -1, 0}, dx[] = { 0, 1, 0, -1};
  
  memset( min_cost, -1, sizeof(min_cost));
  que.push( Piii( Pi( 0, 0), p));
  min_cost[p.second][p.first][0] = 0;
  
  int ret = 0;
  
  while(!que.empty()){
  
    Piii p = que.front(); que.pop();
  
    Pi point = p.second;
    int bit = p.first.first, time = p.first.second;
  
      
    if(ret < min_cost[point.second][point.first][bit]){
      ret = min_cost[point.second][point.first][bit];
    }
  
    for(int i = 0; i < 4; i++){
      int ny = point.second + dy[i], nx = point.first + dx[i];
      if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
  
      if(isdigit(mas[ny][nx])){
          
        int time_sell = mas[ny][nx] - '0';
  
        if(!((bit >> time_sell) & 1)){
            
          sell se = shop[time_sell];
  
          if(se.s > time){ //待ってプッシュ
            que.push( Piii( Pi( bit, se.s), point));
          } else if(se.s <= time && time < se.e){ //時間内だったら買ってみる
            int next_bit = bit | (1 << time_sell);
            if(min_cost[point.second][point.first][bit] + se.d > min_cost[point.second][point.first][next_bit]){
              que.push( Piii( Pi( next_bit, time), point));
              min_cost[point.second][point.first][next_bit] = min_cost[point.second][point.first][bit] + se.d;
            }
          }
        }
  
      } else {
        if(min_cost[point.second][point.first][bit] > min_cost[ny][nx][bit]){
          que.push( Piii( Pi( bit, time + 1), Pi( nx, ny)));
          min_cost[ny][nx][bit] = min_cost[point.second][point.first][bit];
        }
      }
    }
  }
  return ret;
}
  
int main(){
  while(cin >> w >> h, w){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> mas[i][j];
        if(mas[i][j] == 'P') p = Pi( j, i);
      }
    }
    cin >> n;
  
    for(int i= 0; i < n; i++){
      int g;
      cin >> g;
      cin  >> shop[g].d >> shop[g].s >> shop[g].e;
    }
  
    cout << bfs() << endl;
  }
}

Measured memory_bytes: 2928
#include <iostream>
#include <algorithm>


#define MAX_N 100000

int N, K, r, l;
unsigned  long int h[MAX_N], res;

int main() {
    std::cin >> N >> K;
    for (int i=0; i<N; ++i) std::cin >> h[i];
    std::sort(h, h+N);
    res = h[N-1] - h[0];
    for (r=K-1; r<N; ++r) {
        res = ( h[r]-h[l] < res) ? h[r]-h[l] : res;
        ++l;
    }
    std::cout << res << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
void init() {
  int n;
  cin >> n;
  vi a(n);
  int cnt = 0;
  for (int &i : a)
    cin >> i;
  vi b(all(a));
  for (int i = 0; i < n; i++)
    b[i] = b[i] - (i + 1);
  sort(all(b));
int  med = b[ (n-1) / 2];
// cout<<med<<endl;
int ans=0;
for(int i=0;i<n;i++){
  ans+=(abs(a[i]-(med+i+1)));
}
cout<<ans<<endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 6344
N = int(input())
A = list(map(int, input().split()))
count = 0
flag = True
while flag == True:
    for num in range(N):
        if A[num] % 2 == 0:
            A[num] /= 2
        else:
            flag = False
            count -= 1
            break
    count += 1
print(count)


Measured memory_bytes: 2940
k,s = input().split()
k=int(k)
s=int(s)

count = 0
if k < 2 or k>2500 or s<0 or s>3*k:
    print(0)
else:
    for i in range(k+1):
        for ii in range(k+1):
            temp_z = s-i-ii
            if temp_z >= 0 and temp_z <= k:
                count = count+1
print(count)

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
x=sum(a)
i=ans1=0
while True:
    if ans1<x/2 and i<n:
        ans1+=a[i]
        i+=1
    else:
        break
if i==n:
    print(2*a[i-1]-x)
else:
    i-=1
    ans2=x-ans1
    ans1-=a[i]
    print(a[i]-abs(ans1-ans2))

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    int n;
    cin >> n;
    cout << (n%2?(n/2)*((n+1)/2):(n/2)*(n/2)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int w, h, ans;
int field[20][20];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
 
void curling(int n, int x, int y) {
    if (n >= ans) {
        return;
    }
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i],
            ny = y + dy[i];
        if (nx < 0 || w <= nx || ny < 0 || h <= ny || field[ny][nx] == 1) {
            continue;
        }
        while (true) {
            if (field[ny][nx] == 3) {
                ans = n;
                return;
            }
            nx += dx[i];
            ny += dy[i];
            if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                break;
            }
            if (field[ny][nx] == 1) {
                field[ny][nx] = 0;
                curling(n + 1, nx - dx[i], ny - dy[i]);
                field[ny][nx] = 1;
                break;
            }
        }
    }
}
 
int main() {
    while (true) {
        cin >> w >> h;
        if ((w | h) == 0) {
            break;
        }
        int sx, sy;
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                cin >> field[y][x];
                if (field[y][x] == 2) {
                    sx = x;
                    sy = y;
                }
            }
        }
        ans = 11;
        curling(1, sx, sy);
        if (ans > 10) {
            ans = -1;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 998244353;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
int N, D[101010];
int C[101010];
bool dbg = false;
void solve() {
    FOR(i, 0, N) {
        C[D[i]]++;
    }
    itn ans = 1;
    int c = 1;
    FOR(i, 1, N) {
        FOR(j, 0, C[i]) {
            ans *= C[i - 1];
            ans %= MOD;
        }

        c += C[i];
        if (c == N)
            break;
    }
    ans = (ans + MOD) % MOD;
    if (D[0] != 0 || C[0] != 1) {
        cout << 0 << endl;
    } else
        cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 0, N)
    cin >> D[i];
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)

{
	int a, b, c, div, i;
	scanf ("%d %d %d", &a, &b, &c);
	for (i = a; i <= b; i++)
	{
		if (c % i ==0)
		{
			div++;
		} 
		
	}
	printf("%d\n", div);
	return 0;
 } 


Measured memory_bytes: 2752
#include <iostream>
#include <sstream>
#include <stack>

int main() {
    std::string line;
    std::getline(std::cin, line);
    std::istringstream stream(line);

    std::stack<int> stack;
    while (!stream.eof()) {
        std::string symbol;
        stream >> symbol;
        if (symbol == "+" || symbol == "-" || symbol == "*") {
            int right = stack.top();
            stack.pop();
            int left = stack.top();
            stack.pop();

            if (symbol == "+") {
                stack.push(left + right);
            } else if (symbol == "-") {
                stack.push(left - right);
            } else if (symbol == "*") {
                stack.push(left * right);
            }
        } else {
            stack.push(std::stoi(symbol));
        }
    }
    std::cout << stack.top() << std::endl;
}



Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>

int main()
{
    int n{};
    std::string s;
    std::cin >> n;
    std::cin >> s;

    long long r{}, g{}, b{};
    for (int i = 0; i < n; i++) {
        switch (s[i]) {
        case 'R': r++; break;
        case 'G': g++; break;
        case 'B': b++; break;
        }
    }
    long long result = r * g * b;
    if (result > 0) {
        for (int i = 0; i < n; i++) {
            int dist = 1;
            while (i + dist * 2 < n) {
                const auto c1 = s[i];
                const auto c2 = s[i + dist];
                const auto c3 = s[i + dist * 2];
                if (c1 != c2 && c2 != c3 && c3 != c1) result--;
                dist++;
            }
        }
    }
    std::cout << result << std::endl;
    return 0;
}


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

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            boolean flag=true;
            String str=sc.nextLine();
            if (str.equals(".")) break;
            Stack<Character> kakko=new Stack<Character>();
            for(int i=0;i<str.length();i++){
                char s=str.charAt(i);
                if(s=='(' || s=='[') kakko.push(s);
                else if(s==')'){
                    if(kakko.empty() || kakko.peek()=='['){
                        flag=false;
                        break;
                    }else kakko.pop();
                }
                else if(s==']'){
                    if(kakko.empty() || kakko.peek()=='('){
                        flag=false;
                        break;
                    }else kakko.pop();
                }
            }
            if(flag && kakko.empty()) System.out.println("yes");
            else System.out.println("no");
        }
    }
}


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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n,x;
	cin>>n;
	vector<long long int> v;
	while(n--){
		cin>>x;
		v.push_back(x);
	}
	sort(v.begin(),v.end());
	cout<<abs(v[0]-v[v.size()-1]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll prime = 998244353;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

int main() {

	ll n;
	cin >> n;
	vector<ll> d(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> d[i];
	}
	bool flag = true;
	if (d[0] != 0) {
		flag = false;
	}

	sort(d.begin(), d.end());
	if (d[1] == 0) {
		flag = false;
	}

	ll product = 1;
	ll num = 0, cand1 = 0, cand2 = 1;
	ll i = 1;
	while (i < n) {
		if (!flag) {
			break;
		}
		if (d[i] == num) {
			product *= cand1;
			product %= prime;
			cand2++;
		}
		else if (d[i] == num + 1) {
			cand1 = cand2;
			cand2 = 0;
			num++;
			product *= cand1;
			product %= prime;
			cand2++;
		}
		else {
			flag = false;
			break;
		}
		i++;
	}

	if (!flag) {
		cout << 0 << endl;
	}
	else {
		cout << product << endl;
	}


	return 0;
}


Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;


main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    int res=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++) res=res+__gcd(i,__gcd(j,k));
        }
    }
    cout<<res;
}


Measured memory_bytes: 3648
def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    for a in A:
        if a % 2 == 1:
            cnt += 1
    if cnt % 2 == 0:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 62576
#include<stdio.h>
long long int gcd(long long int N,long long int M){
  long long int t,L;
  if(M>N){
    t=N;
    N=M;
    M=t;
  }
  L=1;
  while(L>0){
    L=N%M;
    N=M;
    M=L;
  }
  return N;
}
long main(){
  int n;
  long long int i,g,l,m;
  scanf("%d",&n);
  scanf("%lld",&m);
  for(i=1;i<n;i++){
    scanf("%lld",&l);
    g=gcd(m,l);
    m=m*(l/g);
  }
  printf("%lld",m);
  return 0;
}
      


Measured memory_bytes: 128
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = list(map(int, sys.stdin.buffer.readline().split()))
    print('Alice' if (A+13)%15 > (B+13)%15 else 'Draw' if (A+13)%15 == (B+13)%15 else 'Bob')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll x,k,d,t,i,ans=INFLL,p,m;
	std::cin >> x >> k >> d;
	t = std::min(std::abs(x)/d,k);
	for(i=-50; i<=50; ++i){
		if(i+t<0ll){
			continue;
		}
		if(i+t>k){
			continue;
		}
		if(((i+t)%2)^(k%2)){
			continue;
		}
		ans = std::min(ans,std::abs(x+d*(i+t)));
		ans = std::min(ans,std::abs(x-d*(i+t)));
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, M;
    cin>>N>>M;
    vector<int> num(N);
    if (N > 1) num[0] = 1;
    vector<bool> settled(N);

    rep(i, M) {
        int s, c;
        cin>>s>>c; s--;
        if ((settled[s] && c != num[s]) || (s > N)) {
            num[0] = -1;
            break;
        }
        settled[s] = true;
        num[s] = c;
    }

    if (num[0] == -1 || (num[0] == 0 && N != 1)) cout<<-1;
    else {
        rep(i, N) cout<<num[i];
        cout<<endl;
    }
}

Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)
for i in range(1,N):
  diff = A[i] + A[i-1] - x
  if diff > 0:
    if diff <= A[i]:
      A[i] -= diff
    else:
      A[i-1] -= diff - A[i]
      A[i] = 0
print(sumA - sum(A))

Measured memory_bytes: 14060
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	H, W = getlist()
	A = []
	for i in range(H):
		a = getlist()
		A.append(a)
	B = []
	for i in range(H):
		b = getlist()
		B.append(b)

	C = [[None] * W for i in range(H)]
	for i in range(H):
		for j in range(W):
			C[i][j] = abs(A[i][j] - B[i][j])

	# print(C)
	diff = 12800
	DP = [[0] * W for i in range(H)]
	DP[0][0] = (1 << (diff + C[0][0])) | (1 << (diff - C[0][0]))
	for i in range(1, W):
		DP[0][i] = (DP[0][i - 1] << C[0][i]) | (DP[0][i - 1] >> C[0][i])
	for i in range(1, H):
		DP[i][0] = (DP[i - 1][0] << C[i][0]) | (DP[i - 1][0] >> C[i][0])

	for i in range(1, H):
		for j in range(W):
			DP[i][j] |= (DP[i][j - 1] << C[i][j]) | (DP[i][j - 1] >> C[i][j])
			DP[i][j] |= (DP[i - 1][j] << C[i][j]) | (DP[i - 1][j] >> C[i][j])

	ans = INF
	for i in range(25601):
		if DP[-1][-1] & (1 << i) == (1 << i):
			ans = min(ans, abs(diff - i))

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 58716
n = int(input())
a = list(map(int, input().split()))

flag = 1 
trade = 0
while flag:
    flag = 0
    for j in range(1, n):
        if a[j-1] > a[j]:
            a[j], a[j-1] = a[j-1], a[j]
            flag = 1
            trade += 1
print(' '.join(list(map(str, a))))
print(trade)


Measured memory_bytes: 5604
n,k,*a=map(int,open(0).read().split())
a=[0]+a
for i in range(n):a[i+1]=(a[i+1]-1+a[i])%k
d={}
c=0
for i,b in enumerate(a):
  v=d.get(b,0)
  c+=v
  d[b]=v+1
  j=i-k+1
  if j>=0:d[a[j]]=d.get(a[j],0)-1
print(c)

Measured memory_bytes: 102656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;

int main(){
  string S;
  cin>>S;
  int p=0;
  for(int i=0;i<S.length();i++){
    if(S[i]=='p') p++;
  }
  cout<<S.length()/2-p<<endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string S; cin >> S;
  string result = S[S.size()-1]=='s' ? S+"es" : S+"s";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <cfloat>
using namespace std;

int solve(vector<string>& tile)
{
    int h = tile.size();
    int w = tile[0].size();
    int sy, sx;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(tile[i][j] == '@'){
                sy = i;
                sx = j;
            }
        }
    }

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

    vector<vector<bool> > check(h, vector<bool>(w, false));
    check[sy][sx] = true;
    queue<pair<int, int> > q;
    q.push(make_pair(sy, sx));

    int ret = 0;
    while(!q.empty()){
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        ++ ret;
        for(int i=0; i<4; ++i){
            int y0 = y + dy[i];
            int x0 = x + dx[i];
            if(tile[y0][x0] == '.' && !check[y0][x0]){
                q.push(make_pair(y0, x0));
                check[y0][x0] = true;
            }
        }
    }
    return ret;
}

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            break;

        vector<string> tile(h+2);
        tile[0] = tile[h+1] = string(w+2, '#');
        for(int i=0; i<h; ++i){
            cin >> tile[i+1];
            tile[i+1] = '#' + tile[i+1] + '#';
        }

        cout << solve(tile) << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   if(a==b)cout<<c;
   else if(a==c)cout<<b;
   else cout<<a;
return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    n = int(input())
    s = list(input())
    cnt = 0
    def f(x):
        tgt = [x[0],x[1],x[2]]
        now = 0
        global n
        for i in range(n):
            if s[i] == tgt[now]:now += 1
            if now == 3:return True
        return False
    for i in range(1000):
        if len(str(i)) == 1:
            t = "00"+str(i)
        elif len(str(i)) == 2:
            t = "0"+str(i)
        else:t = str(i)
        if f(t):cnt += 1
    print(cnt)

Measured memory_bytes: 70192
#include<iostream>
#include<cstdio>
#include<vector>

#define INF 99999999999999999
#define ll long long

using namespace std;

struct edge
{
	int from;  //?????????
	int to;    //??°??????
	int cost;  //??????
};

const int MAX_N = 100;
const int MAX_M = 10000;

ll d[MAX_N][MAX_N];
edge es[MAX_M];
bool flag;

void shortest_path(int n,int m,int s)	//s???????????????????????????????????????????????¢????±???????
{
	int cnt = 0;
	d[s][s] = 0;
	while(true && cnt < n){
		bool update = false;
		for(int i=0;i<m;i++){
			edge e = es[i];
			if(d[s][e.from] != INF && d[s][e.to] > d[s][e.from] + e.cost){
				d[s][e.to] = d[s][e.from] + e.cost;
				update = true;
			}
		}
		if(!update) break;
		cnt++;
	}
	if(cnt == n){
		flag = true;
	}
}

int main()
{
	int i,n,m,s;
	cin >> n;  //????????°
	cin >> m;  //?????°
	for(int i=0;i<m;i++){
		scanf("%d",&es[i].from);
		scanf("%d",&es[i].to);
		scanf("%d",&es[i].cost);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			d[i][j] = INF;
		}
	}
	flag = false;
	for(int i=0;i<n;i++){
		shortest_path(n,m,i);
		if(flag){
			break;
		}
	}
	if(!flag){
		for(int i=0;i<n;i++){
			for(int j=0;j<n-1;j++){
				if(d[i][j] == INF){
					cout << "INF ";
				}else{
					cout << d[i][j] << " ";
				}
			}
			if(d[i][n-1] == INF){
				cout << "INF";
			}else{
				cout << d[i][n-1];
			}
			cout << "\n";
		}
	}else{
		cout << "NEGATIVE CYCLE\n";
	}
}

Measured memory_bytes: 3388
#include<bits/stdc++.h>
#define N 500005
using namespace std;
long long a[N],sum[N],n,k,disc[N],ans=0,c[N];
int lowbit(int x){return x&-x;}
void add(int x){for (int i=x;i<=n+2;i=i+lowbit(i)) c[i]++;}
int getsum(int x){int ans=0;for (int i=x;i;i=i-lowbit(i)) ans=ans+c[i];return ans;}
int main()
{
	scanf("%lld%lld",&n,&k);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]),a[i]=a[i]-k;
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i]; sum[0]=0;
	for (int i=0;i<=n;i++) disc[i]=sum[i]; sort(disc,disc+n+1);
	int tot=unique(disc,disc+n+1)-disc-1;
	for (int i=0;i<=n;i++) sum[i]=lower_bound(disc,disc+tot+1,sum[i])-disc;
	for (int i=0;i<=n;i++) sum[i]++; add(sum[0]);
	for (int i=1;i<=n;i++){ans=ans+getsum(sum[i]);add(sum[i]);} printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,l=1;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        l*=2;
    }
    cout<<(1900*m+100*(n-m))*l<<endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int,input().split())
HW = [input() for _ in range(H)]
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
print("\n".join(HW))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    int a=0,t=0,n,sz=0;
    string s;
    cin>>s;
    n=s.size();
    for(int i=0;i<n ;i++){
        if(s[i]=='T'&&!a){
            sz++;
        }
        else if(s[i]=='T'){
            a--;
        }
        else
            a++;
    }
    cout<<2*sz<<endl;
    return 0;
}



Measured memory_bytes: 720
n = int(input())
L = list(map(int,input().split()))
L.sort()
import bisect
ans = 0
for i in range(1,n):
    for j in range(i+1,n):
        tmp = L[:i]
        v = L[j]-L[i]
        idv = bisect.bisect_right(tmp,v)
        if idv!=len(tmp):
            ans += len(tmp)-idv
print(ans)



Measured memory_bytes: 79480
s = list(str(input()))
a = 0
b = 0
c = 0
for i in range(len(s)):
    if s[i] == 'a':
        a += 1
    elif s[i] == 'b':
        b += 1
    elif s[i] == 'c':
        c += 1

if a == 1 and b == 1 and c == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void){
    int X;
    cin >> X;
    int N=X;
    
    int S=0;
    for(int i=0;i<10;i++){
        S+=X%10;
        X=(X-X%10)/10;
    }
    
    if(N%S==0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	int N = s.size() - 1;
	for(int bit = 0; bit < 1 << N; bit++){
		int ans = s[0] - '0';
		for(int i = 0; i < N; i++){
			if(bit & 1 << i){
				ans += s[i + 1] - '0';
			}else{
				ans -= s[i + 1] - '0';
			}
		}
		if(ans == 7){
			cout << s[0];
			for(int i = 0; i < N; i++){
				if(bit & 1 << i){
					cout << "+";
					cout << s[i + 1];
				}else{
					cout << "-";
					cout << s[i + 1];
				}
			}
			cout << "=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
s = list(str(input()))
n = len(s)
gaki_rside = 0
gaki_lside = 0
ans = [0] * n
i = 0
while i < n-1:
    if s[i:i+2] == ['R', 'R']:
        gaki_rside += 1
        i += 1
    elif s[i:i+2] == ['R', 'L']:
        gaki_rside += 1
        for j in range(i+1, n):
            if s[j] == 'L' and j < n-1:
                gaki_lside += 1
            elif s[j] == 'L' and j == n-1:
                gaki_lside += 1
                ans[i] += (gaki_rside - (gaki_rside // 2)) + gaki_lside // 2
                ans[i+1] += gaki_rside // 2 + (gaki_lside - (gaki_lside // 2))
                i += 10 ** 6
                break
            else:
                ans[i] += (gaki_rside - (gaki_rside // 2)) + gaki_lside // 2
                ans[i+1] += gaki_rside // 2 + (gaki_lside - (gaki_lside // 2))
                i = j
                gaki_rside = 0
                gaki_lside = 0
                break
print(' '.join(map(str, ans)))

Measured memory_bytes: 11180
N = input()
ct, cx, cy = 0, 0, 0
enabled = True
for i in range(N):
    nt, nx, ny = map(int, raw_input().split())
    d = abs(nx-cx) + abs(ny-cy)
    dt = nt - ct
    enabled &= (dt >= d) and (dt % 2 == d % 2)
print "Yes" if enabled else "No"

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

int main (){
string a , b , c ;
cin >> a >> b >> c ;
char dif = 'A' - 'a';
printf ("%c%c%c",a[0] + dif,b[0]+dif,c[0]+dif);
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

struct SegmentTree {
    int N;
    vector<int> node;
    const int INF = INT_MAX;

    /*
    SegmentTree(int n_ = 0){
        init(n_);
    }
    */

    void init(int n_) {
        N = 1;
        while (N < n_) N *= 2;  // 最下段の要素数を2のべき乗にする
        node.resize(2*N-1, INF);
    }

    void init(vector<int> &dat){
        int siz = dat.size();
        N = 1;
        while (N < siz) N *= 2;
        node.resize(2*N-1, INF);
        // 最下段に値を入れたあと下から順に更新
        for(int i=0; i<siz; i++){
            node[i+N-1] = dat[i];
        }
        for(int i=N-2; i>=0; i++){
            node[i] = min(node[2*i+1], node[2*i+2]);
        }
    }

    void update(int k, int a) {
        k += N - 1; //葉の節点の番号
        node[k] = a;
        while (k > 0) { //登りながら上の要素を更新
            k = (k-1)/2;
            node[k] = min(node[k*2+1], node[k*2+2]);
        }
    }
    /*
    [a,b)の最小値を求める
    外からはquery(a,b,0,0,N)で呼ぶ
    kは節点の番号、l,rはそのk番目の節点の区間を表す
    */
    int getMin(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)
            return INF;  //[a,b)と[l,r)に共通区間がないならINF
        if (a <= l && r <= b){
            return node[k];  //[a,b)が[l,r)を完全に含むならその節点kの値
        }
        else {
            int vl = getMin(a, b, k*2+1, l, (l+r)/2);
            int vr = getMin(a, b, k*2+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree rmq;
    rmq.init(n);
    REP(i,q){
        int a, b, c;
        cin >> a >> b >> c;
        if(a){
            cout << rmq.getMin(b, c+1, 0, 0, rmq.N) << endl;
        }
        else{
            rmq.update(b, c);
        }
    }
    return 0;
}


Measured memory_bytes: 3888
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    string S;
	cin >> S;

	int maxCount = 0;
	int count = 0;
	for (size_t i = 0; i < S.length(); i++)
	{
		if (S[i] == 'R')
		{
			count++;
			maxCount = max(maxCount, count);
		}
		else
		{
			count = 0;
		}
	}
	

	cout << maxCount << endl;

	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N, K; cin >> N >> K;
    vector<int> h(N);
    int ans = 1000000000;
    for(int i=0; i<N; i++) cin >> h[i];
    sort(h.begin(), h.end());

    for(int i=0; i<N-K+1; i++){
        ans = min(ans, h[i+K-1]-h[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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 long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int n; string s;
int main() {
	cin >> n >> s; int ans = 0;
	rep(i, n) {
		string t; cin >> t;
		bool exi = false;
		for (int i = 0; i < t.size(); i++) {
			for (int j = 1; j < t.size(); j++) {
				string u;
				for (int k = i; k < t.size(); k += j) {
					u.push_back(t[k]);
				}
				if (u.length() < s.length())continue;
				if (u.substr(0, s.length()) == s)exi = true;
			}
		}
		if (exi)ans++;
	}
	cout << ans << endl;
	//stop
	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
const int maxn = 105;
char mp[maxn][maxn];
int dp[maxn][maxn];
int main(int argc, char const *argv[])
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n; ++i)
	{
		scanf("%s",mp[i] + 1);
	}
	for(int i = 0;i < maxn; ++i)
	{
		dp[i][0] = dp[0][i] = 0x3f3f3f3f;
	}
	dp[1][0] = dp[0][1] = 0;
	for(int i = 1;i <= n; ++i)
	{
		for(int j = 1;j <= m; ++j)
		{
			if(mp[i][j] == '#')
			{
				dp[i][j] = min(dp[i - 1][j] + (mp[i][j] != mp[i - 1][j]),dp[i][j - 1] + (mp[i][j] != mp[i][j - 1]));
			}
			else
			{
				dp[i][j] = min(dp[i - 1][j],dp[i][j - 1]);
			}
		}
	}
	printf("%d\n",dp[n][m]);
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
# print(maze)

blacks = []
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            blacks.append((i, j))
# print(blacks)

count = 0
while len(blacks) != 0:
    count += 1
#     print(blacks)
    nexts = []
    for x, y in blacks:
        for nx, ny in [(x-1, y), (x+1,y), (x,y-1),(x,y+1)]:
            if 0<=nx<H and 0<=ny<W and maze[nx][ny] == '.':
                maze[nx][ny] = '#'
                nexts.append((nx, ny))
#     print(maze)
    blacks = nexts
    
print(count-1)

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

int main(){
  int N; cin>>N;
  ll A[N]; rep(i,N) cin>>A[i];
  sort(A,A+N);
  ll ans=0;
  while(A[N-1]>2*N){
    ll k=max(1LL,(A[N-1]-2*N)/N);
    A[N-1]-=k*N;
    rep(i,N-1) A[i]+=k;
    sort(A,A+N);
    ans+=k;
  }
  while(A[N-1]>=N){
    A[N-1]-=N;
    rep(i,N-1) A[i]++;
    sort(A,A+N);
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M;
int a[100010], b[100010], c[100010];
int cnt[200010], rec[200010];



signed main() {
    cin >> N >> M;
    rep(i,0,N) {
        cin >> a[i];
    }
    int sum = 0;
    rep(i,0,N-1) {
        int x = a[i] + 1, y = a[i+1];
        if(x > y) y += M;
        int d = y - x;
        sum += d + 1;
        cnt[x]++; cnt[y]--; rec[y] -= d;
    }

    rep(i,1,2*M+2) {
        cnt[i] += cnt[i-1];
        // printf("#index = %lld, cnt = %lld, rec = %lld\n", i, cnt[i], rec[i]);
    }

    rep(i,1,2*M+2) rec[i] += (cnt[i] + rec[i-1]);

    rep(i,0,2*M+2) {
        // printf("index = %lld, cnt = %lld, rec = %lld\n", i, cnt[i], rec[i]);
    }

    int ans = INF;
    repq(i,1,M) {
        int temp = rec[i] + rec[i+M];
        chmin(ans, sum - temp);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int n;
    cin >> n;
    set<string> st;
    rep(i, n)
    {
        string s;
        cin >> s;
        st.insert(s);
    }

    OP(st.size());
    return 0;
}

Measured memory_bytes: 19260
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define fi first
#define se second
using namespace std;
static const int inf = 1ll<<60;
typedef pair<int,int> pii;

signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    int sum=a*b*c;
    int red1=c/2*a*b;
    int red2=a/2*b*c;
    int red3=b/2*a*c;
    int blue1=sum-red1;
    int blue2=sum-red2;
    int blue3=sum-red3;
    cout<<min(abs(red1-blue1),min(abs(red2-blue2),abs(red3-blue3)))<<endl;
}


Measured memory_bytes: 256
from math import cos,sin,pi,sqrt
A,B,H,M = map(int,input().split())
m = 60*H + M
x = [A*cos(2*pi*m/(12*60)),B*cos(2*pi*m/60)]
y = [A*sin(2*pi*m/(12*60)),B*sin(2*pi*m/60)]
##print(x,y)
print(sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))

Measured memory_bytes: 9588
package main

import "fmt"

func main() {
	var N, A, B int
	var S string
	fmt.Scan(&N, &A, &B, &S)
	x := 0
	y := 0
	for i := 0; i < len(S); i++ {
		switch string(S[i]) {
		case "a":
			if x < A+B {
				fmt.Println("Yes")
				x++
			} else {
				fmt.Println("No")
			}
		case "b":
			y++
			if x < A+B && y <= B {
				fmt.Println("Yes")
				x++
			} else {
				fmt.Println("No")
			}
		case "c":
			fmt.Println("No")
		}
	}
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		if (n == 1) {
			System.out.println(1);
			return;
		}

		int ans = 1;
		int base = 0;
		for (int i = 1; i < n; i++) {
			int d = a[i] - a[i - 1];
			if (d > 0) {
				if (base < 0) {
					ans++;
					base = 0;
				} else {
					base = 1;
				}
			} else if (d < 0) {
				if (base > 0) {
					ans++;
					base = 0;
				} else {
					base = -1;
				}
			}
		}
		System.out.println(ans);
	}
}


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

set<int> hamming;
void make_hamming() {
  hamming.insert(1);
  for(int i=0; i<100; i++) {
    for(int j=0; j<100; j++) {
      for(int k=0; k<100; k++) {
	int temp = pow(2.0, i)*pow(3.0, j)*pow(5.0, k);
	hamming.insert(temp);
      }
    }
  }
}

int main() {
  make_hamming();
  int m, n;
  while(cin >> m >> n && m) {
    set<int>::iterator it = hamming.begin();
    int cnt = 0;
    for(it; it!=hamming.end(); it++) {
      if(m<=*it && *it <=n) cnt ++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

template< typename T >
struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(g.size(), INF);

    using Pi = pair< T, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]) {
            auto next_cost = cost + e.cost;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}


signed main() {
    int N;
    cin >> N;
    WeightedGraph<int> G(N + 1);
    for (int i = 0; i < N - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    int Q, K;
    cin >> Q >> K;
    auto dist = dijkstra(G, K);
    for (int i = 0; i < Q; i++) {
        int x, y;
        cin >> x >> y;
        cout << dist[x] + dist[y] << endl;
    }
}

Measured memory_bytes: 12464
p=int(input())
alist=list(map(int,input().split()))

fact_list=[1]
fact_inv_list=[1]
for i in range(1,p):
  fact=(fact_list[-1]*i)%p
  fact_list.append(fact)
  fact_inv_list.append(pow(fact,p-2,p))
def comb_mod(n,r):
  return fact_list[n]*fact_inv_list[r]*fact_inv_list[n-r]
  
answer_list=[0]*p
for i in range(p):
  a=alist[i]
  if a==1:
    #1-(x-i)^(p-1)
    coeff_list=[0]*p
    coeff_list[0]=1
    for j in range(p):
      coeff=comb_mod(p-1,j)*pow(-i,p-1-j,p)
      coeff_list[j]-=coeff
      coeff_list[j]%=p
      
    #print(i,coeff_list)
    for i in range(p):
      answer_list[i]+=coeff_list[i]
      answer_list[i]%=p
      
print(*answer_list)

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

char s[5];
int  main() {
    scanf("%s", &s);
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    if (a - b - c - d == 7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
    else if (a - b - c + d == 7) printf("%d-%d-%d+%d=7\n ", a, b, c, d);
    else if (a - b + c - d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a - b + c + d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a + b - c - d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a + b - c + d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a + b + c - d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a + b + c + d == 7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    std::sort(std::begin(A), std::end(A));

    if (N % 2 == 0) {
        // 偶数
        for (int64_t i = 0; i < N; i += 2) {
            if ((A[i] != A[i+1]) || A[i] != i+1) {
                std::cout << 0 << std::endl;
                return 0;
            }
        }
    }
    else {
        // 奇数
        if (A[0] != 0) {
            std::cout << 0 << std::endl;
            return 0;
        }

        for (int64_t i = 1; i < N; i += 2) {
            if ((A[i] != A[i+1]) || A[i] != i+1) {
                std::cout << 0 << std::endl;
                return 0;
            }
        }

        N--;
    }

    int64_t ans = 1;
    for (int64_t i = 0 ; i < N/2; ++i) {
        ans *= 2;
        ans %= DIV1097;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1400