akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

double dp[3000][3000];
signed main(void) {
    int n;
    cin >> n;
    dp[0][0] = 1;
    rep(i,n){
        double p;
        cin >> p;
        rep(j,i+1){
            dp[i+1][j+1] += dp[i][j] * p;
            dp[i+1][j] += dp[i][j] * (1-p);
        }
    }
    double ans = 0;
    loop(i,n/2+1,n+1)ans += dp[n][i];
    cout << shosu(10) << ans << endl;
}


Measured memory_bytes: 68864
a=input().split()
d,e={},{}
for w in a:d.setdefault(w,0);d[w]+=1
for w in d:
 if d[w]==max(d.values()):print(w,end='')
 e.setdefault(len(w),[]).append(w)
print('',*e[max(e)])


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

int main() {

long long t = 1;
//cin >> t;
while(t--){
	int a,b,cc;
	cin >> a >> b >> cc;
	if(a+b+cc >=22) cout <<"bust";
	else cout <<"win";
}
return 0;
}

Measured memory_bytes: 256
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

/*
半分全列挙です。
前半と後半で、あり得る組み合わせをそれぞれ vector で列挙し、ソートです。
前半を全探索します。前半が x なら 後半hは [L-x,R-x] なので、二分探索で数えます。
*/

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, k; std::cin >> n >> k;
  lint L, R; std::cin >> L >> R;
  std::vector<lint> a(n); std::cin>>a;
  debug(k,L,R,a);

  auto make = [&] (auto&& a) {
    int n = a.size();
    int N = 1<<n;
    lint sum = 0;
    int count = 0;
    std::vector<int> now(n,0);
    std::vector<std::vector<lint>> ans(n+1);
    ans.at(0) = {0};
    rep(bs,1,N) {
      int i = __builtin_ctz(bs);
      int & b = now.at(i);
      b ^= 1;
      sum += (b ? +1 : -1) * a.at(i);
      count += b ? +1 : -1;
      ans.at(count).push_back(sum);
    }
    for (auto& v : ans) {
      std::sort(all(v));
    }
    return ans;
  };
  int l = n / 2;
  auto former = make(std::vector<lint>(a.begin(),a.begin()+l));
  auto latter = make(std::vector<lint>(a.begin()+l,a.end()));
  for (auto& v : former) {
    std::reverse(all(v));
  }
  debug(former,latter);

  lint ans = 0;
  rep(k0,0,k+1) {
    int k1 = k - k0;
    if (l < k0 || n-l < k1) continue;
    auto& v0 = former.at(k0);
    auto& v1 = latter.at(k1);
    for (lint x0 : v0) {
      lint l = L - x0;
      lint r = R - x0;
      auto lb = std::lower_bound(all(v1),l);
      auto ub = std::upper_bound(all(v1),r);
      lint now = ub - lb;
      debug(now);
      ans += now;
    }
    debug(v0,v1);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 23732
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    n = int(input())
    s = 0
    for v in range(n + 1):
        if v % 3 == 0 or v % 5 == 0:
            continue
        s += v
    #print('s') # debug
    print(s)

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 68844
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c, i, ans;
    cin >> a >> b >> c;
    ans = 0;
    for(i=a; i<=b; i++)
    {
        if(c % i == 0)
          ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,n,x,y,z,i=0,ans=0,c=0,r;
    string s;
    cin >> a >> b >> c;
    if((a==b && b==c) || (a!=c && c!=b && b!=a) )
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }    
        
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MMS(x, y) memset((x), (y), sizeof(x))
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define EPS 1e-9
#define EPSS 1e-10

#define MAXN 40010
#define SEGN 300030
using namespace std;
struct line {
    double a, b, c;
    double slope() {
        return -(a / b);
    }
    double gety(double x) {
        return (-c / b) - (a * x / b);
    }
    double getx(double y) {
        return (-c / a) - (b * y / a);
    }
};
inline bool cmp1 (line &n1, line &n2) {
    return n1.slope() > n2.slope();
}
inline bool cmp2 (line &n1, line &n2) {
    return n1.slope() < n2.slope();
}
vector <line> AL;
int N;
double K;
int bit[MAXN];
void update(int x, int v) {
    for (int a = x; a <= N; a += (a & -a))
        bit[a] += v;
}
int query(int x) {
    int sum = 0;
    for (int a = x; a > 0; a -= (a & -a))
        sum += bit[a];
    return sum;
}
double seq[MAXN];
int cnt;
double findans(int mode) {
    double left = -INF, rght = INF;
    if (!mode) {
        sort(AL.begin(), AL.end(), cmp2);
    } else {
        for (auto &i : AL) {
            swap(i.a, i.b);
        }
        sort(AL.begin(), AL.end(), cmp2);
    }
    int steps = 0;
    while (steps < 100) {
        steps++;
        unordered_map <double, int> MP;
        set <double> inter;
        cnt = 1;
//        memset(bit, 0, sizeof bit);
        for (int i = 0; i <= N; i++)
            bit[i] = 0;
        double mid = (rght + left) / 2;
        for (line i : AL) {
            double a = i.gety(mid);
            inter.insert(a);
            seq[cnt++] = a;
        }
        cnt = 1;
        for (auto i : inter) {
            MP[i] = cnt++;
        }
        cnt = 0;
        for (int i = 1, c; i <= N; i++) {
            c = MP[seq[i]];
            cnt += query(c);
            update(c, 1);
        }
        if (cnt < K / 2.0) {
            left = mid + EPSS;
        } else {
            rght = mid - EPSS;
        }
    }
    return 0.5 * (left + rght);
}
int main() {
    scanf("%d", &N);
    K = (N * (N - 1)) / 2;
    for (int i = 1; i <= N; i++) {
        double a, b, c;
        scanf("%lf %lf %lf", &a, &b, &c);
        c = -c;
        AL.push_back((line){a, b, c});
    }
    cout << fixed << setprecision(12) << findans(0) << " ";
    cout << findans(1) << "\n";
}


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

using namespace std;
int n,k,i,j;
int a[105];
int dp[100005];
int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>a[i];

    for(i=0;i<=k;i++)
    {
        if(!dp[i])
        {
            for(j=1;j<=n;j++)
            {
                if(i+a[j]>k)
                    break;
                dp[i+a[j]]=1;
            }

        }
    }

    if(dp[k])
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}


Measured memory_bytes: 4032
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

	Int ans;
	if (A1*T1+A2*T2== B1 * T1 + B2 * T2) {
		cout << "infinity" << "\n";
	}
	else if (A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2) {
		if (B1 * T1 <= A1 * T1) {
			ans = (A1 * T1 - B1 * T1) / (B1 * T1 + B2 * T2 - (A1 * T1 + A2 * T2));
			ans += 1;
			ans *= 2;
			ans--;
			if ((A1 * T1 - B1 * T1) % (B1 * T1 + B2 * T2 - (A1 * T1 + A2 * T2))==0) {
				ans--;
			}
			cout << ans << "\n";
		}
		else {
			cout << 0 << "\n";
		}
	}
	else {
		if (A1 * T1 <= B1 * T1) {
			ans = (B1 * T1 - A1 * T1) / (A1 * T1 + A2 * T2 - (B1 * T1 + B2 * T2));
			ans += 1;
			ans *= 2;
			ans--;
			if ((B1 * T1 - A1 * T1) % (A1 * T1 + A2 * T2 - (B1 * T1 + B2 * T2)) == 0) {
				ans--;
			}
			cout << ans << "\n";
		}
		else {
			cout << 0 << "\n";
		}
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = min(a, c);
    c -= a;
    if (c < 0) {
        cout << ans + b << endl;
    } else {
        cout << ans + b + min(b + 1, c) << endl;
    }
}


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

int main() {
    string S;
    cin >> S;
    int n = S.size();
    int ans = 0;
    for (int i = 0; i < n/2; ++i) {
        if(S[i] != S[n-1-i]) ans++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, w; cin >> n >> w;
	vi dp(100001, inf + 1);
	dp[0] = 0;
	rep(i, n){
		int a, b; cin >> a >> b;
		for(int i = 100000 - b; i >= 0; i--) if(dp[i] <= inf)
		dp[i + b] = min(dp[i + b], dp[i] + a);
	}
	for(int i = 100000; i >= 0; i--) if(dp[i] <= w){
		cout << i << endl;
		break;
	}
	
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
static const int mod = 1e9+7;
const Int Inf = 1e17;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  cin>>n>>q; Int a[n]; rep(i,n)cin>>a[i];
  Int ans=0;
  rep(l,q+1)for(int r=0; min(l,n)+r<=q; r++){
    gPr(Int)p;
    rep(i,min(l,n))p.push(a[i]);
    for(int i=0; i<r&&min(l,n)+i<n; i++)p.push(a[n-1-i]);
    Int c=0; int t=q-l-r;
    while(!p.empty()&&t){
      Int x=p.top();
      if(x<0){p.pop(); t--;}
      else break;
    }
    while(!p.empty()){
      Int x=p.top(); p.pop(); c+=x;
    }
    cmax(ans,c);
  }
  END
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))

distance = []

for i in range(N-1):
    dis = A[i + 1] - A[i]
    distance.append(dis)

dis = K - A[N - 1] + A[0]
distance.append(dis)

index = distance.index(max(distance))

print(K - distance[index])


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

int main()
{
	int a,b,c;
	int k;
	cin>>a>>b>>c>>k;
	while(k--){
		if(a>b){
			int t=a;a=b;b=t;
		}	
		if(b>c){
			int t=b;b=c;c=t;
		}
		if(a>c){
			int t=a;a=c;c=t;
		}
		c*=2;
	}
	cout<<a+b+c<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size();
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(k);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = (1e9)+10;
long double INFD = 100100100;

//_____________________________________Templates_________________________________________//

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

//_____________________array calc____________________________________//
/*
vvi mul(vvi &A, vvi &B){
  vvi C(A.size(), vi(B.size()))
  rep(i,A.size()){
    rep(j,B.size()){
      rep(k,B[0].size()){
        C[i][j] = (C[i][j] A[i][k] + B[k][j]) % Mod;
      }
    }
  }

  return C;
}

vvi pow(vvi A, ll n){
  vvi B(A.size(), vi(A.size()));
  rep(i=0;i<A.size();i++){
    B[i][i] = 1;
  }

  while (n >0){
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n = n >> 1;
  }
  return B;
}
*/
//_____________________Bynary Indexed Tree __________________________//
/*
const max_st = (1 << 15) - 1;
int bit[max_st];
int sum (int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}
*/
//_____________________　following sorce code_________________________//
int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,k;cin >> n >> k;
  vi v(n);
  rep(i,0,n-1)IN(v[i]);
  vi dp(n+5,INF);
  dp[0] = 0;
  rep(i,0,n-1){
      rep(j,1,k){
          if(i+j<n)chmin(dp[i+j], dp[i]+abs(v[i]-v[i+j]));
      }
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = input()
l = [0]*n
c = 0
d = 0
for i in range(n-1):
  if s[i+1] == "E":
    c += 1
    if s[i] == "E":
      l[i+1] = l[i] - 1
      d = min(d, l[i+1])
    else:
      l[i+1] = l[i]
  else:
    if s[i] == "W":
      l[i+1] = l[i] + 1
    else:
      l[i+1] = l[i]
ans = d + c
print(ans)


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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;

const int MAXN = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

ll dp[MAXN];
ll group_value[MAXN];
ll M[20][20];

void init_groups(int N) {
    for(int mask = 0; mask < (1 << N); mask++) {
        for(int i = 0; i < N; i++) {
            if((mask >> i) & 1) {
                for(int j = i + 1; j < N; j++)
                    if((mask >> j) & 1)
                        group_value[mask] += M[i][j];
            }
        }
    }
}

void rec(int i, const vector <int>& not_used, ll score, int mask, int group_mask) {
    if(i == not_used.size()) {
        dp[mask] = max(dp[mask], score + group_value[group_mask]);
        return;
    }

    rec(i + 1, not_used, score, mask, group_mask);          // nisi iskoristija trenutni element
    rec(i + 1, not_used, score, mask + (1 << not_used[i]), group_mask + (1 << not_used[i]));     // iskoristija si trenutni element
}

int main() {
    int N, last;

    scanf("%d", &N);
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            scanf("%lld", &M[i][j]);

    init_groups(N);
    for(int mask = 0; mask < (1 << N); mask++) {
        vector <int> not_used;
        for(int i = 0; i < N; i++)
            if(!((mask >> i) & 1))
                not_used.push_back(i);

        rec(0, not_used, dp[mask], mask, 0);
    }

    cout << dp[(1 << N) - 1] << endl;

    return 0;
}



Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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; }

int main() {
    string s;
    cin >> s;
    int ans = 0;
    FOR(i, s.length()) {
        if (!(i % 2) && s[i] == 'p')ans--;
        else if(i % 2 && s[i] == 'g')ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


const int MAX_N=200010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=0;
    return n;
}
int Seg_calc(int a,int b){
    return (a+b)%3;
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
/*
int Seg_query(int a,int b,int k,int l,int r){
    cout << a MM b MM k MM l MM r << endl;
    //外からはSeg_query(a,b,0,0,n)で呼ぶ
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}*/
/*
int Seg_query(int a,int b){
    vector<pair<pair<int,int>,int>> G;
    G.push_back({{0,n},0});
    int R=0;
    
    while(!G.empty()){
        int l=G.back().first.first;
        int r=G.back().first.second;
        int k=G.back().second;
        //cout << l MM r MM k;
        G.pop_back();
        if(r<=a||b<=l)continue;
        if(a<=l&&r<=b){R=Seg_calc(R,dat[k]);continue;}
        G.push_back({{l,(l+r)/2},2*k+1});
        G.push_back({{(l+r)/2,r},2*k+2});
    }
    
    return R;
}*/

int Seg_query(int a,int b){
    a += n;
    b += n;
    int R = 0;
    while(a < b){
        if(a % 2 == 1){
            R = Seg_calc(R, dat[a - 1]);
            a += 1;
        }
        a /= 2;
        if(b % 2 == 1){
            b -= 1;
            R = Seg_calc(R, dat[b - 1]);
        }
        b /= 2;
    }
    return R;
}

signed main(void){
    string S,T;
    int Q;
    int A[114514],B[114514],C[114514],D[114514];
    int G[114514],H[114514];
    
    cin >> S >> T;
    cin >> Q;
    REP(i,Q){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;B[i]--;C[i]--;D[i]--;
    }
    
    //Aを1、Bを2、O(=AB)を0と扱う
    
    //Sをセグる
    Seg_init(S.size());
    REP(i,S.size()){
        Seg_update(i,(S[i]=='A'?1:2));
    }
    REP(i,Q){
        G[i]=Seg_query(A[i],B[i]+1);
    }
    //Tをセグる
    Seg_init(T.size());
    REP(i,T.size()){
        Seg_update(i,(T[i]=='A'?1:2));
    }
    REP(i,Q){
        H[i]=Seg_query(C[i],D[i]+1);
    }
    
    //REP(i,Q){cout << G[i] MM H[i] << endl;}
    
    REP(i,Q){
        if(G[i]==H[i]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}



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

using namespace std;

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

  int N; cin>>N;
  class Data {
   public:
    int l, r;
	int range() const {return max(0, r-l+1);}
	Data() = default;
	Data(int il, int ir) : l(il), r(ir) {}
	Data unite(const Data& x) {
	  return {max(l, x.l), min(r, x.r)};
	}
  };
  vector<Data> LR(N);

  int maxl = 0, minr = 1e9;
  int maxr = 0;
  for (auto& lr : LR) {
    cin>>lr.l>>lr.r;
    maxl = max(maxl, lr.l);
    minr = min(minr, lr.r);
    maxr = max(maxr, lr.range());
  }

  auto ans1 = maxr + Data(maxl, minr).range();

  sort(LR.begin(), LR.end(), [&](auto l, auto r) {
    auto lv = max(0, l.r - maxl+1);
    auto rv = max(0, r.r - maxl+1);
    return lv < rv;
  });

  vector<int> sums(N);
  Data dtmp = {1, (int)1e9};
  for (int i = 0; i < N; i++) {
    dtmp = dtmp.unite(LR[i]);
	sums[i] = dtmp.range();
  }
  dtmp = {1, (int)1e9};
  int ans2 = 0;
  for (int i = N-1; i > 0; i--) {
    dtmp = dtmp.unite(LR[i]);
    ans2 = max(ans2, sums[i-1] + dtmp.range());
  }


  sort(LR.begin(), LR.end(), [&](auto l, auto r) {
	auto lv = max(0, minr - l.l+1);
	auto rv = max(0, minr - r.l+1);
	return lv > rv;
  });

  dtmp = {1, (int)1e9};
  for (int i = 0; i < N; i++) {
	dtmp = dtmp.unite(LR[i]);
	sums[i] = dtmp.range();
  }
  dtmp = {1, (int)1e9};
  int ans3 = 0;
  for (int i = N-1; i > 0; i--) {
	dtmp = dtmp.unite(LR[i]);
	ans3 = max(ans3, sums[i-1] + dtmp.range());
  }

  cout << max(max(ans1, ans2), ans3) << endl;

  return 0;
}


Measured memory_bytes: 1408
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = [deque for _ in range(N)]
    for i in range(N):
        A[i] = deque(list(map(lambda x: int(x) - 1, input().split())))

    days = 0
    ta = [i for i in range(N)]
    while True:
        ta2 = []
        aset = set()
        for i in ta:
            if len(A[i]) == 0 or i in aset:
                continue
            if i == A[A[i][0]][0]:
                ta2.append(i)
                ta2.append(A[i][0])
                aset |= set([i])
                aset |= set([A[i][0]])
        if len(ta2) > 0:
            for t in ta2:
                A[t].popleft()
            days += 1
            ta = ta2
        else:
            break

    empty = True
    for i in range(N):
        if len(A[i]) != 0:
            empty = False
            break

    if empty:
        print(days)
    else:
        print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 72540
#include <iostream>
#include <cstdio>
#include <array>

using namespace std;

int main(){
  int N;
  int w_num = 0, e_num = 0, min, tmp;
  char leadr = '\0';

  scanf("%d", &N);

  char arr[N];
  scanf("%s", arr);

  for(int i=1; i<N; i++){
    if(arr[i] == 'E'){ e_num++; }
  }
  min = e_num;

  for(int i=1; i<N; i++){
    if(arr[i-1] == 'W'){ w_num++; }
    if(arr[i] == 'E'){ e_num--; }
    tmp = w_num + e_num;
    if(tmp < min){ min = tmp; }
  }

 cout << min << endl;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		long c = fs.nextLong();
		long k = fs.nextLong();
		
		long[] arrivalTimeArr = fs.nextLongArr(n);
		Arrays.sort(arrivalTimeArr);
		
		int ans = 0;
		ArrayDeque<Long> passengerQue = new ArrayDeque<>();
		for(int i = 0; i < n; i++) {
			long arrivalTime = arrivalTimeArr[i];
			if(!passengerQue.isEmpty()) {
				long nextAngerTime = passengerQue.peek();
				while(nextAngerTime < arrivalTime) {
					ans++;
					busArrive(passengerQue, c);
					if(passengerQue.isEmpty()) {
						nextAngerTime = Long.MAX_VALUE;
					}else {
						nextAngerTime = passengerQue.peek();
					}
				}
			}
			passengerQue.add(new Long(arrivalTime + k));
		}
		
		while(!passengerQue.isEmpty()) {
			ans++;
			busArrive(passengerQue, c);
		}
		
		System.out.println(ans);
	}
	
	public void busArrive(ArrayDeque<Long> passengerQue, long c) {
		for(long i = 0; i < c; i++) {
			if(passengerQue.isEmpty()) {
				break;
			}
			passengerQue.poll();
//			System.out.print(passengerQue.poll()+",");
		}
//		System.out.print("\n");
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 38852
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
using namespace std;
int n, m;
string fl[1001];
string tmp[2];
string JOI = "JOI";

bool hani(int i, int j) {
	if (i < n && i >= 0 && j < m && j >= 0) return true;
	return false;
}

bool check(int i,int j) {
	
	if (hani(i, j))
		if (fl[i][j] == tmp[0][0])
			if (hani(i + 1, j))
				if (fl[i + 1][j] == tmp[1][0])
					if (hani(i, j + 1))
						if (fl[i][j + 1] == tmp[0][1])
							if (hani(i + 1, j + 1))
								if (fl[i + 1][j + 1] == tmp[1][1]) return true;
	return false;
}

int mxy(int i, int j) {
	int cnt = 0;
	if (check(i - 1, j - 1)) cnt++;
	if (check(i - 1, j)) cnt++;
	if (check(i, j - 1)) cnt++;
	if (check(i, j)) cnt++;
	return cnt;
}


int main() {

	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> fl[i];
	}
	for (int i = 0; i < 2; i++) {
		cin >> tmp[i];
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (check(i, j)) cnt++;
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char now = fl[i][j];
			int ncnt = mxy(i, j);
			int MAX = 0;
			for (int s = 0; s < 3; s++) {
				if (now == JOI[s]) continue;
				fl[i][j] = JOI[s];
				MAX = max(MAX, mxy(i, j));
			}
			fl[i][j] = now;
			if (ncnt < MAX) {
				ans = max(ans, MAX - ncnt);
			}
		}
	}
	printf("%d\n", cnt + ans);
}


Measured memory_bytes: 4200
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
#define Next(a,i) ((i)+1)%(a).size()
#define Curr(a,i) (i)%(a).size()
#define Prev(a, i) (i+a.size()-1) % a.size()

using namespace std;

int main(void){

  int n,m,x,dp[101][101];
  vector<int>a;

  cin >> n;

  while(n--){
    a.clear();

    for(int i=0;i<101;i++)
      for(int j=0;j<101;j++)dp[i][j]=0;

    cin >> m;
    for(int i=0;i<m;i++){
      cin >> x;
      a.push_back(x);
    }

    //for(int i=0;i<m;i++)dp[i][Next(a,i)]=abs(curr(a,i)-next(a,i));
    
    for(int k=1;k<m;k++){
      for(int i=0;i<m;i++){
	for(int j=0;j<k;j++){
	  dp[Curr(a,i)][Curr(a,k)]=max(dp[i][k],dp[Curr(a,i)][Curr(a,j)]+dp[Next(a,i+j)][Prev(a,k-j)]+abs(curr(a,i)-next(a,i+j)));
						  
	}
	
      }
    }
    int ans=0;
    for(int i=0;i<m;i++)
      for(int j=0;j<m;j++)
      ans=max(ans,dp[i][j]);
    
    cout << ans << endl;
    
  }

  return 0;
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  auto speak = [&](int x, int y){return abs(y - x) <= d;};
  cout << (speak(a, c) || (speak(a, b) && speak(b, c)) ? "Yes" : "No") << endl;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int mn = mod;
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    sort(A, A+N);
    int sum = 0;
    rep(i, N){
        if(A[i]%10 > 0) mn = min(mn, A[i]);
        sum += A[i];
    }
    if(mn == mod) cout << 0 << endl;
    else if(sum % 10 == 0) cout << sum-mn << endl;
    else cout << sum << endl;
    return 0;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(all(b),greater<ll>());
    rep(i,n){
        if(a[i]!=b[0]) cout << b[0] << endl;
        else cout << b[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 6432
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


x = ini()


def solve():
    return x >= 30


print("Yes" if solve() else "No")


Measured memory_bytes: 9172
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

def main():
    N, M, Q = map(int, input().split())
    ans = [[0]*N for _ in range(N)]
    for i in range(M):
        L, R = map(lambda x: int(x)-1, input().split())
        ans[L][R] += 1
    
    # print(ans)

    # ansの2次元累積和
    # s = [[0]*(N+1) for _ in range(N+1)]
    # s[N-1][0] = ans[N-1][0]
    for i in range(N):
        if i != N-1:
            for j in range(N):
                ans[N-2-i][j] += ans[N-1-i][j]
        for j in range(N-1):
            ans[N-1-i][j+1] += ans[N-1-i][j]
    # print(ans) 
    for i in range(Q):
        p, q = map(int, input().split())
        print(ans[p-1][q-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 9768
# coding: utf-8
# Your code here!
import sys

def sum_digits(n,m):
   r = 0
   while n:
       r, n = r + n % m, n // m
   return r


n,a,b = [int(i) for i in input().split()]

c=a^b
if sum_digits(c,2)%2 == 0:
   print('NO') 
   sys.exit()

def grey(n):
    if n == 1: return [0,1]
    a0 = grey(n-1)
    a2= [(2**(n-2))^i^(2**(n-1)) for i in grey(n-1)] 
    return a0 + a2
    #print(grey(4))

def newgrey(a,b,move):
    if len(move) == 1:
        return [a,b]
    diff = 0
    for j in move:
        if a&(2**j) != b&(2**j):
            diff=j
            break
    ac = a
    bc = b
    for j in move:
        if j == diff: continue
        ac = a^(2**j)
        bc = ac ^ (2**diff)
        if bc != b: break
    return newgrey(a,ac, move-set({diff})) + newgrey(bc,b, move-set({diff}))
    
print('YES')
ans =newgrey(a,b,set(range(n)))
print(*ans)
    
    







Measured memory_bytes: 11500
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

def pne(n):
    print(n,end='')

rem = pow(10,9)+7

#n = ip()                                     #入力整数1つ
n,q= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
gatacca = ["A","C","T","G"]
pa = [0]
pc = []
s = 0
for i in range(n-1):
    if a[i] == "A" and a[i+1] == "C":
        s+=1
    pa.append(s)
for i in range(q):
    left,right =  (int(i) for i in input().split())
    right-=1
    left-=1
    print(pa[right]-pa[left])

Measured memory_bytes: 16940
let () =
    let mul_inv a = function
        | 1 -> 1
        | b ->
            let rec aux a b x0 x1 =
                if a <= 1 then x1 else
                if b = 0 then failwith "mul_inv" else
                    aux b (a mod b) (x1 - (a / b) * x0) x0
            in
            let x = aux a b 0 1 in
            if x < 0 then x + b else x
    in
    let m = 1_000_000_000 + 7 in
    let ( +@ ) a b = (a + b) mod m in
    let ( -@ ) a b = (a - b + m) mod m in
    let ( *@ ) a b = ((a mod m) * (b mod m)) mod m in
    let ( /@) a b = a *@ mul_inv b m in
    let main () =
        let n, k = Scanf.scanf "%d %d" (fun n k -> n, k) in
        let arr = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
        Array.sort compare arr;
        let rec loop fact a b i acc =
            if i = n then acc else
                let acc = acc +@ fact *@ (arr.(i) -@ arr.(n - 1 - i)) in
                loop (fact *@ a /@ b) (a + 1) (b + 1) (i + 1) acc
        in
        loop 1 k 1 (k - 1) 0 |> Printf.printf "%d\n"
    in
    main ()

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#define NMAX 100000
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n";
#define scan(arg) cin>>arg;
using namespace std;
typedef long long ll;
int n,m;
int a[10];
int b[10];
int dp[10][10010];
int main(){
	scan(n);scan(m);
	rep1(i,m) scan(a[i]);
	sort(a+1,a+m+1);
	rep1(i,m){
		if(a[i]==1)b[i]=2;
		if(a[i]==2)b[i]=5;
		if(a[i]==3)b[i]=5;
		if(a[i]==4)b[i]=4;
		if(a[i]==5)b[i]=5;
		if(a[i]==6)b[i]=6;
		if(a[i]==7)b[i]=3;
		if(a[i]==8)b[i]=7;
		if(a[i]==9)b[i]=6;
	}
	rep(i,m+1){
		rep1(j,n){
			dp[i][j]=-100000;
		}
	}
	rep(i,m+1) dp[i][0]=0;
	rep1(i,m){
		rep1(j,n){
			if(b[i]>j){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-b[i]]+1);
			}
		}
	}
	string res="";
	while(m>0||n>0){
		if(n>=b[m]){
			if(dp[m][n]-1==dp[m][n-b[m]]){
				res+=to_string(a[m]);
				n-=b[m];
			}
			else m--;
		}
		else m--;
	}
	prin(res);
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#define BLANK 0
#define QUEEN 1

/* Global Variables */
int row[8], column[8], lobl[2 * 8 - 1], robl[2 * 8 - 1];
int board_state[8][8];

void printbState() {
  int i, j;
  //Output
  for ( i = 0; i < 8; i++)
    for ( j = 0; j < 8; j++ )
      if ( board_state[i][j] == QUEEN && row[i] != j )
	return;
    
  for ( i = 0; i < 8; i++ ) {
    for ( j = 0; j < 8; j++ ) {
      if ( row[i] == j )
        printf("Q");
      else
        printf(".");
    }
    printf("\n");
  }

}

/* Solve the 8 Queens Problem */
void putQueen(int i) {
  int j;

  if ( i == 8 ) {
    printbState();
    return;
  }

  for ( j = 0; j < 8; j++ ) {
    if (  column[j] == QUEEN ||
          lobl[i + j] == QUEEN ||
          robl[i - j + 8 - 1] == QUEEN )
            continue;
    
    //Put a Queen
    row[i] = j;
    column[j] = QUEEN;
    lobl[i + j] = QUEEN;
    robl[i - j + 8 - 1] = QUEEN;
    
    //Next Row
    putQueen(i + 1);
    
    //Remove a Queen
    row[i] = BLANK;
    column[j] = BLANK;
    lobl[i + j] = BLANK;
    robl[i - j + 8 - 1] = BLANK;
  }

}

int main() {
  int i, j, k;
  int r, c;

  scanf("%d", &k);

  //Initialize
  for ( i = 0; i < 8; i++ ) {
    row[i] = BLANK;
    column[i] = BLANK;
  }
  for ( i = 0; i < 8; i++ )
    for ( j = 0; j < 8; j++ )
      board_state[i][j] = BLANK;

  for ( i = 0; i < 2 * 8 - 1; i++ ) {
    lobl[i] = BLANK;
    robl[i] = BLANK;
  }

  //Put a Initial Queen
  for ( i = 0; i < k; i++ ) {
    scanf("%d%d", &r, &c);
    board_state[r][c] = QUEEN;
  }

  putQueen(0);

  return 0;
}

Measured memory_bytes: 572
from fractions import gcd
from math import sqrt,asin,degrees
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from itertools import accumulate,permutations
from bisect import bisect_left,bisect_right

a,b,x = map(int,input().split())
 
m = 2*x/a**2 - b
if m >= 0:
    sin = (b-m)/sqrt((b-m)**2+a**2)
    print("{:.7f}".format(degrees(asin(sin))))
else:
    sin = b/sqrt((b**2)+((2*x)/(a*b))**2)
    print("{:.7f}".format(degrees(asin(sin))))

Measured memory_bytes: 5048
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b//gcd(a,b)
n,m=map(int,input().split())
s=input()
t=input()
l=lcm(n,m)
d={}
f=l
for i in range(max(n,m)):
    o=i*(l//n)
    p=i*(l//m)
    if i<n and o not in d:
        d[o]=s[i]
    elif i<n and o in d and d[o]!=s[i]:
        f=-1
    if i<m and p not in d:
        d[p]=t[i]
    elif i<m and p in d and d[p]!=t[i]:
        f=-1
print(f)


Measured memory_bytes: 61148
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    
    int i = 0;
    while(!(A < B && B < C)){
        if(A >= B){
            B *= 2;
        }
        else{
            C *= 2;
        }
        i++;
    }
    if(i <= K){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3128
# int(input()) # 入力が1つ
a, b, c, d = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

t = 0
while a > 0 or c > 0:
    if t == 0: # takahashi attack
        c -= b
        t = 1
    else:
        a -= d
        t = 0
    if c < 1:
        print('Yes')
        break
    if a < 1:
        print('No')
        break

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> pixel(H);
    for (int i = 0; i < H; i++) {
        cin >> pixel.at(i);
    }

    for (int i = 0; i < (W + 2); i++) cout << "#"; cout << endl;
    for (int i = 0; i < H; i++) cout << "#" << pixel.at(i) << "#" << endl;
    for (int i = 0; i < (W + 2); i++) cout << "#"; cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100001
using namespace std;
int n;
double pw,vw[N],pf[N],vf[N],th[N];
const double EPS = 1e-10;

double f(double x){
  double cost=x*pw;
  for(int i=0;i<n;i++){
    double v = th[i]-x*vw[i];
    if(v>0)cost+=pf[i]*(v/vf[i]);
  }
  return cost;
}

double search(){
  double L=0,R=101;
  while(abs(L-R)>EPS){
    double M1=(L+(R-L)/3);
    double M2=(L+2*(R-L)/3);
    if(f(M1)<f(M2))R=M2-EPS;
    else L=M1+EPS;
  }
  return L;
}


int main(){
  while(cin>>n,n){
    cin>>pw;
    for(int i=0;i<n;i++)scanf("%lf%lf%lf%lf",&vw[i],&pf[i],&vf[i],&th[i]);
    printf("%.10f\n",f(search()));
  }
  return 0;
}

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

int main(void){
    int N;
    cin >> N;
    int ans=0;
    if(N%1000 != 0) ans = 1000 - N%1000;
    else ans = 0;
    cout << ans << endl;
    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = 1000000007;

int main() {
	int N; cin >> N;
	V<int> A(N); rep(i, N) cin >> A[i];
	V<int> cnt(N);
	V<int> all(N);

	ll ans = 1;
	int zan = 3;

	rep(i, N) {
		if (A[i] == 0) {
			ans = ans * zan % MOD;
			--zan;
		} else {
			ans = ans * cnt[A[i] - 1] % MOD;
			--cnt[A[i] - 1];
		}
		++cnt[A[i]];
		++all[A[i]];
	}

	rep(i, N) if (all[i] > 3) {
		ans = 0;
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;

ll gcd(ll x, ll y){
	if(x < y)
		return gcd(y, x);
	if(y == 0)
		return x;
	return gcd(y, x%y);
}

int main(){
	long long a, b, c, d;
	int t;
	cin >> t;
	while(t--){
		cin >> a >> b >> c >> d;
		ll g = gcd(d, b);	
		ll r = a - (a/g)*g - g;
		if(a < b || d < b || c < b-1 && c-b < r)
			cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
using namespace std;


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

int main(void){
    double N, X;
    cin>>N;
    cin>>X;

    int koyaku = 0;
    int l, i=0, x[100010];
    for(i=0; i<N; i++){
        cin>>l;
        if (i == 0){
            koyaku = (int)fabs((int)(l - X));
        } else {
            int tmp = gcd(koyaku, (int)fabs(l - X));
            koyaku = tmp;
        }
    }
    cout << koyaku << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  static Scanner sc = new Scanner(System.in);
  public static void main(String[] args){
    String a = sc.next();
	if( Character.isUpperCase( a.charAt(0) ) ) {
    	System.out.println('A');
	}
	else {
    	System.out.println('a');
	}
  }
}   

Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

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

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int64_t dp[101][100001];

int main(){
    int N, K, A[100];
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> A[i];

    dp[0][0] = 1;
    for(int i=0; i<N; i++){
        int64_t sum = 0;
        for(int j=0; j<=K; j++){
            add(sum, dp[i][j]);
            if(j-A[i]-1>=0) add(sum, MOD - dp[i][j-A[i]-1]);
            add(dp[i+1][j], sum);
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}

Measured memory_bytes: 78336