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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    int mn = 1e9;
    for(int i = 0; i < s.size() - 2;i++){
        int curr = stoi(s.substr(i, 3));
        mn = min(mn, abs(curr - 753));
    }
    cout << mn << "\n";
    return 0;        
}

Measured memory_bytes: 764
// ABC080B - 

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

typedef unsigned long long int ull;
typedef long long int ll;

// n 各桁の和を返す関数
int SumOfDigits(int n) {
	int ans = 0;

	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}

	return ans;
}

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

	if (N % SumOfDigits(N) == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    int n; cin >> n;
    string s1, s2;
    for(int i = 0; i < n; ++i){
        char c; cin >> c;
        s1 += c;
    }
    for(int i = 0; i < n; ++i){
        char c; cin >> c;
        s2 += c;
    }
    string ref = s1;
    sort(all(ref));
    int a = 0;
    int b = 0;
    int i = 0;
    do{
        ++i;
        if(s1 == ref) a = i;
        if(s2 == ref) b = i;
    }while(next_permutation(all(ref)));
    cout << abs(a - b) << '\n'; 
    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>

int main(){
    const char *end = "END_OF_TEXT";
    char w[11], t[1000];
    int sum = 0, wn;
    bool flag;
    scanf("%s", w);
    for(int i = 0; w[i] != '\0'; i++){
        wn = i;
    }
    wn ++;
    while(true){
        scanf("%s", t);
        flag = true;
        for(int i = 0; end[i] != '\0'; i++){
            if (end[i] != t[i]){
                flag = false;
                break;
            }
        }
        if(flag){
            break;
        }
        for(int i = 0; t[i] != '\0'; i++){
            if('A' <= t[i] && t[i] <= 'Z'){
                t[i] += ('a' - 'A');
            }
        }
        flag = true;
        for(int i = 0; i <= wn; i++){
            if (w[i] != t[i]){
                flag = false;
                break;
            }
        }
        if(flag){
            sum += 1;
        }
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 2756
#include<stdio.h>
 
int Linear(int a[], int n, int key){
  int i = 0;
  a[n]  = key;
  while (a[i] != key)
    i++;
  if (i==n){
    return 0;
  } else {
    return 1;
  }
}
 
int main(){
  int i, n, a[10001], q, k;
  int sum = 0;
  scanf("%d", &n);
  for (i=0; i<n; i++)
  scanf("%d", &a[i]);
  scanf("%d", &q);
  for (i=0; i<q; i++) {
  scanf("%d", &k);
  if (Linear(a, n, k)==1)
  sum++;
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 1856
#include<iostream>
#include<vector>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> a(n), v;
    v.push_back(0);
    for (int i = 0; i < n;++i) {
        cin >> a[i];
        if (i > 0) {
            if (a[i - 1] < a[i]) {
                v.push_back(v.back() + 1);
            } else if (a[i - 1] > a[i]) {
                v.push_back(v.back() - 1);
            }
        }
    }
    /*
    for (auto e : v) {
        cout << v[e] << " ";
    }
    cout << endl;*/
    int m = (int)v.size();
    int ans = 1;
    for (int i = 1; i < m - 1; ++i) {
        if ((v[i] - v[i - 1]) * (v[i] - v[i + 1]) > 0) { //大小変わった
            ++ans;
            ++i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1276
#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) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
 
int main() {
  string S; cin >> S;
  string T;
  int Q; cin >> Q;
  while (Q--) {
    int type; cin >> type;
    if (type == 1) {
      swap(S, T);
    } else {
      int f; char c; cin >> f >> c;
      if (f == 1) {
        T.push_back(c);
      } else {
        S.push_back(c);
      }
    }
  }
  reverse(range(T));
  cout << T + S << endl;
}

Measured memory_bytes: 1248
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n;
vector<int> a;
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n, k;
	cin >> k >> n;
	if(k % 2 == 0){
		cout << k / 2 << " ";
		for(int i = 2; i <= n; i ++)
			cout << k << " ";
		return 0;
	}
	for(int i = 1; i <= n; i ++){
		a.pb(k / 2 + 1);
	}
	for(int i = 1; i <= n / 2; i ++){
		int sz = (int)a.sz();
		if(a[sz - 1] == 1){
			a.pop_back();
		}else{
			a[sz - 1] --;
			while(a.sz() < n){
				a.pb(k);
			}
		}
	}
	for(int i = 0; i < a.sz(); i ++)
		cout << a[i] << " ";
	return 0;
}

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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)

string up(string s) {
  REP(i, s.size()) {
    if(s[s.size()-1-i] == '3') {
      s[s.size()-1-i] = '5';
      break;
    } else if(s[s.size()-1-i] == '5') {
      s[s.size()-1-i] = '7';
      break;
    } else if(s[s.size()-1-i] == '7') {
      s[s.size()-1-i] = '3';
      if(s.size()-1 == i) {
        s = "3" + s;
        break;
      }
    }
  }
  return s;
}

int main() {
  int N;
  cin >> N;
  string s = "3";
  int ans = 0;
  int c3, c5, c7;
  while(atol(s.c_str()) <= N) {
    c3 = 0;
    c5 = 0;
    c7 = 0;
    REP(i, s.size()) {
      if(s[i] == '3') {
        c3++;
      } else if(s[i] == '5') {
        c5++;
      } else if(s[i] == '7') {
        c7++;
      }
    }
    if(c3 > 0 && c5 > 0 && c7 > 0) ans++;
    s = up(s);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*input
3238506 17063340 92686568 73361868
125660016
*/
#include <bits/stdc++.h>

using namespace std;

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


#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define syso(n) cout<<n<<endl;
#define sysom(message, n) cout<<message<<n<<endl;
#define all(c) c.begin(), c.end() 
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(all(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 


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

ll lcm(ll fir, ll sec){
	return (fir*sec)/(gcd(fir, sec));
}


const int MOD = 1e9 + 7;
const string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
const int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(5) << f << '\n';


int main(){
	ll q,h,s,d;
	cin>>q>>h>>s>>d;
	ll n;
	cin>>n;
	ll ans=0;
	ll mini = min(q*4.0, min(h*2.0, s*1.0));
	if(d<2*mini){
		ll m = n/2;
		ans+= d*m;
		n -= m*2;
	}
	// syso(ans);
	ans+=n*mini;
	syso(ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int main() {
	LL Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	H = Q * 2 < H ? Q * 2 : H;
	S = H * 2 < S ? H * 2 : S;
	D = S * 2 < D ? S * 2 : D;
	LL ans = 0;
	ans += N / 2 * D;
	if (N % 2 == 1) {
		ans += S;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int n;
	static int[] c;
	static int[] s;
	static int[] f;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		c = new int[n];
		s = new int[n];
		f = new int[n];
		for (int i = 0; i < n - 1; i++) {
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			solver(i, 0);
		}
	}

	public static void solver(int stationNo, int arrivedTime) {
		if (stationNo == n - 1) {
			System.out.println(arrivedTime);
			return;
		}
		if (arrivedTime <= s[stationNo]) {
			solver(stationNo + 1, s[stationNo] + c[stationNo]);
		} else {
			solver(stationNo + 1, (arrivedTime + f[stationNo] - 1) / f[stationNo] * f[stationNo] + c[stationNo]);
		}
	}
}


Measured memory_bytes: 26284
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX

int n, m;
int a[2001], b[2001];

int dp[2001][2001];
bool v[2001][2001];

int s1(int i, int j)
{
    if(i==n or j==m)
        return 1;
    if(v[i][j])
        return dp[i][j];
    v[i][j] = 1;
    if(a[i] == b[j])
        return dp[i][j] = (s1(i,j+1) + s1(i+1, j)+mod)%mod;
    else
        return dp[i][j] = (s1(i,j+1) + s1(i+1, j) - s1(i+1, j+1)+mod)%mod;

}


void solve()
{
    cin >> n >> m;
    inp(a, n);
    inp(b, m);
    cout << s1(0,0) << endl;
}



signed main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

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

#define all(x) (x).begin(), (x).end()
#define itn int
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

void solve() {
	int n = nxt();
	vector<pair<int, int>> a;
	for (int i = 0; i < n; ++i) {
		long double xd;
		cin >> xd;
		xd *= 1'000'000'000;
		long long x = roundl(xd);
		int d2 = -9, d5 = -9;
		while (x % 2 == 0) {
			x /= 2;
			d2 += 1;
		}
		while (x % 5 == 0) {
			x /= 5;
			d5 += 1;
		}
		a.push_back({d2, d5});
	}
	map<pair<int, int>, int> M;
	for (auto p : a) {
		M[p] += 1;
	}
	long long ans = 0;
	for (auto p : M) {
		for (auto q : M) {
			if (p.first == q.first) {
				if (p.first.first >= 0 && p.first.second >= 0) {
					ans += 1ll * p.second * (p.second - 1) / 2;
				}
				break;
			} else {
				if (p.first.first + q.first.first >= 0 && p.first.second + q.first.second >= 0) {
					ans += 1ll * p.second * q.second;
				}
			}
		}
	}
	cout << ans << "\n";
}

int main() {
	int t = 1; // nxt();
	while (t--) {
		solve();
	}

	return 0;
}


Measured memory_bytes: 5560
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL A,V,B,W,T;

string ans = "NO";

void solve(){
	if((V-W)*T>=abs(B-A)) ans = "YES";
}

int main(){
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    solve();

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359

const int mod = 1e9 + 7;

int sum(long long left, long long right)
{
  long long ret = (right + left) * (right - left + 1) / 2;
  return ret;
}

int H, W;

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> H >> W;

  vector<vector<char>> field(H, vector<char>(W, '#'));

  // input
  rep(i, H) rep(j, W)
  {
    char tmp;
    cin >> tmp;
    field[i][j] = tmp;
  }

  // BFS
  int ans = 0;

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

  rep(h, H) rep(w, W)
  {
    if (field[h][w] != '.')
      continue;

    queue<pair<int, int>> bfs_queue;
    vector<vector<int>> visited_cnt(H, vector<int>(W, 0));

    visited_cnt[h][w] = true;

    bfs_queue.push(make_pair(h, w));

    while (!bfs_queue.empty())
    {
      // current cordinate
      pair<int, int> cc = bfs_queue.front();
      bfs_queue.pop();

      int y = cc.first;
      int x = cc.second;

      rep(idx, 4)
      {
        int nx = x + dx[idx];
        int ny = y + dy[idx];
        if (0 <= nx && nx < W && 0 <= ny && ny < H)
        {
          if (field[ny][nx] == '.' && visited_cnt[ny][nx] == 0)
          {
            visited_cnt[ny][nx] = visited_cnt[y][x] + 1;
            bfs_queue.push(make_pair(ny, nx));

            // TODO: remove
            // if (ans < visited_cnt[ny][nx])
            // {
            //   cout << "===" << endl;
            //   cout << visited_cnt[ny][nx] << endl;
            //   rep(i, H)
            //   {
            //     rep(j, W)
            //     {
            //       cout << visited_cnt[i][j] << "\t";
            //     }
            //     cout << endl;
            //   }
            // }

            ans = max(ans, visited_cnt[ny][nx]);
          }
        }
      }
    }
  }

  cout << ans-1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    ll n, fw = 0, bw = 0, ans = -INF; cin >> n;
    vector<ll> a(3*n), vf, vb;
    rep(i, 3*n) cin >> a[i];
    priority_queue<ll, vector<ll>, greater<ll>> pqf;
    priority_queue<ll> pqb;

    rep(i, n){
        pqf.push(a[i]);
        fw += a[i];
    }
    vf.push_back(fw);

    Rep(i, 2*n, 3*n){
        pqb.push(a[i]);
        bw += a[i];
    }
    vb.push_back(bw);

    Rep(k, n, 2*n){
        pqf.push(a[k]);
        fw += a[k] - pqf.top();
        pqf.pop();
        vf.push_back(fw);
    }
    for(ll k = 2*n-1; k >= n; k--){
        pqb.push(a[k]);
        bw += a[k] - pqb.top();
        pqb.pop();
        vb.push_back(bw);
    }

    reverse(all(vb));

    rep(i, vf.size()) chmax(ans, vf[i] - vb[i]);
    cout << ans << endl;
}


Measured memory_bytes: 9512
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
using namespace std;

int main()
{
    FAST
    int t;
    cin>>t;
    if(t>=400 && t<=599)
    cout<<"8"<<endl;
    else
    if(t>=600 && t<=799)
    cout<<"7";
    else
    if(t>=800 && t<=999)
    cout<<"6";
    else
    if(t>=1000 && t<=1199)
    cout<<"5";
    else
    if(t>=1200 && t<=1399)
    cout<<"4";
    else
    if(t>=1400 && t<=1599)
    cout<<"3";
    else
    if(t>=1600 && t<=1799)
    cout<<"2";
    else
    if(t>=1800 && t<=1999)
    cout<<"1";
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
int main(void){
    long int k;
    scanf("%ld",&k);
    //if(k%2!=0){
        long int su=0;
        for(long int i=1;i<=k;i++){
            su=(su*10+7)%k;
            
            if(su%k==0){
                printf("%ld\n",i);
                return 0;
            }
        }
    //}
    printf("-1\n");
}

Measured memory_bytes: 1732
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

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

//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [i32; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: usize, b: usize, c: usize,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input!{
        a: usize, b: usize, c: usize
    }
    // ab+c, ba+c, ac+b, ca+b, bc+a, cb+a
    let v = vec![10*a+b+c, 10*b+c+a, 10*c+a+b];
    println!("{}", v.iter().max().unwrap());
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> C(N - 1), S(N - 1), F(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }
  for (int start = 0; start < N - 1; start++) {
    int t = 0;
    for (int i = start; i < N - 1; i++) {
      if (t < S[i]) {
        t = S[i];
      } else if (t % F[i] != 0) {
        t += F[i] - t % F[i];
      }
      t += C[i];
    }
    cout << t << endl;
  }
  cout << 0 << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    string S;
    cin >> S;

    LL ans = 0;
    int head = 0;
    int tail = S.size()-1;
    while (head < tail) {
        if (S[head] != S[tail]) ++ans;
        ++head;
        --tail;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

N,M = input_int()
A = many_int()

sumA=sum(A)
count=0
for a in A:
    if 1/(4*M) > a/sumA:
        pass
    else:
        count+=1


if M <= count:
    print("Yes")
else:
    print("No")

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i < (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do{ cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << setprecision(20);
    }
} iosetup;

// YOUR CODE GOES HERE ↓↓↓
const int inf = 1000000000;
struct Solver{
    int Min, Max;
    Solver(int mi = -inf, int ma = inf) : Min(mi), Max(ma) {}
    bool unchanged(){ return Min <= -inf && Max >= inf; }
    bool change(Solver sol){
        if(!unchanged() && !sol.unchanged()){
            if((Min - sol.Min) & 1)return false;
            if(max(Min, sol.Min) > min(Max, sol.Max))return false;
        }
        chmax(Min, sol.Min);
        chmin(Max, sol.Max);
        return true;
    }
    Solver plus(){
        if(unchanged())return *this;
        else return Solver(Min - 1, Max + 1);
    }
};

int N, K;
vector<int> graph[100000];
Solver sols[100000];

bool dfs(int v = 0, int p = -1){
    for(int u : graph[v])if(u != p){
        if(!dfs(u, v))return false;
        if(!sols[v].change(sols[u].plus()))return false;
    }
    return true;
}

void dfs2(int v = 0, int p = -1){
    if(p != -1)sols[v].change(sols[p].plus());
    for(int u : graph[v])if(u != p)dfs2(u, v);
}

int main(){

    cin >> N;
    rep(i, N - 1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    cin >> K;
    rep(i, K){
        int v, p;
        cin >> v >> p;
        v--;
        sols[v].change(Solver(p, p));
    }

    if(!dfs()){
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";
    dfs2();
    rep(i, N){
        cout << sols[i].Min << '\n';
    }

}

Measured memory_bytes: 14976
class Union():
  def __init__(me,N):
    me.N = N
    me.up = [-1]*N
    me.down = [ [] for i in range(N) ]
  def union(me,a,b):
    ua = me.up[a] if me.up[a]!=-1 else a
    ub = me.up[b] if me.up[b]!=-1 else b
    if (ua == ub):
      return
    if ( len(me.down[ua]) < len(me.down[ub]) ):
      ub,ua = ua,ub
    for v in me.down[ub]:
      me.up[v] = ua
    me.down[ua].extend( me.down[ub] )
    me.down[ub] = []
    me.up[ub] = ua
    me.down[ua].append( ub )
  def count(me,a):
    ua = me.up[a] if me.up[a]!=-1 else a
    return len(me.down[ua])+1

N = int(input())

li = [ [ int(it) -1 for it in input().split() ] for i in range(N-1) ]

down = [ [] for i in range(N) ]

for a,b in li:
  down[a].append(b)
  down[b].append(a)

mita = [0]*N
mita[0]=1
kouho = [0]
dist = [100000000000000000]*N
dist[0] = 0

for i in range(10000000000000000):
  if ( len(kouho) == 0 ):
    break
  n = kouho.pop()
  for k in down[n]:
    if ( mita[k] == 0 ):
      dist[k] = min(dist[k],dist[n]+1)
      mita[k] = 1
      kouho.append(k)

route = [N-1]
for i in range(10000000000000000):
  n = route[-1]
  if ( n == 0 ):
    break
  s = 100000000000000
  sk = -1
  for k in down[n]:
    if (s > dist[k] - dist[n]):
      s = dist[k] - dist[n]
      sk = k
  route.append(sk)   
route.reverse()
x,y = route[ (len(route)-1)//2 ],route[ 1+((len(route)-1)//2) ]

u = Union(N)
for a,b in li:
  if (a==x and b==y) or (a==y and b==x):
      continue
  u.union(a,b)

if ( u.count(0) <= u.count(N-1) ):
  print ( "Snuke" )
else:
  print ( "Fennec" )



  

Measured memory_bytes: 87640
a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
ans = 0
for i in range(min(a, x // 500) + 1):
    for j in range(min(b, (x - i * 500) // 100) + 1):
        rest = x - (i * 500 + j * 100)
        if rest <= c * 50:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long n, k, q;

	std::cin >> n >> k >> q;
	
	std::vector<long long> v(n, 0);

	for (long long i = 0; i < q; i++)
	{
		long long num;
		std::cin >> num;
		v[num - 1]++;
	}

	for (long long i = 0; i < n; i++)
	{
		v[i] = k - (q - v[i]);
		if (v[i] > 0) {
			std::cout << "Yes" << std::endl;
		}
		else {
			std::cout << "No" << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using pii = std::pair<int,int>;
using cint = const int;
template<bool debug = 0>
bool check(cint sx, cint sy, cint tx, cint ty, std::string out) {
    std::map<pii,int>cnt;
    cnt[{sx,sy}]++;
    int cx=sx,cy=sy;
    for (char dir : out) {
        if (dir == 'R') { cx++; }
        else if (dir == 'L') { cx--; }
        else if (dir == 'U') { cy++; }
        else if (dir == 'D') { cy--; }
        else assert(false);
        cnt[{cx,cy}]++;
    }
    debug && std::cout << "out = " << out << std::endl;
    bool ok = 1;
    for (auto &it : cnt) {
        if (it.first != pii{sx,sy} && it.first != pii{tx,ty}) {
            ok &= it.second == 1;
            if (debug && it.second != 1) {
                std::cout << it.first.first << ' ' << it.first.second << " visited " << it.second << std::endl;
            }
        }
    }
    return ok &= cnt[{sx,sy}] == 3 && cnt[{tx,ty}] == 2;
}
int main() {
    int sx,sy,tx,ty;
    while(std::cin >> sx >> sy >> tx >> ty) {
        int dx = tx - sx, dy = ty - sy;
        std::string out = "D";
        out += std::string(dx+1, 'R');
        out += std::string(dy+1, 'U');
        out += "LU";
        out += std::string(dx+1, 'L');
        out += std::string(dy+1, 'D');
        out += std::string(dx+1,'R');
        out += std::string(dy,'U');
        out += std::string(dx, 'L');
        out += std::string(dy, 'D');
        bool flag = check(sx,sy,tx,ty,out);
        assert(flag);
        std::cout << out << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#define N 10000
#define MAX 1000

int su,n;
int A[MAX],B[MAX],C[N+1],f[MAX];

int res();
void bubbleSort(int b);
int min(int a,int b);

int main(){
  int i,t,r;
  su=10000;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    su=min(su,A[i]);
  }

  r=res();

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

  return 0;
}

void  bubbleSort(int b){
  int i,j,t,f=1;
  i=0;
  while(f==1){
    f=0;
    for(j=b-1;j>=i+1;j--){
      if(B[j]<B[j-1]) {
	t=B[j];
	B[j]=B[j-1];
	B[j-1]=t;
	f=1;
      }
    }
    i++;
  }
}

int min(int a,int b){
  if(a<b) return a;
  else return b;
}

int res(){
  int r=0,i,c,s,m,a,v;

  for(i=0;i<n;i++){
    B[i]=A[i];
    f[i]=0;
  }

  bubbleSort(n);

  for(i=0;i<n;i++) C[B[i]]=i;
  for(i=0;i<n;i++){
    if(f[i]==1) continue;
    c=i;
    s=0;
    m=10000;
    a=0;
    while(1){
      f[c]=1;
      a++;
      v=A[c];
      m=min(m,v);
      s=s+v;
      c=C[v];
      if(f[c]==1)break;
    }

    r=r+min(s+(a-2)*m,m+s+(a+1)*su);
  }
  return r;
}




Measured memory_bytes: 2132
#include <cstdio>
using namespace std;

const int MAX_N = 100001;
const int MAX_K = 12;

// 連続で x 回半額弁当をゲットしたときに半額弁当を得る確率
double P(int x){
	return 1.0 / (1 << x);
}

// dp[i][k] := i 日目で k 回連続ゲットしたときの期待値
double dp[MAX_N+1][MAX_K+1] = {0};
// ans[i] := i 日目の半額弁当を得る個数の期待値
double ans[MAX_N+1] = {0};

int main(){
	int n;
	double sum = 0;
	
	dp[0][0] = 1.0;
	for(int i=0 ; i < MAX_N ; i++ ){
		for(int k=0 ; k < MAX_K ; k++ ){
			if( dp[i][k] > 0 ){
				sum += dp[i][k] * P(k);
				
				// 半額弁当を得るとき
				dp[i+1][k+1] += dp[i][k] * P(k);
				// 半額弁当を得られないとき
				dp[i+1][0] += dp[i][k] * (1.0 - P(k));
				
			}
		}
		ans[i] = sum;
	}
	
	while( scanf("%d", &n ) , n ){
		printf("%.8f\n", ans[n-1] );
	}
}

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

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

Measured memory_bytes: 256
N, M = map(int, input().split())
mod = 10**9 + 7

diff = N - M
if diff < 0:
    diff = -diff
if diff > 1:
    print(0)
    exit()

def perm(n, mod):
    p = 1
    for i in range(1, n + 1):
        p = (p * i) % mod
    return p

ans = perm(N, mod)
ans = (ans * perm(M, mod)) % mod
if diff == 0:
    ans = (ans * 2) % mod
print(ans)


Measured memory_bytes: 38512
l = int(input())
s = input()
s_dict = {}
l = len(s)
for i in range(l):
    if not s[i] in s_dict:
        s_dict[s[i]] = 1
    else:
        s_dict[s[i]] += 1
ans = 1
for v in s_dict.values():
    if v == 1:
    	ans *= 2
    else:
        ans *= v+1

print(int(ans-1)%(10**9+7))


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

int main() {
  int N; cin >> N;
  
  for (int i = 0; i < N; i++) {
    int A; cin >> A;

    if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }

  cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,i,j;
	while(1){
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)
		break;
		for(i=1;i<=a;i++){
			for(j=1;j<=b;j++){
				if(i%2==1){
				if(j%2==1)
				printf("#");
				else
				printf(".");
				}
				else{
				if(j%2==0)
				printf("#");
				else
				printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
N, M = gets.split.map &:to_i
A = N.times.map{ gets.chomp }
B = M.times.map{ gets.chomp }

def clip(x, y)
  M.times.map{|v|
    A[y+v][x, M]
  }
end

for x in 0..(N-M)
  for y in 0..(N-M)
    if clip(x, y) == B
      puts "Yes"; exit
    end
  end
end
puts "No"


Measured memory_bytes: 2044
import sys
input=sys.stdin.readline

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

x=-1
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        x=i
        break

if x==-1:
    print('Impossible')
else:
    print('Possible')
    for i in range(x):
        print(i+1)
    for i in range(n-2,x,-1):
        print(i+1)
    print(x+1)

Measured memory_bytes: 86012
import java.util.Scanner;

public class Main {
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(true)
			{
				int a = stdIn.nextInt();
			
				if(a==0)
				{
					break;
				}
				else
				{
					System.out.println(func(a));
				}
			}
	}
	
	static int func(int a)
	{
		int i = 2;
		int k = 1;
		int h = 0;
		while(true)
		{
			k = k + i;
			
			if(a<k)
			{
				break;
			}
			
			if((a-k)%i == 0)
			{
				h++;
			}
			
			i++;
		}
		
		return h;
	}
}

Measured memory_bytes: 18160
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, q = map(int, readline().split())
  s = input()
  t = [0] *(n+1)
  for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)
  for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 11568
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
	int n;
	int ateam,bteam,ascore,bscore;
	cin>>n;
	vector<int> team(n),cmp(n);
	int num=n=(n*n-n)/2;
//	cout<<n;
	while(n--){
		cin>>ateam>>bteam>>ascore>>bscore;
//		cout<<ateam<<bteam<<ascore<<bscore<<endl;
		if(ascore==bscore)
			team[ateam-1]++,team[bteam-1]++;
		else if (ascore>bscore)
			team[ateam-1]+=3;
		else if (ascore<bscore)
			team[bteam-1]+=3;
	}
	for(int i = 0 ; i < team.size() ; i ++){
		int rank = 1;
		for(int j = 0 ; j < cmp.size() ; j ++)
				if(team[i]<team[j]){
					rank++;
					}
		cout<<rank<<endl;
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define maxx 100100
using namespace std;
int dp[maxx],vis[maxx];
vector<int>ladj[maxx];
int ans = 0;

void dfs(int x){
	if(!vis[x]){
		vis[x] = 1;
		for(auto e:ladj[x]){
			if(!vis[e]) dfs(e);
			dp[x] = max(dp[x],dp[e]+1);
			ans = max(dp[x],ans);
		}
	}
}

int main(){
    ios_base::sync_with_stdio(false);    
    cin.tie(NULL);
 
    int n,m;
    cin >> n >> m;
 
    int x,y;
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        ladj[x].push_back(y);
    }
 
    for(int i = 1; i <= n; i++){
		if(vis[i] != 1) dfs(i);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 12420
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            string[] In = Console.ReadLine().Split(' ');
            int H = int.Parse(In[0]);
            int A = int.Parse(In[1]);
            int cnt = 0;
            while (H > A * cnt)
            {
                cnt++;
            }
            Console.WriteLine(cnt);
        }

    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 long long int N;
 long long int A;
 long long int B;
 long long int C;
 cin >> N >> A >> B;
 if(((B-A)%2)==0){     
     cout << (B-A)/2 << endl;
 }
 else{C=min(((A-1)+((B-(A-1))/2)),((N-B)+(((N+1-A)-(N-B))/2)));
            cout << C << endl;}
     return 0;
 }


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

using namespace std;

#define mod 1000000007


int n, k;
vector<vector<int> > v(100001);
vector<int> a(100001);
int ans = 0;

int solve(int nownode)
{
	// cout << nownode << endl;
	int maxdepth = 1;
	for(int i = 0; i < v[nownode].size(); i++){
		int next = v[nownode][i];
		maxdepth = max(maxdepth, solve(next) + 1);
	}
	// cout << nownode << maxdepth << endl;
	if(maxdepth == k){
		if(a[nownode] != 1) ans++;
		return 0;
	}
	return maxdepth;
}


int main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i == 1){
			if(a[i] != 1){
				a[i] = 1;
				ans++;
			}
		} else {
			v[a[i]].push_back(i);
		}
	}
	solve(1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10752
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int h, w, k;
	cin>>h>>w>>k;
	VS b(h);
	rep(i,h){
		cin>>b[i];
	}
	int ans = 0;
	rep(r, 1<<h){
		rep(c, 1<<w){
			int black = 0;
			rep(i,h){
				rep(j,w){
					if(((r>>i)&1)==0 and ((c>>j&1)==0)){
						if(b[i][j] == '#'){
							black++;
						}
					}
				}
			}
			if(black==k){
				ans++;
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100100;
int n , deg[N] , ans ;
vector<int>adj[N];
set<int>s;

int dfs(int i,int p=-1){
if( deg[i]>2 )return i;
for(auto j:adj[i])
    if( j!=p )
        return dfs(j,i);
return -1;
}

int main(){

scanf("%d",&n);
for(int i=1;i<n;i++){
    int u,v;
    scanf("%d %d",&u,&v);
    deg[u]++;
    deg[v]++;
    adj[u].push_back(v);
    adj[v].push_back(u);
}

int mx=0;
for(int i=1;i<n;i++)
    if( deg[mx]<deg[i] )
        mx=i;

if( deg[mx]<=2 ){
    printf("1\n");
    return 0;
}

for(int i=0;i<n;i++)
    if( deg[i]==1 )
        ans++,s.insert(dfs(i));

printf("%d\n",ans-s.size());
return 0;
}


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

int main(){
    for (int a = 0;;a++) {
        int x,y;
        cin >> x>>y;
        if (x == 0 && y == 0) break;
        if (x > y) swap (x,y);
        cout << x << " "<<y<<endl;
    }
}


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

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(a == 1 || b == 1 || c == 1 || d == 1){
		if(a == 4 || b == 4 || c == 4 || d == 4){
			if(a == 7 || b == 7 || c == 7 || d == 7){
				if(a == 9 || b == 9 || c == 9 || d == 9){
					cout << "YES" << endl;
					return 0;
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

int main(){
  
  int n,i = 0;
  cin >> n;
  
  double Out=0,A[n];
  
  for(i=0;n>i;i++){
    cin >> A[i];
    Out = Out+(1/A[i]);
  }    
  
  cout << 1/Out;
  
  return 0;
      
}

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

int main() {
	int N;
	int t[110000], x[110000], y[110000];
	cin >> N;
	t[0] = x[0] = y[0] = 0;  // 初期状態
	for (int i = 0; i < N; ++i) cin >> t[i + 1] >> x[i + 1] >> y[i + 1];  // 1-index にしておく

	bool can = true;

	for (int i = 0; i < N; ++i) {
		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if (dt < dist) can = false;
		if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

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

    int a, b;
    cin >> a >> b;

    cout << max(a + b, max(a - b, a * b)) << endl;

    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, d;

int main() {
	cin >> a >> b;
	d = b - a;
	
	cout << d * (d + 1) / 2 - b << endl;
	
	return 0;
}


Measured memory_bytes: 256
N  = int(raw_input())

ans = [0, 0]
T, A = [0] * 1001, [0] * 1001

for i in range(N):
    T[i], A[i] = map(int, raw_input().split())

    if i != 0 and T[i - 1] - T[i] > 0 or A[i - 1] - A[i] > 0:

        if (T[i  - 1] / T[i]) > (A[i - 1] / A[i]):
            m  = T[i  - 1] / T[i]
            if T[i - 1] % T[i] != 0:
                m += 1 

        else:
            m = A[i - 1] / A[i]
            if A[i - 1] % A[i] != 0:
                m += 1

        T[i] *= m
        A[i] *= m

    ans = [T[i], A[i]]

print sum(ans)

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF INT_MAX/3
#define mod 1000000007

#define MAX_V 1010

struct edge{
  int to,cap,cost,rev;
};

int V;
vector<edge> g[MAX_V];
ll h[MAX_V];
ll dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init(int v){
  V=v;
  for(int i=0;i<MAX_V;i++){
    g[i].clear();
  }
}

void add_edge(int from,int to,int cap,int cost){
  g[from].push_back((edge){to,cap,cost,(int)g[to].size()});
  g[to].push_back((edge){from,0,-cost,(int)g[from].size()-1});
}

ll min_cost_flow(int s,int t,int f){
  ll res=0;
  memset(h,0,sizeof(h));
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(que.size()){
      P p=que.top(); que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<(int)g[v].size();i++){
        edge e=g[v][i];
        if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }
    if(dist[t]==INF)return -1;
    for(int v=0;v<V;v++) h[v]+=dist[v];

    ll d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,(ll)g[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=g[prevv[v]][preve[v]];
      e.cap-=d;
      g[v][e.rev].cap+=d;
    }
  }
  return res;
}

int N;
vector<P> g0[1001];
int d[1001][1001];
int indeg[1001],outdeg[1001];

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

  cin>>N;
  ll res=0;
  rep(i,N){
    int k;
    cin>>k;
    rep(j,k){
      int a,b;
      cin>>a>>b;
      a--;
      g0[i].push_back(P(a,b));
      outdeg[i]++; indeg[a]++;
      res+=b;
    }
  }

  rep(i,N)rep(j,N)d[i][j]=INF;
  rep(i,N){
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,i));
    while(que.size()){
      P p=que.top(); que.pop();
      if(d[i][p.se]!=INF)continue;
      d[i][p.se]=p.fi;
      for(P e : g0[p.se]){
        que.push(P(p.fi+e.se,e.fi));
      }
    }
  }

  init(N+2);
  int source=N,sink=N+1;
  int fsum=0;
  rep(i,N){
    if(i==0||indeg[i]>outdeg[i]){
      if(i==0) add_edge(source,i,INF,0);
      else add_edge(source,i,indeg[i]-outdeg[i],0);
    }
    if(indeg[i]<outdeg[i]){
      add_edge(i,sink,outdeg[i]-indeg[i],0);
      fsum+=outdeg[i]-indeg[i];
    }
  }
  rep(i,N){
    for(P e : g0[i]){
      add_edge(i,e.fi,INF,e.se);
    }
  }
  cout<<res+min_cost_flow(source,sink,fsum)<<endl;

  return 0;
}



Measured memory_bytes: 9532
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;
}

Measured memory_bytes: 256