akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007, INF = 1111111111;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	int N, M, tmp;
    cin >> N >> M;
    
    vector<int> city(N);
    FOR(i, 0, M*2) {
      
      cin >> tmp;
      city[tmp - 1]++;
    }

	FOR(i, 0, N)cout << city[i] << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<String> ary = new ArrayList<>();

        for (int i = 1; i < n + 1; i++) {
            ary.add(sc.next());
        }
        List<String> list = new ArrayList<String>(new HashSet<>(ary));
        System.out.print(list.size());
    }
}



Measured memory_bytes: 73016
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int N, T, A, tmp, m = 1e9, idx;
    cin >> N >> T >> A;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        if (m > abs(1000*A - (1000*T - tmp*6))) {
            m = abs(1000*A - (1000*T - tmp*6));
            idx = i;
        }
    }
    cout << idx + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int h,w,d;
	cin >>h>>w>>d;
	VVi a(h,Vi(w,0));
	vector<ll>data(h*w,0LL);
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
			a[i][j]--;
			data[a[i][j]]=i*1000+j;
		}
	}
	V dis(h*w,0LL);
	rep(i,h*w){
		if(i>=d){
			dis[i]=dis[i-d]+abs(data[i]/1000 - data[i-d]/1000)+abs(data[i]%1000- data[i-d]%1000);
		}
	//	clog<<dis[i]<<" ";
	}
	//clog<<endl;
	int q;
	cin>>q;
	Pi lr;
	rep(i,q){
		cin>>lr.F>>lr.S;
		cout<<dis[lr.S-1]-dis[lr.F-1]<<endl;
	}
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long N, A, B;
	scanf("%lld %lld %lld", &N, &A, &B);
	
	long long ans;
	if ((B - A) % 2 == 0) ans = (B - A) / 2;
	else if (A + B - 1 < N * 2 - A - B + 1) ans = (A + B - 1) / 2;
	else ans = N - (A + B - 1) / 2;
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		int x[4] = {};
		for( int i = 0; i < 3; ++i ) {
			int a, b;
			cin >> a >> b;
			x[a-1] += 1;
			x[b-1] += 1;
		}

		int y = 0;
		y += x[0] == 2;
		y += x[1] == 2;
		y += x[2] == 2;
		y += x[3] == 2;

		cout << (y == 2 ? "YES" : "NO") << endl;
	}
};

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


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main{
	static final int MaxN = 400000;
	static final int MaxV = 100000;
	static int []pre = new int[MaxN + 5];
	static int []last = new int[MaxN + 5];
	static int []other = new int[MaxN + 5];
	static int []cost = new int[MaxN + 5];
	static int []a = new int [MaxV + 5];
	static boolean []vis = new boolean[MaxV + 5];
	static boolean flag = true;
	static int n, m, all;
	public static void build(int u, int v, int c){
		pre[++all] = last[u];
		last[u] = all;
		other[all] = v;
		cost[all] = c;
	}
	public static void dfs(int u, int sum){
		if(flag == false) return;
		if(vis[u]){
			if(a[u] != sum) flag = false;
			return;
		}
		vis[u] = true;
		a[u] = sum;
		int ed, dr, add;
		ed = last[u];
		while(ed != -1){
			dr = other[ed];
			add = cost[ed];
			dfs(dr, sum + add);
			ed = pre[ed];
		}
	}
	public static void main(String[] args){
		all = -1;
		Arrays.fill(last, -1);
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		for(int i = 1; i <= m; i++){
			int u, v, c;
			u = sc.nextInt();
			v = sc.nextInt();
			c = sc.nextInt();
			build(u, v, c);
			build(v, u, -c);
		}
		for(int i = 1; i <= n; i++){
			if(!vis[i]) dfs(i, i);
		}
		if(flag == true) System.out.println("Yes\n");
		else System.out.println("No\n");
	}
}


Measured memory_bytes: 166988
A, B = map(int, input().split())
S = list(input())
num = '0123456789'
ans = 0

for i in range(A):
    for n in num:
        if S[i] == n:
            ans += 1

if S[A] == '-':
    ans += 1

for j in range(B):
    for n in num:
        if S[A + 1 + j] == n:
            ans += 1

if ans == A + B + 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main() {
    long long N;
    cin >> N;
    long long L0 = 2;
    long long L1 = 1;
    long long L2 = 2;
    if(N == 0) {
        cout << L0 << endl;
        return 0;
    }else if (N == 1) {
        cout << L1 << endl;
        return 0;
    }
    for(int i = 0; i < N - 1; i++) {
        L2 = L1 + L0;
        L0 = L1;
        L1 = L2;
    }
    cout << L2 << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: usize = read();
    let mut ans: f64 = 0.0;
    for _i in 0..n {
        ans += 1.0 / read::<f64>();
    }

    ans = 1.0 / ans;

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
bool check(int a, int b, int c){
	bool ret;
	if(a+b>c && c+a>b && b+c>a) ret = true;
	else ret = false;
	return ret;
}
int main() {
	int n; scanf("%d",&n);
	int a[n];
	rep(i,0,n) scanf("%d",a+i);
	int counter=0;
	rep(i,0,n){
		rep(j,i+1,n){
			rep(k,j+1,n){
				if(a[i]==a[j] || a[j]==a[k] || a[k]==a[i]) continue;
				//cout << i << " " << j << " " << k << endl;
				if(check(a[i], a[j], a[k])) ++counter;
			}
		}
		//cout << counter << endl;
	}
	printf("%d",counter);
}


Measured memory_bytes: 3796
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
unordered_map<int, int> M;

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

  cin >> N;
  int a;
  rep(i, N){
    cin >> a;
    M[a]++;
  }

  int ans=0;
  for (auto it=M.begin(); it !=M.end(); ++it){
    int v = it->first;
    int cnt = it->second;

    ans += v<=cnt?cnt-v:cnt;
  }
  cout << ans << "\n";
  return 0;
}

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

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

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

    int q;
    cin>>q;
    vector<int> a;
    rep(i, q) {
        int n, x;
        cin>>n;
        switch (n)
        {
        case 0:
            cin>>x;
            a.push_back(x);
            break;
        case 1:
            cin>>x;
            cout<<a[x]<<endl;
            break;
        default:
            a.pop_back();
            break;
        }
    }
}


Measured memory_bytes: 3952
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  cout << endl;
  for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

using P = pair<int, int>;
using LP = pair<ll, P>;
int main(){
  int H, W;
  cin >> H >> W;

  int sh, sw, gh, gw;
  cin >> sh >> sw >> gh >> gw;
  sh--; sw--; gh--; gw--;

  vector<string> maze(H);
  for(int i=0; i<H; i++) cin >> maze[i];

  const int ADD = 10;
  const int INF = 1e8 + 1;
  vector<vector<ll>> field(H+ADD, vector<ll>(W+ADD, INF));
  field[sh][sw] = 0;
  
  int dh[] = {-1, 0, 1, 0};
  int dw[] = {0, -1, 0, 1};

  // queue<P> qu;
  // qu.push(P(sh, sw));
  priority_queue<LP, vector<LP>, greater<LP>> pri_qu;
  pri_qu.push(LP(0, P(sh, sw)));
 
  // while(!qu.empty()){
  while(!pri_qu.empty()){
    // int h = qu.front().first;
    // int w = qu.front().second;
    // qu.pop();
    ll cost = pri_qu.top().first;
    int h = pri_qu.top().second.first;
    int w = pri_qu.top().second.second;
    pri_qu.pop();
  
    for(int i=0; i<4; i++){
      int nh = h + dh[i];
      int nw = w + dw[i];
      // cout << "  cnt : " << cnt  << "(h, w)= (" << h << ", " << w  << ")   (nh, nw) = (" << nh << ", " << nw << ")"<< endl;
      if(nh < 0  || H <= nh) continue;
      if(nw < 0  || W <= nw) continue;
      if(maze[nh][nw] == '#') continue;
      // if(field[nh][nw] <= field[h][w]) continue;
      if(field[nh][nw] <= cost) continue;
      field[nh][nw] = field[h][w];
      // cout << "  hhh " << endl;
    
      // qu.push(P(nh, nw));
      pri_qu.push(LP(cost, P(nh, nw)));
    }

    for(int _h=-2; _h<=2; _h++){
      for(int _w=-2; _w<=2; _w++){
        int nh = h + _h;
        int nw = w + _w;
        if(nh < 0  || H <= nh) continue;
        if(nw < 0  || W <= nw) continue;
        if(maze[nh][nw] == '#') continue;
        // if(field[nh][nw] <= field[h][w]+1) continue;
        if(field[nh][nw] <= cost+1) continue;
        field[nh][nw] = field[h][w] + 1;
      
        // qu.push(P(nh, nw));
        pri_qu.push(LP(cost+1, P(nh, nw)));
      }
    }
  }

  if(field[gh][gw] != INF) cout << field[gh][gw] << endl;
  else cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 13472
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String ss=s.next();
        int ff=0;
        for(int j=0;j<ss.length();j++){
            if(j%2==0 && ss.charAt(j)!='h'){
                ff=1;
                break;
            }
            else if(j%2==1 && ss.charAt(j)!='i'){
                ff=1;
                break;
            }
        }

        if(ff==1 || ss.length()%2==1){
            System.out.println("No");
        }
        else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 22740
l1  = input().split(" ")
ar = []
for i in l1:
  ar.append(int(i))
d = {1:0,9:0,7:0,4:0}
for i in ar:
  for j in d:
    if  i == j:
      d[j] = 1
con = True
for  i in d:
  if d[i] == 0:
    con = False
    print("NO")
    break
if con:
  print("YES")    

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

int main(){
  int nari[5],i,j,h,a;

  for(i=0;i<5;i++){
    cin>>nari[i];
    }

  for(i=0;i<5;i++){
    a=i;
    for(j=i;j<5;j++){
      if(nari[a]<nari[j])a=j;
    }
    h=nari[a];
    nari[a]=nari[i];
    nari[i]=h;
  }

  for(i=0;i<5;i++){
    cout << nari[i];
    if(i != 4)printf(" ");
  }
  cout << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,d;cin>>n>>d;
    vector<vi>v(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            ll a;cin>>a;
            v[i].pb(a);
        }
    }
    ll cnt=0;
    for(int i=0;i<n;i++){
        for(int k=i+1;k<i+n;k++){
            ll sum=0;
            for(int j=0;j<d;j++){
                ll a=v[i][j]-v[(k)%n][j];
                sum+=(a*a);
            }
            ll t=(ll)sqrt((ld)sum);
            if(sqrt((ld)sum)==t)cnt++;
        }
    }
    cout<<cnt/2<<"\n";
}


Measured memory_bytes: 256
import sys

def straight(cards):
    aa = range(1,5)
    if cards == [1, 10, 11, 12, 13]:
        return True
    for i in range(1, 10):
        if cards == range(i, i+5):
            return True
    return False

for s in sys.stdin.read().rstrip().split('\n'):
    cards = sorted(map(int, s.split(',')))
    c = [0]*13
    for card in cards:
        c[card-1] += 1
    if 4 in c:
        print 'four card'
    elif (3 in c) and (2 in c):
        print 'full house'
    elif straight(cards):
        print 'straight'
    elif 3 in c:
        print 'three card'
    elif c.count(2) == 2:
        print 'two pair'
    elif c.count(2) == 1:
        print 'one pair'
    else:
        print 'null'

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

    vector<int> l(N);

    REP(i, N)
        cin >> l[i];

    sort(ALL(l), greater<>());

    int sum = 0;

    REP(i, K)
        sum += l[i];

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
# 2019-11-12 22:40:44(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    dishes = [int(x) for x in sys.stdin.read().split()]
    

    total = 0
    for i in range(5):
        if dishes[i] % 10 != 0:
            total += (dishes[i] // 10 + 1) * 10
        else:
            total += dishes[i]
    

    remainder = [dishes[i] % 10 for i in range(5) if dishes[i] % 10 != 0]
    if remainder:
        ans = total - (10 - min(remainder))
    else:
        ans = total
    print(ans)

if __name__ == "__main__":
    main()


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

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

  int r = 0, b = 0;
  for (char c : S) {
    if (c == '0')  r++;
    else b++;
  }

  cout << S.size() - abs(r - b) << endl;
  return 0;
}


Measured memory_bytes: 3764
//agc024_a.cpp
//Sat Oct 27 15:18:06 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll a,b,c,k;
	cin >> a >> b >> c >> k;

	ll ans = 0;
	if (k%2 == 1){
		ans = b-a;
	}else {
		ans = a-b;
	}

	cout << ans << endl;
}

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

using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	set<int> ans;

	for (int i = a; i < a + k && i <= b; i++)
	{
		ans.insert(i);
	}
	for (int i = b; b - k < i && a <= i; i--)
	{
		ans.insert(i);
	}

	for (auto item : ans)
	{
		cout << item << endl;
	}

	return 0;
}

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;


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

	int R;
	double C;

	cin >> R;

	C = 2*pi*R;

	printf("%.2f\n", C);
	return 0;		
}



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

int main(){
  
  int i, Size, cnt = 0;
  string S, T;
  cin >> S;
  cin >> T;
  Size = T.size();
  
  for (i = 0; i < Size; i++){
    if (S.at(i) == T.at(i)) cnt++;
  }
 
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
typedef long long LL;
using namespace std;
const LL mod = 1e9+7;
int a[200003], dp[200003]={1};
int main(){
    LL ans = 0;
    int n, x, y=-1;
    scanf("%d",&n);
    for(int i=1; i<=n; ++i){
        scanf("%d",&x);
        if(!a[x]) dp[i] = dp[i-1];
        else{
            dp[i] = dp[a[x]];
            if(x != y){
                dp[i] += dp[i-1];
                if(dp[i] >= mod) dp[i] -= mod;
            }
        }
        y = x;
        a[x] = i;
    }
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int& i : a) cin >> i;
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int k;
		cin >> k;
		cout << lower_bound(a.begin(), a.end(), k) - a.begin() << endl;
	}
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int a,b,c;
    cin>>a>>b>>c;
    int ma = 0;
    char ans;
    if(chmax(ma,a))ans='A';
    if(chmax(ma,b))ans='B';
    if(chmax(ma,c))ans='C';
    cout << ans << endl;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
const int maxN = 55;
long long ans = 0;
set < int > val[maxN];
int a[maxN];
int b[maxN];
int n;
bool go[maxN][maxN][maxN];
int main() {
    srand(time(0));
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    for (int i = 0; i < maxN; i++) go[i][i][0] = true;
    for (int i = 1; i < maxN; i++) {
        for (int j = 0; j < maxN; j++) {
            for (int k = 0; k < maxN; k++) {
                go[j][k][i] = go[j][k][i - 1];
            }
        }
        for (int j = 0; j < maxN; j++) {
            for (int k = 0; k < maxN; k++) {
                go[j][k][i] |= go[j % i][k][i];
            }
        }
    }
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        val[i].insert(a[i]);
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        if (!go[a[i]][b[i]][maxN - 1]) {
            cout << -1;
            exit(0);
        }
    }
    for (int iter = 50; iter >= 1; iter--) {
        bool ok = true;
        for (int i = 1; i <= n; i++) {
            bool ok1 = false;
            for (auto it = val[i].begin(); it != val[i].end(); it++) {
                int y = *it;
                if (go[y][b[i]][iter - 1]) {
                    ok1 = true;
                    break;
                }
            }
            if (!ok1) {
                ok = false;
                break;
            }
        }
        if (ok) continue;
        //cout << iter << '\n';
        ans += (1LL << iter);
        for (int i = 1; i <= n; i++) {
            for (auto it = val[i].begin(); it != val[i].end(); it++) {
                int y = *it;
                val[i].insert(y % iter);
            }
        }
    }
    cout << ans;
}


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

public class Main{
	public static int count;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		for(int i = 0;i < n; i++){
			int num = Integer.parseInt(br.readLine());
			solve(num);
		}

		System.out.println(count);

	}

	public static void solve(int num){
		if(num == 1){
			return;
		}
		else if(num == 2){
			count++;
			return;
		}
		else if(num % 2 == 0){
			return;
		}
		else{
			for(int i = 3;i <= Math.sqrt(num); i +=2){
				if(num % i == 0){
					return;
				}
			}
		}
		count++;
	}

}

Measured memory_bytes: 30112
if __name__ == '__main__':
    data = input().split()
    data = [int(s) for s in data]
    outputmax = min(data)
    if data[0] == data[1] == data[2]:
        outputmin = data[1]
    else:
        outputmin = data[1] + data[2] - data[0]
        if (outputmin < 0):
            outputmin = 0
    print(str(outputmax) + " " + str(outputmin))

Measured memory_bytes: 3060
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    map<string, int> Smap;
    rep(i, N) {
        string S;
        cin >> S;
        Smap[S]++;
    }
    int max_num = 0;
    for (auto& s : Smap) {
        max_num = max(max_num, s.second);
    }

    for (auto& s : Smap) {
        if (s.second == max_num) {
            cout << s.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 23808
from collections import deque

def main():
    s = list(input())
    Q = int(input())
    Qry = []
    for i in range(Q):
        q = list(input().split())
        Qry.append(q)
    d = deque(s)

    flg = 0
    l = 0
    r = len(s) -1
    for i, q in enumerate(Qry):
        if int(q[0]) == 1:
            tmp = l
            l = r
            r = tmp
            if flg == 0:
                flg =1
            else:
                flg = 0
        if int(q[0]) == 2:
            if int(q[1]) == 1:
                if flg == 0:
                    d.appendleft(q[2])
                else:
                    d.append(q[2])
            if int(q[1]) == 2:
                if flg ==1:
                    d.appendleft(q[2])
                else:
                    d.append(q[2])
    ans = []
    if flg == 0:
        for _ in range(len(d)):
            ans.append(d.popleft())
    if flg == 1:
        for _ in range(len(d)):
            ans.append(d.pop())
    print(''.join(ans))

if __name__=='__main__':
    main()


Measured memory_bytes: 36104
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    ll res=1e18;
    int n;cin>>n;
    for(int i=0;i<n;i++){
        ll a,b;cin>>a>>b;
        res=min(res,a+b);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
bool u[100005];
int main()
{
	int n,k;
	while(1)
	{
		memset(u,0,sizeof(u));
		scanf("%d %d",&n,&k);
		int ret=0;
		if(!n) return 0;
		for(int i=0;i<k;i++)
		{
			int g; scanf("%d",&g);
			
			u[g]=true;
		}
		bool con=false;
		int val=0;
		vector<int>vec(0);
		for(int i=1;i<=n;i++)
		{
			if(con && !u[i])
			{
				vec.pb(val);
				val=con=0;
			}
			else if(u[i])
			{
				val++; con=1;
			}
			else
			{
				for(int i=0;i<vec.size();i++)
				{
					ret=max(ret,vec[i]);
				}
				if(u[0])
				{
					for(int i=1;i<vec.size();i++)
					{
						ret=max(ret,vec[i-1]+1+vec[i]);
					}
					for(int i=0;i<vec.size();i++)
					{
						ret=max(ret,vec[i]+1);
					}
				}
				vec.clear();
			}
		}
				if(val) vec.pb(val);
				for(int i=0;i<vec.size();i++)
				{
					ret=max(ret,vec[i]);
				}
				if(u[0])
				{
					for(int i=1;i<vec.size();i++)
					{
						ret=max(ret,vec[i-1]+1+vec[i]);
					}
					for(int i=0;i<vec.size();i++)
					{
						ret=max(ret,vec[i]+1);
					}
				}

		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1308
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    printf("%.8f\n",distance);
}



Measured memory_bytes: 3208
rank3 = 100000
rank2 = 200000
rank1 = 300000

# prize = {
#     "1": 300000,
#     "2": 200000,
#     "3": 100000
# }

x, y = input().split(' ')
x,y = int(x), int(y)

reward = 0

if x == 1:
    reward += rank1
elif x == 2:
    reward += rank2
elif x == 3:
    reward += rank3

if y == 1:
    reward += rank1
elif y == 2:
    reward += rank2
elif y == 3:
    reward += rank3

if x==1 and y==1:
    reward += 400000

print(reward)

Measured memory_bytes: 3064
//PLUS ULTRA

#include<bits/stdc++.h>
using namespace std;
     
     
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define mp make_pair
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define nfor(i,st,n) for(int i = st; i >= n ; i--)
#define ss second
#define ff first

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

const int N = 1e5 + 10 , mod =  1000000007;

void solve(){

	float pie = (6.28318530)/2;

	int r; cin >> r;

	printf("%0.4f\n", 2*pie*r);



}

int main(){
    //SPEED;

    solve();

    return 0;
}
      
       


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main() {
    map<char,char> mp;
    mp['A']='T';
    mp['T']='A';
    mp['C']='G';
    mp['G']='C';
    char c;
    cin>>c;
    cout<<mp[c];
    return 0;
}


Measured memory_bytes: 256
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3936103
#include <bits/stdc++.h>
using namespace std;

// 強連結成分分解(Strongly Connected Components).
struct SCC{
    const int INF = int(1e9);
    vector<vector<int>> vec;
    int index;
    vector<int> idx;
    vector<int> lowLink;
    vector<bool> onStack;
    stack<int> sccStack;
    vector<int> sccIndex;
    int sccCount;
    vector<int> topological;
    
    // lower sccIndex means appear later
    void init(int N){
        idx.assign(N, -1);
        index = 0;
        onStack.assign(N, 0);
        lowLink.assign(N, INF);
        while(!sccStack.empty()) sccStack.pop();
        sccIndex.assign(N, -1);
        sccCount = 0;
        vec.clear();
        topological.clear();
        vec.resize(N);
    }
    
    // u -> v
    void addEdge(int u, int v){ vec[u].push_back(v); }
    
    void connect(int u){
        idx[u] = index;
        lowLink[u] = index;
        index++;
        sccStack.push(u);
        onStack[u] = true;
        for(int i = 0; i < vec[u].size(); i++){
            int v = vec[u][i];
            if(idx[v] == -1){
                connect(v);
                lowLink[u] = min(lowLink[u], lowLink[v]);
            }else if(onStack[v]){
                lowLink[u] = min(lowLink[u], idx[v]);
            }
        }
        if(lowLink[u] == idx[u]){
            while(1){
                int v = sccStack.top();
                sccStack.pop();
                onStack[v] = false;
                sccIndex[v] = sccCount;
                if(v == u) break;
            }
            sccCount++;
        }
    }
    
    void tarjan(){
        for(int i = 0; i < vec.size(); i++) if(idx[i] == -1) connect(i);
    }
    
    // if graph is a DAG and i just want to topological sort.
    void topologicalSort(){
        tarjan();
        int N = vec.size();
        topological.resize(N);
        vector<pair<int, int>> tmp;
        for(int i = 0; i < N; i++) tmp.push_back({sccIndex[i], i});
        sort(tmp.begin(),tmp.end());
        reverse(tmp.begin(),tmp.end());
        for(int i = 0; i < N; i++){
            topological[i] = tmp[i].second;
            if(i > 0) assert(tmp[i].first != tmp[i - 1].first);
        }
    }
};

int dp[111111];
vector<int> adj[111111];

int main(){
    
    // 1. 入力情報取得.
    int N, M;
    scanf("%d %d", &N, &M);
    SCC scc;
    scc.init(N);
    
    // 2. グラフ構築.
    vector<pair<int, int>> E;
    for(int i = 0; i < M; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        scc.addEdge(u,v);
        E.push_back({u, v});
    }
    scc.tarjan();
    for(int i = 0; i < M; i++){
        int u = E[i].first;
        int v = E[i].second;
        adj[scc.sccIndex[u]].push_back(scc.sccIndex[v]);
    }
    
    // 3. dp更新.
    int ans = 0;
    for(int i = 0; i < N; i++){
        dp[i] = 1;
        for(int v : adj[i]) dp[i] = max(dp[i], dp[v] + 1);
        ans = max(ans, dp[i]);
    }
    // for(int i = 0; i < N; i++) printf("%d ", dp[i]);
    // printf("\n");
    
    // 4. 出力.
    printf("%d\n", ans - 1);
    return 0;
}

Measured memory_bytes: 15348
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>>request(m);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		request[i] = { b,a };
	}
	sort(request.begin(), request.end());

	int ans = 1;
	int cutL = 0, cutR = n + 1;
	for (int i = 0; i < m; i++) {
		if (cutL < request[i].second)cutL = request[i].second;
		if (cutR > request[i].first)cutR = request[i].first;
		else if (cutR <= request[i].second || cutL >= request[i].first) {
			ans++;
			cutL = request[i].second;
			cutR = request[i].first;
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {

  int N = 1;
  int A = 0;

  cin >> N;
  cin >> A;

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

}



Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.HashMap;

public class Main{
	

	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String dayofWeek[] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
		int days[] = {31,29,31,30,31,30,31,31,30,31,30,31};
		String input;
		while((input = br.readLine()) != null){
			String s[] = input.split(" ");
			int month = Integer.parseInt(s[0]);
			int day = Integer.parseInt(s[1]);
			
			if(month == 0 && day == 0){
				System.exit(0);
			}
			
			for(int i = 0;i <month -1;i++){
				day += days[i];
			}
			
			System.out.println(dayofWeek[(day-1)%7]);
		}
	}
}

Measured memory_bytes: 24192
N = int(input())
START = ord('a')
END = ord('z')
LEN = abs(START - END) + 1

def count(s):
    arr = [0 for _ in range(LEN)]
    for c in list(s):
        arr[ord(c) - START] += 1
    return arr

def main():
    curr = [float('inf') for _ in range(LEN)]
    for _ in range(N):
        s = input()
        counted = count(s)
        curr = [min(t) for t in zip(curr, counted)]
    ans = ''.join([chr(i + START) * n for i, n in enumerate(curr)])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  char b;
  cin>>b;
  if(b=='A'){
    cout<<'T'<<endl;
  }
  else if (b=='T'){
    cout<<'A'<<endl;
  }
  else if(b=='C'){
    cout<<'G'<<endl;
  }
  else{
    cout<<'C'<<endl;
  }
}
    

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

#ifdef DONLINE_JUDGE
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
// add i/o method of specific testing system
#endif

using namespace std;

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

    int i = 1, x;
    while (cin >> x, x)
    {
        cout << "Case " << i++ << ": " << x << endl;
    }

    return 0;
}


Measured memory_bytes: 3160
n = int(input())
l = list(map(int, input().split()))

a = []
b = []

for i in range(n):
    if i % 2 == 0:
        a.append(l[i])
    else:
        b.append(l[i])

def createMyList(li):
    d = {-1:(0,-1)}
    for e in li:
        if e not in d:
            d[e] = (1,e)
        else:
            d[e] = (d[e][0] + 1, d[e][1])
    return list(reversed(sorted(list(d.values()))))

la = createMyList(a)
lb = createMyList(b)
#print(la)
#print(lb)

if la[0][1] == lb[0][1]:
    ans = n- max(lb[0][0] + la[1][0], la[0][0] +lb[1][0])
else:
    ans = n - (la[0][0] + lb[0][0])
print(ans)


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


#define NMAX 105
#define WMAX 10005
// 選択する場合
#define DIAGONAL 1
// 選択しない場合
#define TOP 0

using namespace std;

// 価値と重さを持った構造体を定義
struct Item {
    int value,weight;
};
// 品物の数(入力により決められる)
int N;
// ナップザックの容量(入力により決められる)
int W;
// 入力された品物の価値と重さを保存する配列
Item items[NMAX + 1];
// 各々に価値の最適解を入れておく配列
int C[NMAX + 1][WMAX + 1];
// 各々の品物を選択するか選択しないかを入れておく配列
int G[NMAX + 1][WMAX + 1];

// maxValueに最大値が入るようになっている
int compute(vector<int>&selection){
    int maxValue = 0;
    for(int w = 0;w <= W;++w){
        C[0][w] = 0;
        G[0][w] = DIAGONAL;
    }
    
    for(int i = 1;i <= N;++i) C[i][0] = 0;
    
    for(int i = 1;i <= N;++i){
        for(int w = 1;w <= W;++w){
            C[i][w] = C[i - 1][w];
            G[i][w] = TOP;
            if(items[i].weight > w) continue;
            if(items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w]){
                C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
                G[i][w] = DIAGONAL;
            }
        }
    }
    
    maxValue = C[N][W];
    selection.clear();
    
    for(int i = N, w = W;i >= 1;--i){
        if(G[i][w] == DIAGONAL){
            selection.push_back(i);
            w -= items[i].weight;
        }
    }
    
    reverse(selection.begin(),selection.end());
    
    return maxValue;
}

int main(){
    int maxValue;
    vector<int> selection;
    
    // 入力処理
    cin >> N >> W;
    for(int i = 1;i <= N;++i){
        cin >> items[i].value >> items[i].weight;
    }
    maxValue = compute(selection);
    
    cout << maxValue << endl;
    return 0;
}



Measured memory_bytes: 11040
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int H,W;
  	cin >>H>>W;
  	string board[50];
  	for(int i=0;i<H*W;i++) cin>>board[i];
  	const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  	const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
  	for(int i=0;i<H;i++){
    	for(int j=0;j<W;j++){
        	if(board[i][j]=='#')continue;
          	int num =0;
          	for(int d =0;d<8;d++){
              	const int ni = i + dx[d];
              	const int nj = j + dy[d];
              	if(ni < 0 or H <= ni) continue;
              	if(nj < 0 or W <= nj) continue;
              	if(board[ni][nj] == '#') num++;
            }
          	board[i][j] = char(num + '0');
        }
    }
  	for (int i = 0; i < H; ++i) cout << board[i] << endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int a, b, c;

int main(void) {
  // Here your code !
  scanf("%d %d %d", &a, &b, &c);

  printf("%d\n", max(0, c - (a - b)));

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int c1, c5, c10, c50, c100, c500;
	int satu, sum;
	
	satu = 0;
	
	scanf("%d %d %d %d %d %d", &c1, &c5, &c10, &c50, &c100, &c500);
	
	sum = c1 * 1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;
	
	if (sum >= 1000){
		satu++;
	}
	
	printf("%d\n", satu);
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
const int INF=1e9;
//const int MOD=1e9+7;
const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
std::vector<int> Factorial(5234567),Finverse(5234567);
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
void Cinit(){
  Factorial[0]=1;
  for(int i=1;i<5234567;i++)Factorial[i]=Factorial[i-1]*i%MOD;
  for(int i=0;i<5234567;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 1;if(k<0)return 0;
  int res=Factorial[n];
  res*=Finverse[k];res%=MOD;
  res*=Finverse[n-k];res%=MOD;
  return res;
}
//main
signed main(){
  Cinit();
  int N,M;cin>>N>>M;
  int ans=nCk(3*M+(N-1),N-1);//cout<<ans<<endl;
  int mi=N*nCk(M-1+N-1,N-1)%MOD;
  ans-=mi;
  ans+=MOD;ans%=MOD;
  //cout<<ans<<endl;
  for(int i=M+1;i<=min(N,3*M);i++){
    if((i&1)!=((3*M)&1))continue;
    int p=(3*M-i)/2;
    int q=nCk(p+N-1,N-1);
    int s=nCk(N,i);
    int a=q*s%MOD;
    ans-=a;
    ans+=MOD;ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 82176
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

long long power(long long x, long long n, long long mod = 1000000007) {
    if (n == 0) return 1;
    if (n % 2 == 0) return power(x * x % mod, n/2, mod);
    else return x * power(x, n-1, mod) % mod;
}

LL dfs(VLL &kai, VVI &es, int &n, int &k, int s, int par) {
    int cs = es[s].size();
    if (cs + 1 > k) return 0;
    LL p = (kai[k-2] * power(kai[k-2-(cs-1)], MOD-2)) % MOD;
    
    for (auto &&v: es[s]) {
        //++cnt;
        if (v == par) continue;
        p = (p * dfs(kai, es, n, k, v, s)) % MOD;
    }

    return p;
}

void solve() {
    int n,k;
    cin >> n >> k;
    VLL kai(k+1,1);
    REP(i,2,k+1) kai[i] = (kai[i-1] * i) % MOD;

    VVI es(n);
    int a,b;
    REP(i,0,n-1) {
        cin >> a >> b;
        --a; --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    int cs = es[0].size();
    if (cs + 1 > k) {
        cout << 0 << endl;
        return;
    }
    LL p = (kai[k] * power(kai[k-cs-1], MOD-2)) % MOD;
    for (auto &&v: es[0]) {
        //dump(cs);
        p = (p * dfs(kai, es, n, k, v, 0)) % MOD;
    }
    cout << p << endl;
}

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

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N;
vector<int> a;

int main(){
  cin >> N;
  a.resize(N);
  REP(i, N){
    cin >> a[i];
  }

  int cnt2 = 0, cnt4 = 0;
  REP(i, N){
    if(a[i] % 4 == 0){
      cnt4++;
    }
    else if(a[i] % 2 == 0){
      cnt2++;
    }
  }

  if(cnt4 >= N/2 || cnt4*2+cnt2 >= N){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

long long int memo[90] = { 0 };

long long int func (int n) {
    if (n == 0)  return 2;
    if (n == 1)  return 1;
    if (memo[n]) return memo[n];

    return memo[n] = func(n-1) + func(n-2);
}

int main() {
    int n;

    cin >> n;

    cout << func(n) << endl;

    return 0;
}

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

#define ll lon long 
using namespace std;


int main(){
    string S;
    int cnt=0;
    cin >> S;
    for(int i = 0; i < 4; i++){
        cnt = 0;
        for(int j = 0; j < 4; j++){
            if(i != j){
                if(S[i] == S[j])cnt++;
            } 
        }
        if(cnt != 1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 504
import sys
input = sys.stdin.readline
n,w=map(int,input().split())

w1,v1=map(int,input().split())
W,V=[0],[v1]
for i in range(n-1):
  wi,vi=map(int,input().split())
  W.append(wi-w1)
  V.append(vi)
DP=[[[0]*(n+1) for _ in range(3*n+1)] for __ in range(n+1)]
for i in range(1,n+1):
  for j in range(3*i+1):
    for k in range(1,i+1):
      if j<W[i-1]:
        DP[i][j][k]=DP[i-1][j][k]
      else:
        DP[i][j][k]=max(DP[i-1][j-W[i-1]][k-1]+V[i-1],DP[i-1][j][k])
ans=0
for j in range(3*n+1):
  for k in range(n+1):
    if j+w1*k<=w:
      ans=max(ans,DP[n][j][k])
print(ans)

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

int A[100];

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

    int n,m,t;
    cin>>n>>m>>t;
    REP(i,n) cin>>A[i];

    int ans=A[0]-m;
    REP(i,n-1){
        int d=A[i+1]-A[i];
        ans+=max(0LL,d-2*m);
    }
    int rest=t-A[n-1];
    ans+=max(0LL,rest-m);
    cout<<ans<<endl;
}



Measured memory_bytes: 3216
#include <cstdio>
#include <cstdlib>
#include <cstring>

const int STR_LENGTH = 13;
const int M = 1000117;

char T[M][STR_LENGTH];

int h1(int k) { return k % M; }
int h2(int k) { return 1 + (k % (M - 1)); }
int h(int k, int i) { return (h1(k) + i * h2(k)) % M;}

int char2int(char c) {
  if (c == 'A') return 1;
  if (c == 'C') return 2;
  if (c == 'G') return 3;
  if (c == 'T') return 4;
  return 0;
}

int genKey(char str[]) {
  int key = 0;
  int p = 5;
  for (int i = 0; i < std::strlen(str); ++i) {
    key += p * char2int(str[i]);
    p *= 5;
  }
  return key;
}

bool insert(char str[]) {
  int key = genKey(str);
  for (int i = 0;; ++i) {
    int j = h(key, i);
    if (std::strcmp(T[j], str) == 0) return false;
    else if (std::strlen(T[j]) == 0) {
      std::strcpy(T[j], str);
      return true;
    }
  }
  return false;
}

bool find(char str[]) {
  int key = genKey(str);
  for (int i = 0;; ++i) {
    int j = h(key, i);
    if (std::strcmp(T[j],str) == 0) return true;
    else if (std::strlen(T[j]) == 0) return false;
  }
  return false;
}

int main() {
  int n;
  char com[6], str[STR_LENGTH];
  for (int i = 0; i < M; ++i) T[i][0] = '\0';

  std::scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    std::scanf("%s%s", com, str);
    if (com[0] == 'i') insert(str);
    else if (com[0] == 'f') {
      bool result = find(str);
      std::printf("%s\n", result ? "yes" : "no");
    }
  }
}



Measured memory_bytes: 15464
#include <bits/stdc++.h>
#define ll long long int
#define N 100
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.141592653
#define cot cout.tie(0)
#define endl "\n"
using namespace std;
/**
  * @author :: Sawlani
  *
  */

const ll M=1e9+7;
ll dp[2001];
ll rec(ll sum)
{
    int ans=0;
    
    if(sum==0)
        return 1;
    else if(sum<3)
        return 0;
    
    if(dp[sum]!=-1)
        return dp[sum];
    for(int i=3;i<=sum;i++)
    {
        ans=(ans+rec(sum-i))%M;
    }

    return dp[sum]=ans;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    ll s;
    cin >> s;

    cout << rec(s);
}

Measured memory_bytes: 3660