akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
#define vi vector<int>
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
const int nax=1e6+10;

void solve(){
    int x,n;cin>>x>>n;
    set<int> st;
    int tp;
    fr(i,0,n-1){
        cin>>tp;
        st.insert(tp);
    }
    ll mx=INT_MAX;
    ll pos;
    fr(i,0,200)
    if(st.find(i)==st.end()){
        if(mx>(abs(x-i))){
            mx=abs(x-i);
            pos=i;
        }
    }
    cout<<pos<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool flg = true;
    for (int i = 1; i < 3; i++)
        flg &= s[i-1] == s[i];
    cout << (flg ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	getline(cin,s);
	int l=s.length();
	int f=0,c=0;
	for(int i=0; i<l; i++) {
	//	cout<<s[i]<<" "<<s[l-i-1]<<endl;
		if(s[i]!=s[l-i-1]) {
			f=1;
			break;
		}
	}
//	if(f)
//		cout<<"no"<<endl;
//	else
//		cout<<"yes"<<endl;
	int l1=(l-1)/2,a=0;
	int l2=(l+3)/2,b=0;
	for(int i=0; i<l1; i++) {
	//	cout<<s[i]<<" "<<s[l1-i-1]<<endl;
		if(s[i]!=s[l1-i-1]) {
			a=1;
			break;
		}
	}
	for(int i=l2; i<l; i++) {
	//	cout<<s[i]<<" "<<s[l-i-1]<<endl;
		if(s[i]!=s[l-i-1]) {
			b=1;
			break;
		}
	}
	if(!f && !a && !b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	//main();

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if (A == B && B == C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl



int main() {
    IN(string, s);
    bool ans = false;
    if (s[2] == s[3] && s[4] == s[5]) {
        ans = true;
    }
    Yes(ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    ini(A, B);
    out((A + B) % 24);
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int mod=1000000007;
const int N=1000005;
int n,n2,f[N],sm[N];
inline void up(int &x,int y) {x+=y;if(x>=mod) x-=mod;}
int main( )
{
  int i,j;
  n=read( );j=n-2;n2=(LL)(n-1)*(n-1)%mod;
  f[0]=1;sm[0]=1;
  for(i=1;i<=n;i++)
    {
      f[i]=(i>=3)?sm[i-3]:0;sm[i]=sm[i-1];
      up(f[i],f[i-1]);up(sm[i],f[i]);
    }
  int ans=0;
  for(i=0;i<=j;i++) up(ans,(LL)f[i]*n2%mod); //_+XY
  for(i=0;i<=j;i++) up(ans,(LL)f[i]*(i+1)%mod); //_+X+X*1 over n
  up(ans,(LL)f[n-1]*(n-1)%mod); //_+X
  printf("%d",(ans+f[n])%mod); //_
  return 0;
}

Measured memory_bytes: 8064
import java.util.*;
public class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   int r = sc.nextInt();
   if(n>=10) System.out.println(""+r);
   else System.out.println(""+(r+100*(10-n)));
 }
}

Measured memory_bytes: 21460
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]
K = int(input())
print(a[K-1])

Measured memory_bytes: 3060
#include <stdio.h>
#include<stdlib.h>
int comp( const void *c1, const void *c2 );

int main(void){
    int n, k, a[200001]={0};
    int i, d, c, s;
    
    scanf("%d %d", &n, &k);
    for(i = 0; i < n; i++){
        scanf("%d", &d);
        a[d]++;
    }
    c = 0;
    for(i = 0; i <= n; i++){
        if(a[i] > 0){
            c++;
        }else{
            a[i] = n + 1;
        }
    }
    qsort(a, n+1, sizeof(int), comp);
    s = 0;
    for(i = 0; i < (c - k); i++){
        s += a[i];
    }
    printf("%d\n", s);
    
    return 0;
}

int comp( const void *c1, const void *c2 )
{
  int tmp1 = *(int *)c1;
  int tmp2 = *(int *)c2;
 
  if( tmp1 < tmp2 )  return -1;
  if( tmp1 == tmp2 ) return  0;
  if( tmp1 > tmp2 )  return  1;
}

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

int main(){
  int h, n;
  cin >> h >> n;

  vector<int> a(n);
  int sum=0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    sum += a[i];
  }

  if(sum >= h) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int maxn=1e6+10;
const int mod=1000000000+7;
const double eps=1e-6;


int main() {
   // freopen("test.txt","r",stdin);
   string s;
    cin>>s;
    if(s.size()%2==0) {
        cout<<"No"<<endl;
        return 0;
    }
    int n=s.size();
    int l=0,r=(n-1)/2-1;
    while(l<=r) {
        if(s[l]!=s[r]) {
            cout<<"No"<<endl;
            return 0;
        }
        l++,r--;
    }
    for(int i=0;i<=(n-1)/2-1;i++) {
        if(s[i]!=s[i+(n+1)/2]) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
/*
500 500 1
YES
2
1 RDU
1 R

*/


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

const int MOD = 1e9 + 7;

int fanc(int n, int m) {
	i64 a = 1;
	rep2(i, 2, n) a = (a*i) % MOD;
	i64 b = 1;
	rep2(i, 2, m) b = (b*i) % MOD;
	return (a*b) % MOD;
}

int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	if (abs(n - m) == 1) {
		ans = fanc(n, m);
	}
	else if (n - m == 0) {
		ans = fanc(n, m);
		ans = (ans * 2) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def main():
    inf = 5000
    n = int(input()[:-1])
    # iより前に色cのj以上が何個あるかがcnts[c][i][j]
    cnts = [[[0] * (n + 1) for _ in range(2 * n + 1)] for __ in range(2)]
    pos = [[0] * n for _ in range(2)]
    for i in range(n * 2):
        c, a = input().split()
        c = (c == "W") * 1
        a = int(a) - 1
        pos[c][a] = i
        for cc in range(2):
            for j in range(n):
                if c == cc and a >= j:
                    cnts[cc][i + 1][j] = cnts[cc][i][j] + 1
                else:
                    cnts[cc][i + 1][j] = cnts[cc][i][j]
    #    for x in cnts:
    #        print(x)
    #    print(pos)

    dp = [[inf] * (n + 1) for _ in range(n + 1)]
    dp[0][0] = 0
    for w in range(1, n + 1):
        i = pos[1][w - 1]
        dp[0][w] = dp[0][w - 1] + cnts[0][i][0] + cnts[1][i][w - 1]
    for b in range(1, n + 1):
        i = pos[0][b - 1]
        dp[b][0] = dp[b - 1][0] + cnts[0][i][b - 1] + cnts[1][i][0]
    for b in range(1, n + 1):
        for w in range(1, n + 1):
            bi = pos[0][b - 1]
            wi = pos[1][w - 1]
            dp[b][w] = min(dp[b - 1][w] + cnts[0][bi][b - 1] + cnts[1][bi][w],
                           dp[b][w - 1] + cnts[0][wi][b] + cnts[1][wi][w - 1])
    print(dp[n][n])

main()


Measured memory_bytes: 192520
import java.util.*;
public class Main{

 public static void main(String[] args) {
  Scanner no=new Scanner(System.in);
  String arr[]=new String[3];
  for(int i=0;i<3;i++){
    arr[i]=no.next();
  }
  int i=0;
  int j=0;
  int k=0;
  char c='a';
  while(true){
    if(c=='a'){
      if(i==arr[0].length()){
        System.out.println("A");
        break;
      }
      c=arr[c-'a'].charAt(i++);
    }
    else if(c=='b'){
      if(j==arr[1].length()){
        System.out.println("B");
        break;
      }
      c=arr[c-'a'].charAt(j++);
    }
    else{
      if(k==arr[2].length()){
        System.out.println("C");
        break;
      }
      c=arr[c-'a'].charAt(k++);
    }
  }
 }
}

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

int N, K;
vector<int> A(100001, 0);

int main(void){
    
    cin >> N >> K;
    for(int i = 0; i < N; ++i) cin >> A[i];
    
    int ans = 1;
    for(int j = K; j < N; j += K - 1) ++ans;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
def solve(string):
    x = int(string)
    a = {i**5: i for i in range(-10000, 10000)}
    for i in range(-10000, 10000):
        if x + i ** 5 in a:
            return str(f"{a[x+i**5]} {i}")


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)

string s;
string ss[10];
string S[25005];
map<string,ll> mp;
ll K;
ll n;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>s>>K;

ll n=0; 
ll sz=s.size();
rep(i,sz){
	ss[0]=s.substr(i,1);
	ss[1]=s.substr(i,2);
	ss[2]=s.substr(i,3);
	ss[3]=s.substr(i,4);
	ss[4]=s.substr(i,5);

	rep(k,5){
		if(i+k>=sz) continue;
		if(mp[ss[k]]==0){
		S[n]=ss[k]; n++;
		mp[ss[k]]++;
		}
	}
}


sort(S,S+n);

cout<<S[K-1]<<endl;

}
	


Measured memory_bytes: 2048
import math
n,m = map(int,input().split())
if abs(n-m) > 1:
  print(0)
elif n == m:
  print((math.factorial(n)**2)*2 % 1000000007)
else:
  print(math.factorial(max(n,m))*math.factorial(min(n,m)) % 1000000007)

Measured memory_bytes: 5192
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  ll n;cin>>n;
  string s;
  vector<int>a(26,0);
  
  rep(i,n){
    cin>>s;
    rep(j,26){
      char x='a'+j;
      if(i==0)a[j]+=count(all(s),x);
      else a[j]=min(a[j],(int)count(all(s),x));
    }
  }
  rep(i,26){
    rep(j,a[i])cout<<(char)('a'+i);
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N;

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

    cin >> N;
    int pt = 0, px = 0, py = 0;
    bool yes = true;
    REP (i, N) {
        int t, x, y;
        cin >> t >> x >> y;
        int dt = t - pt;
        int dx = abs(x - px);
        int dy = abs(y - py);
        if (dx + dy > dt || (dt - dx - dy) % 2) {
            yes = false;
        }
    }
    cout << (yes ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
  
    int sum = min({a + b, b + c, c + a});
    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 256
N = int(input())
mi = 100000
for q in range(11120):
    a = 0
    n = q*9
    pn = N-n
    if(n>N) : break;
    for i in range(6,0,-1):
        if(n >= 9**i) :
            a += n//(9**i)
            n%=(9**i)
    for i in range(8,0,-1):
        if(pn >= 6**i) :
            a += pn//(6**i)
            pn%=(6**i)
    a += pn;
    mi = min(mi,a)
print(mi)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
n,m = (int(i) for i in input().split())
ab = [[int(i)-1 for i in input().split()] for i in range(m)]

ab = list(filter(lambda x:x[0]==0 or x[1]==n-1, ab))
ab0 = list(filter(lambda x:x[0]==0,ab))
abn = list(filter(lambda x:x[1]==n-1,ab))

ab0_bin = ["0"]*n
abn_bin = ["0"]*n
for x in ab0:
    ab0_bin[x[1]] = "1"
for x in abn:
    abn_bin[x[0]] = "1"

ab0_bin = "".join(ab0_bin)
abn_bin = "".join(abn_bin)

if bin(int(ab0_bin,2) & int(abn_bin, 2))[2:].count("1") > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

long long x, y;

int main(void){
	scanf("%lld%lld", &x, &y);
	long long t = __gcd(x, y);
	x = x / t;
	y = y / t;
	long long ans = t * x * (y - 1);
	if (ans == 0) return 0 * printf("%d\n", -1);
	cout << ans << endl;	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
const ll M = 1000000007;
long int dp[4002];
int main()
{
	int s;
	cin>>s;
	dp[0]=1;
	loop(i,0,s-2)
	{
		if(dp[i])
		loop(j,3,s+1)
		{
			dp[i+j]+=dp[i];
			dp[i+j]%=M;
		}
	}
	cout<<dp[s];
}

Measured memory_bytes: 3580
import java.util.*;
 public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      int H = sc.nextInt();
      int N = sc.nextInt();
      int[] A = new int[N];

      for(int i = 0;i < A.length;i++){
       A[i] = sc.nextInt();
      }

      for(int i = 0;i < A.length;i++){
       H -= A[i];
      }

      if(H <= 0){
       System.out.print("Yes");
      }else{
       System.out.print("No");
      }

      
   }
 }

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

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a>=b)
    cout << b*c + (a-b)*d << endl;
    else
        cout << a*c << endl;
}


Measured memory_bytes: 3476
import sys
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
A = LIST()

A.sort(reverse=1)
que = [-A[0]]
ans = 0
for i in range(1, N):
    cur = -heappop(que)
    ans += cur
    heappush(que, -A[i])
    heappush(que, -A[i])
print(ans)


Measured memory_bytes: 33204
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)

using namespace std;

const int maxn=2e5+5,G=5,md=924844033;

int f[maxn*4],F[maxn],b[maxn*4],t[maxn*4],size[maxn];
int w[maxn*4],_w[maxn*4],cc[maxn],inv[maxn];
int fi[maxn],ne[maxn*2],dui[maxn*2],qc[maxn];
int i,j,k,l,m,n,now,x,y,N,ans;

void add(int x,int y){
	if (fi[x]==0) fi[x]=++now; else ne[qc[x]]=++now;
	dui[now]=y; qc[x]=now;
}
int quickmi(int x,int y){
	int t1=1;
	while (y){
		if ((y & 1)==1) t1=1ll*t1*x%md;
		x=1ll*x*x%md;
		y=y/2;
	}
	return t1;
}
void dfs(int x,int y){
	size[x]=1;
	for(int i=fi[x];i;i=ne[i]) if (dui[i]!=y){
		dfs(dui[i],x);
		F[size[dui[i]]]++; F[n-size[dui[i]]]++;
		size[x]=size[x]+size[dui[i]];
	}
}
void Ge_N(){
	N=1;
	while (N<=n) N=N*2;
	N=N*2;
}
void Ge_W(){
	w[0]=w[N]=1;
	int t=quickmi(G,(md-1)/N);
	fo(i,1,N-1) w[i]=1ll*w[i-1]*t%md;
	fo(i,0,N) _w[i]=w[N-i];
}
int reversal(int x){
	int t=0;
	for(int i=1;i<N;i<<=1,x>>=1) t=(t<<1)+(1&x);
	return t;
}
void DFT(int *x,int *w){
	int i,j,k,m,tmp;
	fo(i,0,N-1) t[i]=x[i];
	fo(i,0,N-1) x[reversal(i)]=t[i];
	for(i=2,m=1;i<=N;i<<=1,m<<=1){
		for(j=0;j<N;j+=i){
			fo(k,0,m-1){
				tmp=1ll*x[j+k+m]*w[N/i*k]%md;
				x[j+k+m]=(x[j+k]-tmp+md)%md;
				x[j+k]=(x[j+k]+tmp)%md;
			}
		}
	}
}
int C(int y,int x){
	return 1ll*inv[x]*inv[y-x]%md*cc[y]%md;
}
int main(){
//	freopen("t4.in","r",stdin);
	scanf("%d",&n);
	fo(i,1,n-1){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	cc[0]=1; inv[0]=1;
	fo(i,1,n){
		cc[i]=1ll*cc[i-1]*i%md;
		inv[i]=quickmi(cc[i],md-2);
	}
	dfs(1,0);
	l=1; b[0]=1;
	fo(i,1,n){
		l=1ll*l*i%md;
		f[n-i]=1ll*F[i]*l%md;
		b[i]=quickmi(l,md-2);
	}
	Ge_N();
	Ge_W();
	DFT(f,w);
	DFT(b,w);
	fo(i,0,N) f[i]=1ll*f[i]*b[i]%md;
	DFT(f,_w);
	l=quickmi(N,md-2);
	fo(i,0,n) f[i]=1ll*f[i]*l%md;
	l=1;
	fo(i,1,n){
		l=1ll*l*i%md;
		ans=(1ll*C(n,i)*n-1ll*f[n-i]*inv[i]%md+md)%md;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 32640
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e18 + 7)
using namespace std;

int x, y, z, n, nn = 0;

long long ans = 0, ans2 = -inf, l[100005], r[100005];

struct node
{
    long long a, b;
    node(long long _a = 0, long long _b = 0)
    {
        a = _a;
        b = _b;
    }
}nd[100005];

bool cmp(const node & a, const node & b)
{
    return a.a - a.b > b.a - b.b;
}

struct cmp2
{
    bool operator()(node a, node b)
    {
        return a.a > b.a;
    }
};

struct cmp3
{
    bool operator()(node a, node b)
    {
        return a.b > b.b;
    }
};

priority_queue<node, vector<node>, cmp2> q;
priority_queue<node, vector<node>, cmp3> q2;

int main()
{
    long long a, b, c;
    scanf("%d%d%d", &x, &y, &z);
    n = x + y + z;
    for(int i = 1;i <= n;i++)
    {
        scanf("%lld%lld%lld", &a, &b, &c);
        ans += c;
        nd[i] = node(a - c, b - c);
    }
    sort(nd + 1, nd + 1 + n, cmp);
    long long res = 0;
    for(int i = 1;i <= x;i++)
        res += nd[i].a, q.push(nd[i]);
    l[x] = res;
    for(int i = x + 1;i <= n;i++)
    {
        res += nd[i].a;
        q.push(nd[i]);
        node u = q.top();
        q.pop();
        res -= u.a;
        l[i] = res;
    }
    res = 0;
    for(int i = n;i > n - y;i--)
        res += nd[i].b, q2.push(nd[i]);
    r[n - y + 1] = res;
    for(int i = n - y;i >= 1;i--)
    {
        res += nd[i].b;
        q2.push(nd[i]);
        node u = q2.top();
        q2.pop();
        res -= u.b;
        r[i] = res;
    }
    for(int i = x;i <= n - y;i++)
        ans2 = max(ans2, l[i] + r[i + 1]);
    printf("%lld\n", ans + ans2);
    return 0;
}


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

int n, u, v, ans, d[2][100005];
vector<int> gr[100005];

void f(int p, int q, int z) {
	if(q!=-1) d[z][p] = d[z][q] + 1;
	for(int x:gr[p]) {
		if(x==q) continue;
		if(z==0 || d[1][p]+1 < d[0][x]) f(x, p, z);
	}
}

int main() {
	int i, t1, t2;
	cin >> n >> u >> v;
	for(i=0; i<n-1; i++) {
		scanf("%d%d", &t1, &t2);
		gr[t1].push_back(t2);
		gr[t2].push_back(t1);
	}
	f(v, -1, 0);
	for(i=1; i<=n; i++) d[1][i] = 1e9;
	d[1][u] = 0;
	f(u, -1, 1);
	for(i=1; i<=n; i++) if(d[1][i] != 1e9) ans = max(ans, d[0][i]-1);
	cout << ans;
	return 0;
}

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

int main() {
	int a;
	int b;
	int c;
	cin>>a;
	cin>>b;
	a*=b;
	cin>>b;
	cin>>c;
	b*=c;
	if(b>a){
		cout<<b<<endl;
	}
	else{
		cout<<a<<endl;
	}
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N;
	vector<llong> A;

	cin >> N;
	A.resize(N);
	for(int i = 0; i < N; i++)
		cin >> A[i];
	A.push_back(inf);

	llong ans = 0;
	llong before = A[0];
	llong dir = 0;
	for(int i = 1; i < N; i++){
		if(dir == 0){
			if(A[i] > before)
				dir = 1;
			else if(A[i] < before)
				dir = -1;
		}else{
			if((dir == 1 && A[i] < before) || (dir == -1 && A[i] > before)){
				cerr << i << endl;
				ans++, dir = 0;
			}
		}
		before = A[i];
	}

	if(before != inf)
		ans++;

	cout << ans << endl;


	return 0;
}

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

#define M 454545/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M/* your task */; }
int h2(int key){ return 1+(key%(M-1))/* your task */; }

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

int find(char str[]){
    /* your task */
    long long key,i=0,j;
    key=getKey(str);
    while(1){
        j=h(key,i);
        if(strcmp(H[j],str)==0){
            return 1;
        }else if(strlen(H[j])==0){
            return 0;
        }
        i++;
    }
}

int insert(char str[]){
    /* your task */
    long long key,i=0,j;
    key=getKey(str);
    while(1){
        j=h(key,i);
        if(strcmp(H[j],str)==0)
            return 1;
        else if(strlen(H[j])==0){
            strcpy(H[j],str);
            return 0;
        }
        i++;
    }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 7952
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
constexpr lint MOD = 1000000007;
int N, M;

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

struct constraint {
    constraint(int r, int l, int x) : r(r), l(l), x(x) {}
    int r, l, x;
};

lint dp[301][301][301]; // dp[i][j][k] i文字目が赤で最後の緑がj、最後の青がkの場合の数
vector<constraint> con;

int main() {

    cin >> N >> M;
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i=0; i<M; i++)
    {
        int l, r, x;
        cin >> l >> r >> x;
        con.push_back(constraint(r, l, x));
    }
    sort(con.begin(), con.end(), [](const auto &a, const auto &b){return a.r < b.r;});

    int m = 0;
    FOR(i, 1, N+1)
    {
        REP(j, i) REP(k, i)
        {
            dp[i][j][k] = dp[i-1][j][k];
        }
        REP(j, i-1)
        {
            REP(k, i-1) (dp[i][i-1][j] += dp[i-1][k][j]) %= MOD;
            dp[i][j][i-1] = dp[i][i-1][j];
        }

        while (m < M && con[m].r == i)
        {
            if (con[m].x == 1) {
                FOR(j, con[m].l, i) REP(k, i) dp[i][j][k] = dp[i][k][j] = 0;
            }
            if (con[m].x == 2) {
                FOR(j, con[m].l, i) FOR(k, con[m].l, i) dp[i][j][k] = 0;
                REP(j, con[m].l) REP(k, con[m].l) dp[i][j][k] = 0;
            }
            if (con[m].x == 3) {
                REP(j, i) REP(k, i) if (min(j, k)<con[m].l) dp[i][j][k] = 0;
            }
            m++;
        }
    }
    lint ans = 0;
    REP(j, N) REP(k, N) (ans += dp[N][j][k]) %= MOD;
    cout << ans * 3 % MOD << endl;
}


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

const int nil = -1;

struct Node { int  p, l, r; };

void calcDepth(int nod, int dep, const vector<Node>& T, vector<int>& D)
{
    if (nod == nil) return;
    D[nod] = dep;
    calcDepth(T[nod].r, dep + 1, T, D);
    calcDepth(T[nod].l, dep + 1, T, D);
}
int calcHeight(int nod, const vector<Node>& T, vector<int>& H)
{
    int h1 = 0, h2 = 0;
    if (T[nod].l != nil) h1 = calcHeight(T[nod].l, T, H) + 1;
    if (T[nod].r != nil) h2 = calcHeight(T[nod].r, T, H) + 1;
    return H[nod] = max(h1, h2);
}
int getSibling(int nod, const vector<Node>& T)
{
    if (T[nod].p == nil) return nil;
    if (T[T[nod].p].l != nod && T[T[nod].p].l != nil) return T[T[nod].p].l;
    if (T[T[nod].p].r != nod && T[T[nod].p].r != nil) return T[T[nod].p].r;
    return nil;
}
void print(int nod, const vector<Node>& T, const vector<int>& D, const vector<int>& H)
{
    cout << "node " << nod
         << ": parent = " << T[nod].p
         << ", sibling = " << getSibling(nod, T)
         << ", degree = " << (T[nod].r != nil) + (T[nod].l != nil)
         << ", depth = " << D[nod]
         << ", height = " << H[nod]
         << ", "
         << (T[nod].p == nil ? "root" : T[nod].l == nil && T[nod].r == nil ? "leaf" : "internal node");

    cout << endl;
}
int main()
{
    int N;
    cin >> N;

    vector<Node> bTree(N, { nil, nil, nil });

    for (int i = 0; i < N; i++) {
        int id, left, right;
        cin >> id >> left >> right;
        bTree[id].l = left;
        bTree[id].r = right;
        if (left != nil)bTree[left].p = id;
        if (right != nil)bTree[right].p = id;
    }

    int root;
    for (int i = 0; i < N; i++) {
        if (bTree[i].p == nil) root = i;
    }

    vector<int> Depth(N);
    calcDepth(root, 0, bTree, Depth);

    vector<int> Height(N);
    calcHeight(root, bTree, Height);

    for (int i = 0; i < N; i++) print(i, bTree, Depth, Height);

    return 0;
}



Measured memory_bytes: 3104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc146_a solver = new abc146_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc146_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            if (S.compareTo("SUN") == 0) {
                out.println(7);
            } else if (S.compareTo("SAT") == 0) {
                out.println("1");
            } else if (S.compareTo("FRI") == 0) {
                out.println(2);

            } else if (S.compareTo("THU") == 0) {
                out.println(3);
            } else if (S.compareTo("WED") == 0) {
                out.println(4);

            } else if (S.compareTo("TUE") == 0) {
                out.println(5);
            } else if (S.compareTo("MON") == 0) {
                out.println(6);
            }


        }

    }
}



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

int main(){
	double v, t, y;
	int n, h[100000];
	
	for(int i=0 ; i<100000 ; i++){
		h[i] = i*5-5;
	}

	while(cin >> v){
		t = v / 9.8;
		y = t*t*4.9;
		n = (int)( (y+5.0)/5.0 );
		for(int i=0 ; i<100000 ; i++){
			if(h[i]>=y){
				n = i;
				break;
			}
		}
		cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    t = 'AKIHABARA'
    l = len(t)
    ti = 0
    for c in s:
        if ti >= l:
            return 'NO'
        if t[ti] == c:
            ti += 1
        else:
            while ti < l and t[ti] == 'A' and t[ti] != c:
                ti += 1
            if ti >= l or t[ti] != c:
                return 'NO'
            ti += 1

    while ti < l and t[ti] == 'A':
        ti += 1
    if ti == l:
        return 'YES'

    return 'NO'



print(main())




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    int cnt=0;
    rep(i,n){
        if (s[i]=='('){
            cnt++;
        }
    }
    int cnt2 = n-cnt;
    int idx = 0;
    int t=0;
    rep(i,n){
        if (s[i]!='(') continue;
        while(idx<n && s[idx]=='(' || i>=idx){
            idx++;
        }
        if (s[idx]!=')') break;
        t++;
        idx++;
    }
    rep(i,cnt2-t){
        s = "("+s;
    }
    rep(i,cnt-t){
        s += ")";
    }
    cout<<s<<endl;
    return 0;
}


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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string S, T; cin >> S >> T;
	int life = 2;
	int s = 0, t = 0;
	rep(i, 0, S.size()) {
		if (i % 2 == 1) {
			while (t < T.size() && S[i] != T[t])
				t++;
			t++;
		}
		else {
			while (s < S.size() && S[i] != S[s])
				s++;
			s++;
		}
	}
	dump(s); dump(t);
	if (t > T.size() || s > S.size())life--;
	s = 0, t = 0;
	rep(i, 0, S.size()) {
		if (i % 2 == 0) {
			while (t < T.size() && S[i] != T[t])
				t++;
			t++;
		}
		else {
			while (s < S.size() && S[i] != S[s])
				s++;
			s++;
		}
	}
	dump(s); dump(t);
	if (t > T.size() || s > S.size())life--;
	if (life) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

dp = [[-1]*n for i in range(n)]
for i in range(n):
    dp[i][i] = 0
cumsum = [0]
for i in range(n):
    cumsum.append(cumsum[-1] + a[i])

def calc_cost(left, right):
    if dp[left][right] >= 0:
        return dp[left][right]
    min_ = min(calc_cost(left, i) + calc_cost(i+1, right) for i in range(left, right))
    dp[left][right] = cumsum[right+1]-cumsum[left] + min_
    return dp[left][right]

print(calc_cost(0,n-1))

Measured memory_bytes: 45020
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    A, B = MAP()
    if A - 1 > B:
        print(2 * A - 1)
    elif A < B - 1:
        print(2 * B - 1)
    else:
        print(A + B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
N,M = map(int,input().split())
#if 'AC':{1:-1}
#if 'WA'*2:{1:2}
problems = {}
correct = 0
penalty = 0
for i in range(M):
    p,s = map(str,input().split())
    p = int(p)
   
    if p not in problems.keys():
        if s == 'AC':
            problems[p] = -1
            correct += 1
        else: #if s == 'WA' and not ACed yet 
            problems[p] = 1
    else: 
        if s == 'AC' and problems[p] != -1: #first AC
            penalty += problems[p]
            problems[p] = -1
            correct += 1
        elif s == 'WA' and problems[p] != -1:
            problems[p] += 1
            
print(correct,penalty)

Measured memory_bytes: 19388
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int sx = Integer.parseInt(sc.next());
    int sy = Integer.parseInt(sc.next());
    int tx = Integer.parseInt(sc.next());
    int ty = Integer.parseInt(sc.next());
    int dx = tx - sx;
    int dy = ty - sy;
    for (int i = 0; i < dy; i++) {
      System.out.print("U");
    }
    for (int i = 0; i < dx; i++) {
      System.out.print("R");
    }
    for (int i = 0; i < dy; i++) {
      System.out.print("D");
    }
    for (int i = 0; i < dx; i++) {
      System.out.print("L");
    }
    System.out.print("L");
    for (int i = 0; i < dy + 1; i++) {
      System.out.print("U");
    }
    for (int i = 0; i < dx + 1; i++) {
      System.out.print("R");
    }
    System.out.print("DR");
    for (int i = 0; i < dy + 1; i++) {
      System.out.print("D");
    }
    for (int i = 0; i < dx + 1; i++) {
      System.out.print("L");
    }
    System.out.println("U");
  }
}

Measured memory_bytes: 23492
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;

//----------------------------------------------------------------
signed main(){

	int n;
	cin >> n;
	int ans = INF;

	for(int i = 1;i*i <=n;i++){
		if(n%i == 0)ans = min(i + n/i,ans);
	}
	cout << ans -2 << endl;
	

	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc144.contest.atcoder.jp/tasks/abc144_b

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
}

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

    cout << "Yes" << endl;
}

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

int main(void){
  char s[27];
  int t[27]={0};
  int n, i=0;

  scanf("%s", s);
  n=strlen(s);

  while(s[i]!='\0'){
    t[s[i]-'a']++;
    i++;
  }

  for(i=0;i<n;i++){
    if(t[i]>=2){
    puts("no");
    break;
  }
    if(i==n-1)
    puts("yes");
  }
    return 0;
  }


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
from collections import defaultdict

"""
(駅、会社)を頂点にグラフを持つ。頂点数O(M)。
そのまま辺を貼ると辺が多くなりすぎる。
(駅、会社) -> (駅、無属性) -> (駅、会社)
"""

L = 32
mask = (1 << L) - 1
N,M = map(int,input().split())
graph = defaultdict(list)
for _ in range(M):
    p,q,c = map(int,input().split())
    p <<= L
    q <<= L
    graph[p].append(p+c)
    graph[p+c].append(p)
    graph[q].append(q+c)
    graph[q+c].append(q)
    graph[p+c].append(q+c)
    graph[q+c].append(p+c)

INF = 10 ** 9
dist = defaultdict(lambda: INF)

start = 1 << L
goal = N << L

q = [start] # 0 が会社に属していない状態
dist[start] = 0
d = 0
q0 = []
q1 = []
while q:
    for x in q:
        if x & mask == 0:
            for y in graph[x]:
                if dist[y] <= d + 1:
                    continue
                dist[y] = d + 1
                q1.append(y)
        else:
            for y in graph[x]:
                if dist[y] <= d:
                    continue
                dist[y] = d
                q0.append(y)
    if q0:
        q = q0
        q0 = []
        continue
    q = q1
    q1 = []
    d += 1

answer = dist[goal]
if answer == INF:
    answer = -1
print(answer)

Measured memory_bytes: 196696
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

long long dp[100][100000];
long long solve( vector<int> &w,vector<int> &p,int i,int j)
{
    
   if(i==w.size())
   return 0;
   if(dp[i][j]!=-1)
   return dp[i][j];
   
   
   if(j-w[i]>=0)
   dp[i][j]= max(solve(w,p,i+1,j),p[i]+solve(w,p,i+1,j-w[i]));
   else
   dp[i][j]=solve(w,p,i+1,j);
   return dp[i][j];
}

int main()
{
  int n,t;
  cin>>n>>t;
  memset(dp,-1,sizeof(dp));
  vector<int> w(n),p(n);
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>p[i];
  }
  
  cout<<solve(w,p,0,t);
  
  return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll max(ll a, ll b) { return (a > b)? a : b; }
ll knapSack(ll W, ll wt[], ll val[], ll n)
{
   ll i, w;
   ll K[n+1][W+1];
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

   return K[n][W];
}
int main()
{
    ll n,W;
    cin>>n>>W;
    ll a,b;
    ll wt[n],val[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a>>b;
        wt[i]=a;
        val[i]=b;
    }
    cout<<knapSack(W, wt, val, n);
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll A,B;
int main() {
    cin >> A >> B;
    if (A*500 >= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl; 
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
using namespace std;
vector<int> v;
int isp[1000006];
int bm1[1000005];
int bm2[1000005];
void ola(int n)
{
    for(int i=2;i<=n;i++)
    {
        if(isp[i]==0) v.push_back(i);
        for(int j=0;v[j]<n/i;j++)
        {
            isp[v[j]*i]=1;
            if(i%v[j]==0) break;
        }
    }
}
int main()
{
    ola(1000000);
    ll a,b;
    cin>>a>>b;
    for(int i=0;i<v.size();i++)
    {
        while(a%v[i]==0)
        {
            a/=v[i];
            bm1[v[i]]=1;
        }
    }
    for(int i=0;i<v.size();i++)
    {
        while(b%v[i]==0)
        {
            b/=v[i];
            bm2[v[i]]=1;
        }
    }
    int ans=0;
    for(int i=0;i<=1000001;i++)
    {
        if(bm1[i]==1&&bm1[i]==bm2[i])
            ans++;
    }
    if(a==b&&a!=1) ans++;
    cout<<ans+1<<endl;
    return 0;
}


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

li = []
li2 = []

for i in range(n):
    if a[i] > b[i]:
        li.append(a[i] - b[i])
    elif a[i] < b[i]:
        li2.append(b[i] - a[i])

li.sort(reverse = True)
sum1 = sum(li2)

tmp = 0
count = 0

while tmp < sum1:
    if count < len(li):
        tmp += li[count]
        count += 1
    else:
        print(-1)
        exit()

print(count + len(li2))


Measured memory_bytes: 18356
/*
w2sc
2019/12/19
19:43:48
*/
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const double EPS=1e-10;
int q;
struct Point{
    double x,y;
    Point(){}
    Point(double xx,double yy){x=xx,y=yy;}
    Point operator +(Point A){return Point(x+A.x,y+A.y);}
    Point operator -(Point A){return Point(x-A.x,y-A.y);}
    double operator *(Point A){return x*A.x+y*A.y;}
    double operator ^(Point A){return x*A.y-y*A.x;}
};
typedef Point Vec;
int main()
{
    cin>>q;
    while(q--)
    {
        Point A,B;
        Vec a,b;
        scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);
        a=A-B;
        scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);
        b=A-B;
        if(fabs(a*b)<EPS) puts("1");
        else if(fabs(a^b)<EPS) puts("2");
        else puts("0");
    }
    return 0;
}



Measured memory_bytes: 3244
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]

A_sorted = sorted(A)
B_sorted = sorted(B)
C_sorted = sorted(C)

ans = 0
for b in B_sorted:
    #Aのうちbより小さいの数
    left = -1
    right = N 
    while right - left > 1:
        mid = left + (right - left) // 2
        if A_sorted[mid] < b:
            left = mid
        else:
            right = mid
    a_count = right
    #Cのうちbより大きいの数
    left = -1
    right = N 
    while right - left > 1:
        mid = left + (right - left) // 2
        if C_sorted[mid] > b:
            right = mid
        else:
            left = mid
    c_count = N - right
    
    ans += a_count * c_count

print(ans)

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxm = 15;
const int maxn = 2e5 + 5;
const int INF = 998244353;

int n, m;
int l[maxm], r[maxm];
int f[maxn], g[maxn];

int main(){
	scanf("%d%d", &n, &m);
	FOR(i, 0, m)
		scanf("%d%d", l + i, r + i);
	
	f[1] = g[1] = 1;
	REP(i, 2, n){
		FOR(j, 0, m)
			(f[i] += (g[max(0, i - l[j])] - g[max(0, i - r[j] - 1)] + INF) % INF) %= INF;
		g[i] = (g[i - 1] + f[i]) % INF;
	}
	
	printf("%d\n", f[n]);
	return 0;
}


Measured memory_bytes: 5368
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <vector>
#include <cstdio>
using namespace std;
int main() {
    string str;
    while (getline(cin, str)) {
        vector<string> vec;
        stack<double> stc;
        string temp="";
        for (int i=0; i<str.length(); i++) {
            if (str[i]==' ') {
                vec.push_back(temp);
                temp="";
            } else {
                temp+=str[i];
            }
        }
        if (temp.length()!=0) vec.push_back(temp);
        for (int i=0; i<vec.size(); i++) {
            if (vec[i]!="+"&&vec[i]!="-"&&vec[i]!="*"&&vec[i]!="/") {
                stringstream ss;
                ss<<vec[i];
                int n; ss>>n;
                stc.push((double)n);
            } else if (stc.size()>1) {
                double top=stc.top(); stc.pop();
                double top2=stc.top(); stc.pop();
                if (vec[i]=="+") stc.push(top+top2);
                else if (vec[i]=="-") stc.push(top2-top);
                else if (vec[i]=="*") stc.push(top*top2);
                else if (vec[i]=="/") stc.push(top2/top);
            }
        }
        printf("%.6f\n",stc.top());
    }
}

Measured memory_bytes: 0