akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
// 设dp[i][j] 表示 “只考虑前 i 个物品的情况下，背包容量是 j 所能凑出的最大价值之和”。
// dp[i][j] = max(v_s[i] + dp[i-1][j-w_s[i], dp[i-1][j])
// dp[i][j+1] =
int main() {
    int N,W;
    std::cin >> N >> W;
    std::vector<int> w_s(N, 0);
    std::vector<long long> v_s(N, 0);

    for (int i=0;i<N;i++) {
        std::cin >> w_s[i] >> v_s[i];
    }

    std::vector<std::vector<long long>> dp;
    dp.resize(N);
    for (int i=0;i<N;i++) {
        dp[i].resize(W+1);
    }

    for (int j=0;j<=W;j++) {
        if (j >= w_s[0]) {
            dp[0][j] = v_s[0];
        } else {
            dp[0][j] = 0;
        }
    }

    for (int i=1;i<N;i++) {
        for (int j=0;j<=W;j++) {
            if (j >= w_s[i]) {
                dp[i][j] = std::max(v_s[i] + dp[i-1][j-w_s[i]], dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    std::cout << dp[N-1][W] << std::endl;
    return 0;
}

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

int main(void){
    double a,b,c,d,e,f;
    double ansX,ansY;
    while(std::cin >> a >> b >> c >> d >> e >> f){
        ansX = (c*e - b*f) / (a*e - b*d);
        ansX *= 1000;
        if(ansX > 0) 
            ansX += 0.5;
        else 
            ansX -= 0.5;
        ansX = int(ansX);
        ansX /= 1000;
        
        ansY = (a*f - c*d) / (a*e - b*d);
        ansY *= 1000;
        if(ansY > 0) 
            ansY += 0.5;
        else
            ansY -= 0.5;
        ansY = int(ansY);
        ansY /= 1000;
        
        std::cout <<fixed << setprecision(3) << ansX << " " << fixed << setprecision(3)<<ansY << std::endl;
    }
    
    return 0;
}

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

using pint = pair<int, int>;
int N;
vector<vector<pint>> v;

bool judge(int bit) { 
    for (int i = 0; i < N; i++){
      if (!(bit & (1 << i))) continue;
      for(pint xy : v[i]){
        int x = xy.first;
        int y = xy.second;
        if (y == 1 && !(bit & (1 << x))) return false;
        if (y == 0 && (bit & (1 << x))) return false;
      }
    }
    return true;
}

int main() {
  cin >> N;
  v.resize(N);
  for (int i = 0; i < N; i++){
    int A;
    cin >> A;
    v[i].resize(A);
    for (int j = 0; j < A; j++){
      cin >> v[i][j].first >> v[i][j].second;
      --v[i][j].first;
    }
  }

  int out = 0;
  for (int bit = 0; bit < (1 << N); bit++){
      if(judge(bit)){
        int count = 0;
        for (int i = 0; i < N; i++){
            if(bit&(1<<i)) count++;
        }
        out = max(out, count);
      }
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 3472
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i< n ;i++){
        cin >> a[i];
    }
    ll ans = 0;
    for(int i = 0; i< 60; i++){
        ll x = 0, y = 0;
        for(int j = 0; j< n; j++){
            if(a[j]>>i&1) x++;
            else y++;
        }
        ll total = 0;
        total = (x * y) % mod;
        for(int j = 0; j< i; j++){
            total = total * 2 % mod;
        }
        ans += total;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	bool arr[(int)1e6+1]={};
	int N,ipt[(int)2e5];
	cin>>N;
	for(int i=0; i<N; i++)cin>>ipt[i];
	sort(ipt,ipt+N);
	int cnt=0;
	for(int i=0; i<N-1; i++){
		if(arr[ipt[i]]==0){
			if(ipt[i]!=ipt[i+1])cnt++;
			for(int j=ipt[i]; j<=ipt[N-1]; j+=ipt[i])arr[j]=1;
		}
	}if(arr[ipt[N-1]]==0)cnt++;
	cout<<cnt<<'\n';
}

Measured memory_bytes: 5404
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279


void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}
int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main(void){
	int n,T;
	int c[101], t[101];
	int min=0;
	scanf("%d %d", &n, &T );
	for(int i=0;i<n;i++)	scanf("%d %d", &c[i], &t[i]);
	
	
	for(int i=1;i<n;i++){
		if(t[i]<=T && c[i]<c[min])	min = i;
	}
	if( min==0 && t[min]>T) printf("TLE");
	else printf("%d", c[min]);
	
	return 0;
}


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

public class Main {

  public static void main(String[] args) {

    int n = 0;
    String[] lineOne = null;
    String[] lineTwo = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      n = Integer.parseInt(br.readLine());
      lineOne = br.readLine().split("\\s");
      lineTwo = br.readLine().split("\\s");
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = 0; j <= i; j++) {
        sum += Integer.parseInt(lineOne[j]);
      }
      sum += Integer.parseInt(lineTwo[i]);
      for (int l = i + 1; l <= n - 1; l++) {
        sum += Integer.parseInt(lineTwo[l]);
      }
      max = Math.max(max, sum);
    }
    System.out.print(max);
  }
}


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

int main()
{
    int N;
    cin >> N;
    if ( N == 1 )
    {
        cout << '1' << endl;
        return 0;
    }
    vector<long long> L(N);
    L.at(0) = 2;
    L.at(1) = 1;
    for ( int i = 2 ;i <= L.size() - 1; ++i)
    {
        L.at(i) = L.at(i - 1) + L.at(i - 2);  
    }
    cout << L.at(N - 1) + L.at(N - 2) << endl;
    return 0; 
}

Measured memory_bytes: 256
// arc088-c
object Main extends App {
  val Array(x, y) = io.StdIn.readLine.split(" ").map(_.toLong)

  def solve(acc: Long, count: Int): Int =
    if (y < acc) count
    else solve(acc*2, count+1)
  
  val result = solve(x, 0)
  println(result)
}

Measured memory_bytes: 54764
#!/usr/bin/env python

def main():
    n = int(input())
    cnt = [0,0,0,0]

    for _ in range(n):
        judge = input()
        if judge == 'AC':
            cnt[0] += 1
        elif judge == 'WA':
            cnt[1] += 1
        elif judge == 'TLE':
            cnt[2] += 1
        elif judge == 'RE':
            cnt[3] += 1

    print('AC x', cnt[0])
    print('WA x', cnt[1])
    print('TLE x', cnt[2])
    print('RE x', cnt[3])

if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<string> s(N);
    int output = 0;
    int a = 0;
    int b = 0;
    int both = 0;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        for (int j = 0; j < s[i].length() - 1; j++) {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B') output++;
        }
        if (s[i][0] == 'B') b++;
        if (s[i][s[i].length() - 1] == 'A') a++;
        if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') both++;
    }

    if (a == both && b == both && both != 0) {
        a--;
    }
    cout << output + min(a, b) << endl;

    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int GCD(int a, int b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int main()
{
  int n,x;
  cin >> n >> x;
  vector<int> xx(n);
  REP(i,n){
    cin >> xx[i];
    xx[i] = abs(x-xx[i]);
  }
  int gcd = GCD(xx[0], xx[1]);
  FOR(i,2,n){
    gcd = GCD(gcd, xx[i]);
  }
  cout << gcd << endl;
  return 0;
}


Measured memory_bytes: 640
use proconio::input;
use proconio::fastout;

#[fastout]
fn main(){

    input!(
        n: usize,
        x: usize,
        t: usize,
);

    let ans = if n%x == 0 {
       n/x
    }else{
         n / x + 1
    };

    println!("{}",ans*t);


}

Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >> n;
	ll l;
	ll ans = 1;
	rep(i, 0, n) {
		cin >> l;
		ans = ans / __gcd(ans, l) * l;
	}
	cout << ans;
	return 0;
}


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

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, S.size()) if (S[i] == T[i]) ans++;
    cout << ans << endl;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;


#define rep(i,n) for(ll i=0;i<n;i++)



int main() {


  cout<<fixed<<setprecision(10);

  double x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;

  cout<<sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))<<endl;

}




//







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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  i64 n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) cout << 1 << "\n";
  else if (n == 1) cout << m - 2 << "\n";
  else if (m == 1) cout << n - 2 << "\n";
  else cout << (n - 2) * (m - 2) << "\n";

  return 0;
}


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

int main(){
    int n;
    int max=0;
    int sum=0;
    int num=0;
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>num;
        sum+=num;
        if(max<num)
            max=num;
    }


    if(sum>2*max)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {

	/* --------------------------------------------------------------------
	   main
	 * -------------------------------------------------------------------- */
	public static void main(String args[]) throws Exception {

		// ----- input -----
		Input input = new Input();
		final Data l = input.readLine();
		final int n = l.col[0];
		Queue<Integer> q = input.getColQueue();
		input.close();

		// ----- main -----
		int min = q.poll();
		int max = min;
		while(!q.isEmpty()) {
			max = q.poll();
		}

		System.out.println(max - min);
	}

	/* --------------------------------------------------------------------
	 * inupt class
	 * -------------------------------------------------------------------- */
	static class Input {

		public BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		public void close() throws Exception {
			input.close();
		}

		public Data readLine() throws Exception {
			return new Data(input.readLine().split(" "));
		}

		public Queue<Integer> getColQueue() throws Exception {

			Data d = readLine();
			PriorityQueue<Integer> q;
			q = new PriorityQueue<>( (a,b) -> a - b);	// 昇順
			for(int i=0; i < d.col.length; i++) {
				q.offer(d.col[i]);
			}
			return q;
		}
	}
	/* --------------------------------------------------------------------
	 * data class
	 * -------------------------------------------------------------------- */
	static class Data{
		public int[] col;
		public Data(String[] values) {
			col = new int[values.length];
			for(int i=0; i < values.length; i++) {
				col[i] = Integer.parseInt(values[i]);
			}
		}
	}
}

Measured memory_bytes: 29396
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

int rec(int n, int k){
    if(n < k)return 0;
    if(n == k)return 1;
    if(k == 0)return 1;
    return rec(n - 1,k) + rec(n - 1, k - 1);
}
ll sum(ll n){
    return n * (n + 1) / 2;
}
void test(){
    for(int i = 1; i <= 100; ++i){
        int n = i;
        int one = n * (n + 3) / 6;
        int two = sum(n/3) * 3;
        if(one != two){
            debug(n);
            debug(one);
            debug(two);
            throw;
        }
    }
}
int main(int argv, char **argc){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n;
    cin >> n;
    ll a = (n * (n + 3) / 6) + (n * (n + 5) / 10) - (n * (n + 15) / 30);
    ll a1 = sum(n/3)*3 + sum(n/5)*5 - 15*sum(n/15);
    ll b = n * (n + 1) / 2;
    cout << b - a1 << endl;
}


Measured memory_bytes: 3588
n,k=map(int,input().split())
d=list(map(int,input().split()))
while 1:
  hantei=0
  for i in range(len(str(n))): 
    #print(str(n)[i])
    if int(str(n)[i]) in d: #1つでも嫌いな数字がある場合はその瞬間判定1にして次の数へ
      hantei=1
      break
  if hantei==0: #嫌いな数字がない場合はその数字が正解なのでbreak
    break
  n+=1
print(n)

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<ll> L(N);
  REP(i, N){
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  int ans = 0;
  REP(i, N-2){
    for(int j = i+1; j < N-1; j++){
      for(int k = j+1; k < N; k++){
        if(L[i]+L[j] > L[k] && L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    ll n,m,ans=0;
    scanf("%lld%lld",&n,&m);
    // ll [n];
    // for(i=0;i<n;i++){
        // scanf("%lld",&[i]);
    // }
    ans=( (n-m)*100 + m*1900) * pow(2,m);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;
  cin >> a>> b;
  cout<<lcm(a,b)<<endl;
}
    

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

l,r,d = lr()
mind = l//d
if l%d == 0:
    mind-=1
maxd = r//d
print(maxd-mind)

Measured memory_bytes: 72640
import itertools
N = int(input())
a = [0] * 5
for _ in range(N):
    s = input()[0]
    if s == 'M':
        a[0] += 1
    elif s == 'A':
        a[1] += 1
    elif s == 'R':
        a[2] += 1
    elif s == 'C':
        a[3] += 1
    elif s == 'H':
        a[4] += 1
count = 0
for i, j, k in itertools.combinations(range(5), 3):
    count += a[i] * a[j] * a[k]
print(count)

Measured memory_bytes: 3064
#include<stdio.h>
int a[1000001],b[1000001],c[1000001],p[1000001],x[1000001];
int main(void)
{
	long long int n,m,s,sum,i;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=m;i++) scanf("%d",&p[i]);
	for(i=1;i<n;i++) scanf("%d%d%d",&a[i],&b[i],&c[i]);
	for(i=1;i<m;i++){
		if(p[i]<p[i+1]){
			x[p[i]]++; x[p[i+1]]--;
		}
		if(p[i]>p[i+1]){
			x[p[i]]--; x[p[i+1]]++;
		}
	}
	s=0; sum=0;
	for(i=1;i<=n;i++){
	//printf("s=%d sum=%d\n",s,sum);
		s+=x[i];
		if(a[i]*s<b[i]*s+c[i]) sum+=a[i]*s;
		else sum+=b[i]*s+c[i];
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	if (a + b == 15){
		cout << '+' << endl;
	}else
	if (a * b == 15){
		cout << '*' << endl;
	}else{
		cout << 'x' << endl;
	} // end if

	return 0;
}

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

int main(){
    int n;
    while(cin >> n, n){
        n = 1000 - n;
        int ans = n/500+n%500/100+
            n%100/50+n%50/10+
            n%10/5+ n%5;
        cout << ans << endl;
    }
    return 0;
}
    


Measured memory_bytes: 3052
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> c(n + 1);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        c[a]++;
        c[b]++;
    }
    for(auto &x : c){
        if(x & 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n;
	cin>>n;
	if(n%2==0){cout<<n;}
	else cout<<2*n;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

using namespace std;

int main()
{
	int n, k;
	int a;

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

	if((n - 1) % (k - 1) == 0) {
		cout << (n - 1) / (k - 1) << endl;
	} else {
		cout << (n - 1) / (k - 1) + 1 << endl;
	}

}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    int n;
    cin>>n;

    VVi to(n);

    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--,b--;
        to[a].pb(b);
        to[b].pb(a);
    }
    Vi c(n);
    rep(i,n)cin>>c[i];
    sort(ALL(c));
    reverse(ALL(c));

    int ans = 0;

    rep(i,n){
        if(i==0)continue;
        ans += c[i];
    }

    priority_queue<int, vector<Pi>, function<bool(Pi, Pi)>> q([](Pi a, Pi b)->int {
        return a.first>b.first;
    });
    //q fi rank se 接点

    q.push(mp(0,0));

    vector<Pi> pos; // fi 接点 se 割当


    Vi parent(n,-1);

    cout<<ans<<endl;
    int cnt = 0;
    while (!q.empty()){
        Pi now = q.top();
        q.pop();
        pos.emplace_back(now.se,c[cnt]);
        cnt++;
        Each(v,to[now.se]){
            if(v==parent[now.se])continue;
            parent[v]=now.se;
            q.push(mp(now.first+1,v));
        }
    }

    sort(ALL(pos));
    rep(i,n){
        cout<<pos[i].se<<" ";
    }
    cout<<endl;

    return  0;
}


Measured memory_bytes: 1280
import sys
import numpy as np


def main():
    s = input()
    n = len(s)
    if (s[0] == s[n - 1] and n % 2 == 1) or (s[0] != s[n - 1] and n % 2 == 0):
        print("Second")
    else:
        print("First")


main()


Measured memory_bytes: 12648
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=1<<26;

int H,W,h,w;

int main(){
	cin>>H>>W>>h>>w;
	if(H%h==0&&W%w==0){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(j) cout<<' ';
			int A=1;
			if(i%h==h-1&&j%w==w-1) A=-h*w;
			if(i==h-1){
				if(j%w==0) A+=M;
				if(j%w==w-1) A-=M;
			}
			if(j==w-1){
				if(i%h==0) A+=M;
				if(i%h==h-1) A-=M;
			}
			cout<<A;
		}
		cout<<endl;
	}
}

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

int main() {
	int N;
	cin >> N;
	vector<int> vec1(N), vec2(N);
	for (int i = 0; i < N; i++)
		cin >> vec1.at(i);
	for (int i = 0; i < N; i++)
		cin >> vec2.at(i);
	int ans, Mans;
	ans = Mans = 0;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			for (int j = 0; j < N; j++)
				ans += vec1.at(j);
			ans += vec2.at(N - 1);
		}
		else ans += (vec2.at(N - i - 1) - vec1.at(N - i));
		Mans = max(Mans, ans);
	}
	cout << Mans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int* p, * q;
	p = new int[n];
	q = new int[n];
	int x=0;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < n - 1; i++) {
		q[i] = p[i] - p[i + 1];
	}
	for (int i = 1; i < n - 1; i++) {
		if (q[i - 1] * q[i] > 0) {
			x++;
		}
	}
	cout << x;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Dice {
public:
    int label1;
    int label2;
    int label3;
    int label4;
    int label5;
    int label6;

    Dice() {
        label1 = 0;
        label2 = 0;
        label3 = 0;
        label4 = 0;
        label5 = 0;
        label6 = 0;
    }

    void setValue(int n, int l) {
        switch (l) {
        case 1: label1 = n; break;
        case 2: label2 = n; break;
        case 3: label3 = n; break;
        case 4: label4 = n; break;
        case 5: label5 = n; break;
        case 6: label6 = n; break;
        default: break;
        }
    }

    void roll(char c) {
        int a = label1;
        int b = label2;
        switch (c) {
        case 'N':            
            label1 = label2;
            label2 = label6;
            label6 = label5;
            label5 = a;                
            break;
        case 'S':
            label1 = label5;
            label5 = label6;
            label6 = label2;
            label2 = a;
            break;
        case 'W':
            label1 = label3;
            label3 = label6;
            label6 = label4;
            label4 = a;
            break;
        case 'E':
            label1 = label4;
            label4 = label6;
            label6 = label3;
            label3 = a;
            break;
        case 'R':
            label2 = label3;
            label3 = label5;
            label5 = label4;
            label4 = b;
            break;
        default: 
            break;
        }
    }
};

int main()
{
    Dice DiceA;

    for (int i = 0; i < 6; i++) {
        int n = 0;
        cin >> n;
        DiceA.setValue(n, i + 1);
    }

    // Ver.1
    //string str;
    //cin >> str;
    //if (str.empty()) return 1;
    //int nSize = (int)str.size();
    //for (int i = 0; i < nSize; i++) {
    //    char c = str[i];
    //    DiceA.roll(c);
    //}

    //cout << DiceA.label1 << endl;

    // Ver.2
    int Q; 
    cin >> Q;
    if (Q<1||Q>24) return 1;

    for (int i = 0; i < Q; i++) {
        int q1{ 0 }, q2{ 0 };
        cin >> q1 >> q2;

        if (DiceA.label3 == q1) DiceA.roll('W');
        if (DiceA.label4 == q1) DiceA.roll('E');
        while (DiceA.label1!=q1) {
            DiceA.roll('N');
        }
        while (DiceA.label2 != q2) {
            DiceA.roll('R');
        }
        cout << DiceA.label3 << endl;
    }
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt() == 0 ? 1 : 0;
		System.out.println(a);
	}
}


Measured memory_bytes: 35680
from itertools import product
N = int(input())
dig = len(str(N))
ans = 0
for i in range(3,dig+1):
    for a in product('357',repeat=i):
        num = int("".join(a))
        if num > N:
            continue
        s = set(a)
        if not '3' in s:
            continue
        if not '5' in s:
            continue
        if not '7' in s:
            continue
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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


int N, K;
ll v[60];

int main () {
  cin >> N >> K;
  Rep(i, N) cin >> v[i];

  int m = min(N, K);

  ll ans = 0;

  for (int l=0;l<=m;++l) {
    for (int r=0;r<=m-l;++r) {
      priority_queue<ll, vector<ll>, greater<ll>> que;
      ll tmp = 0;

      Rep(i, l) {
        que.push(v[i]);
        tmp += v[i];
      }
      Rep(j, r) {
        que.push(v[N-1-j]);
        tmp += v[N-1-j];
      }

      Rep(s, K-l-r) {
        if (que.empty()) {
          break;
        }
        //cout << que.top() << "\n";
        ll top = que.top();
        if (top >= 0) {
          break;
        } 
        que.pop();
        tmp -= top;
      }

      ans = max(ans, tmp);
      //cout << l << " " << r << "\n";
      //cout << ans << "\n";
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		BitSet a = new BitSet(M);
		a.flip(0, M);

		for (int i = 0; i < N; i++) {
			int K = sc.nextInt();
			BitSet x = new BitSet(M);
			for (int j = 0; j < K; j++) {
				x.set(sc.nextInt() - 1); // 入力は1オリジンなので1引く
			}
			a.and(x);
		}

		out.println(a.cardinality());

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

int max(int a,int b){
    int ans;
    if(a>b)ans=a;
    else ans=b;
    return ans;
}

int LCSLength(char *X,char *Y){
    int i,j,m,n;
    int mx=0;
    int c[1001][1001];
    m=strlen(X);
    n=strlen(Y);
    for(i=1;i<=m;i++)c[i][0]=0;
    for(j=0;j<=n;j++)c[0][j]=0;
    for(i=1;i<=m;i++){
        for(j=1;j<=n;j++){
            if(X[i-1]==Y[j-1])c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=max(c[i-1][j],c[i][j-1]);
            mx=max(mx,c[i][j]);
        }
    }
    return mx;
}

int main(){
    int n,i,ans[1000]={};
    char a[1000],b[1000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s%s",a,b);
        ans[i]=LCSLength(a,b);
    }
    for(i=0;i<n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}



Measured memory_bytes: 5644
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main(){
  int A,B,count = 0;
  cin >> A >> B;
  for(int i = A;i <= B;++i){
    int n = i;
    vector<int> a,b;
    while(n > 0){
      a.push_back(n%10);
      n /= 10;
    }
    b = a;
    reverse(a.begin(),a.end());
    if(a == b) count++;
  }
  cout << count <<endl;
  return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s;
    cin >> s;

    int num = s.size();

    int ans = 0;
    ans += 9 * (num - 1);
    if(s[0] != 0) ans += s[0] - '0' - 1;

    int cnt = 0;
    REP(i, num) if (s[i] == '9') cnt++;
    if (cnt == num) ans = 9 * num;

    if (num == 1) ans = stoi(s);

    string t = s.substr(1, s.size());
    cnt = 0;
    REP(i, num - 1) if (t[i] == '9') cnt++;
    if (cnt == num - 1) {
        ans = 9 * (num - 1);
        ans += s[0] - '0';
    }

    cout << ans << '\n';
    return 0;
}


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

    int n;
    cin>>n;
    int a[n];

    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    int ans = 1e9;
    for(int i=-100; i<=100; i++){

        int sum=0;

        for(int j=0; j<n; j++){
            sum+=(a[j]-i)*(a[j]-i);
        }
       ans=min(ans,sum);
    }

    cout<<ans<<endl;

    return 0;
}


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

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

Measured memory_bytes: 256
//Zory-2018
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
using namespace std;

namespace mine
{
	typedef long long ll;
	const int INF=0x3f3f3f3f;

	int n;

	const int MAX_N=110000;
	struct Nod
	{
		ll d;int p,siz;
		friend bool operator < (Nod a,Nod b) {return a.d<b.d;}
	}p[MAX_N];

	#define PR pair<int,int>
	vector<PR> ans;

	int hou[MAX_N];
	struct Edge{int y,g;}e[MAX_N*2];
	int ln=0;
	void ins(int x,int y)
	{
		e[++ln]=(Edge){y,hou[x]};hou[x]=ln;
	}
	ll f[MAX_N];
	void dfs(int x,int fa,int dis)
	{
		f[x]=dis;
		for(int k=hou[x];k>0;k=e[k].g)
		{
			int y=e[k].y;if(y==fa) continue;
			dfs(y,x,dis+1);
		}
	}
	void main()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%lld",&p[i].d),p[i].p=i,p[i].siz=1;
		sort(p+1,p+n+1);

		for(int i=n;i>=2;i--)
		{
			ll want=p[i].d-n+2*p[i].siz;
			int fa=lower_bound(p+1,p+n+1,(Nod){want,0,0})-p;//互不相同
			if(p[fa].d!=want or fa==i) {puts("-1");return;}
			ins(p[i].p,p[fa].p);ins(p[fa].p,p[i].p);
			ans.push_back( make_pair(p[i].p,p[fa].p) );
			p[fa].siz+=p[i].siz;
		}
		dfs(1,0,0);
		ll rt=0,rt2=0;for(int i=1;i<=n;i++) {rt+=f[i];if(p[i].p==1) rt2=p[i].d;}
		if(rt!=rt2) {puts("-1");return;}
		for(int i=0;i<(int)ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
	}
}
int main()
{
	mine::main();
}


Measured memory_bytes: 11380
#include <iostream>
#include <vector>
#include <queue>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int MAX_N = 100;
vector<int> G[MAX_N];
vector<bool> seen(MAX_N, false);

int main()
{
    int N;
    cin >> N;
    rep(i, N)
    {
        int id, u;
        cin >> id >> u;
        rep(j, u)
        {
            int target;
            cin >> target;
            target--;
            G[i].push_back(target);
        }
    }

    // 最短距離を算出
    queue<int> que;
    que.push(0);

    int distance = 0;
    int d[N];
    fill_n(d, N, -1);
    d[0] = 0;
    seen[0] = true;
    while (!que.empty())
    {
        int origin = que.front();
        int distance = d[origin];
        que.pop();
        for (int target : G[origin])
        {
            if (!seen[target])
            {
                seen[target] = true;
                d[target] = distance + 1;
                que.push(target);
            }
        }
    }

    rep(i, N)
    {
        int id = i + 1;
        cout << id << " " << d[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

vector<int> C(1001);
int L=1000000007;
void D(int n) {
  if (n<=1) {
    return;
  }
  for (int i=2; i*i<=n; i++) {
    while (n%i==0) {
      n=n/i;
      C[i]++;
    }
  }
  if (n>1) {
    C[n]++;
  }
}

int main() {
  int N;
  cin >> N;
  for (int i=2; i<=N; i++) {
    D(i);
  }
  long long ans=1;
    for (int i=2; i<=1000; i++) {
    ans=ans*(C[i]+1);
    ans=ans%L;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
from subprocess import call
call(('pypy3','-c',"""
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
dy=[0,0,1,-1]
dx=[1,-1,0,0]
m=[[-1]*W for i in range(H)]

from collections import deque
q=deque()
for y in range(H):
  for x in range(W):
    if A[y][x]=='#':
      q.append((y,x))
      m[y][x]=0      
      
def bfs(q,m):
  d=0
  while q:
    y,x=q.popleft()
    d=m[y][x]
    for i in range(4):
      ny=y+dy[i]
      nx=x+dx[i]
      if 0<=ny<H and 0<=nx<W and m[ny][nx]==-1 and A[ny][nx]!='#':
        q.append((ny,nx))
        m[ny][nx]=m[y][x]+1            
bfs(q,m)
ans=0
for i in range(H):
  for j in range(W):
    ans=max(ans,m[i][j])    
print(ans)     
"""))

Measured memory_bytes: 125508
#include <iostream>
#include "algorithm"
using namespace std;
int main(int argc, char *argv[])
{
	int n,x;
	while(cin>>n>>x)
	{
		int aa[n+1];
		int i;
		for(i = 0;i<n;i++)
		{
			cin>>aa[i];
		}
		
		sort(aa,aa +n);
		int sum = 0;
		for(i = 0;i<n - 1;i++)
		{
			if (x >= aa[i])
			{
				x -= aa[i];
				sum +=1;
			}	
		}
		if (aa[n - 1] == x) sum +=1;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);


int main(){
  int N, U, V; cin >> N >> U >> V;
  U--; V--;

  vector <int> Graph[N];
  for (int i = 0; i < N - 1; i++){
    int A, B; cin >> A >> B;
    A--; B--;
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }

  int Dist_from_A[N];
  fill(Dist_from_A, Dist_from_A + N, -1);
  Dist_from_A[V] = 0;
  queue <int> que; que.push(V);

  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (Dist_from_A[next] == -1){
        que.push(next);
        Dist_from_A[next] = Dist_from_A[Q] + 1;
      }
    }
  }
  
  int Dist_from_T[N];
  fill(Dist_from_T, Dist_from_T + N, -1);
  Dist_from_T[U] = 0; que.push(U);

  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (Dist_from_T[next] == -1){
        Dist_from_T[next] = Dist_from_T[Q] + 1;
        que.push(next);
      }
    }
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (Dist_from_T[i] <= Dist_from_A[i]){
      ans = max(ans, Dist_from_A[i] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n,a,b,c,k ;
string str ;

void solve()
{
    cin >> a >> b >> c >> k ;
    int ans = min(a,k) ;
    k -= ans ;
    k -= b ;
    if(k<=0)
        cout << ans ;
    else
        cout << ans-k ;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int tt = 1;
	//cin >> tt ;
	while(tt--)
	{
	     solve() ;
	}
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 1e9+7;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int N; cin >> N;
	string S1, S2; cin >> S1 >> S2;

	ll used = 0;
	ll cols = 1;
	F0R(i, N) {
		if (S1[i] == S2[i]) {
			cols *= (3 - used);
			used = 1;
		} else {
			if (used == 0) cols *= 6;
			else if (used == 1) cols *= 2;
			else cols *= 3;
			used = 2;
			++i;
		}
		cols %= MOD;
	}
	print(cols);
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> wow;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		wow.push_back(make_pair(a, b));
	}
	vector<pair<int, int>> gyao;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		gyao.push_back(make_pair(a, b));
	}
	for (int i = 0;i < n;++i) {
		int go = 0;
		int kyori = 10000000000000;
		for (int q = 0;q < m;++q) {
			long long hoge = abs(wow[i].first - gyao[q].first) + abs(wow[i].second - gyao[q].second);
			if (hoge < kyori) {
				kyori = hoge;
				go = q;
			}
		}
		cout << go+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
* @Author: 王文宇
* @Date:   2018-03-14 23:59:01
* @Last Modified by:   王文宇
* @Last Modified time: 2018-03-15 00:12:07
*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000007;
#define _for(i,a,b) for(int i=a;i<=b;i++)
int n,m,fa[maxn];
struct node
{	
	int x,y;
	double length;
}a[maxn];
struct point
{
	int x,y;
}b[maxn];
bool cmp(node a,node b)
{
	return a.length>b.length;
}
int find(int x)
{
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
double get(int x1,int x2,int y1,int y2)
{
	double xx = (double)(x1-x2)*(double)(x1-x2);
	double yy = (double)(y1-y2)*(double)(y1-y2);
	return sqrt(xx+yy);
}
int main(int argc, char const *argv[])
{
	cin>>n>>m;
	_for(i,1,n)
	{
		fa[i]=i;
		int x,y;
		cin>>b[i].x>>b[i].y;
	}
	double sum = 0.0;
	_for(i,1,m)
	{
		int x,y;
		cin>>x>>y;
		a[i].x=x;
		a[i].y=y;
		a[i].length = get(b[x].x,b[y].x,b[x].y,b[y].y);
		sum+=a[i].length;
	}
	sort(a+1,a+1+m,cmp);
	_for(i,1,m)
	{
		int p = find(a[i].x);
		int q = find(a[i].y);
		if(p!=q)
		{
			sum-=a[i].length;
			fa[p]=q;
		}
	}
	printf("%.3f\n",sum);
	return 0;
}


Measured memory_bytes: 3780