akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int lifegame[110][5][5][5]; // (d, x, y, z)

bool inside(int x, int y, int z) {
    return 0 <= x && x < 5 && 0 <= y && y < 5 && 0 <= z && z < 5;
}

int main() {
    string line;
    int N, no = 1;
    while (true) {
        cin >> N;
        if (N == 0) break;

        for (int z = 0; z < 5; z++) {
            for (int x = 0; x < 5; x++) {
                cin >> line;
                for (int y = 0; y < 5; y++) {
                    lifegame[0][x][y][z] = line[y] - '0';
                }
            }
        }

        int M1, M2;
        cin >> M1;
        vector<int> a(M1);
        for (int i = 0; i < M1; i++) {
            cin >> a[i];
        }

        cin >> M2;
        vector<int> b(M2);
        for (int i = 0; i < M2; i++) {
            cin >> b[i];
        }
        for (int d = 0; d < N; d++) {
            for (int x = 0; x < 5; x++) {
                for (int y = 0; y < 5; y++) {
                    for (int z = 0; z < 5; z++) {
                        int num = 0;
                        for (int dx = -1; dx <= 1; dx++) {
                            for (int dy = -1; dy <= 1; dy++) {
                                for (int dz = -1; dz <= 1; dz++) {
                                    int nx = x + dx, ny = y + dy, nz = z + dz;
                                    if (!inside(nx, ny, nz) || (nx == x && ny == y && nz == z)) continue;
                                    num += lifegame[d][nx][ny][nz];
                                }
                            }
                        }
                        bool live = false,
                             die = true;
                        for (int i = 0; i < M1; i++) {
                            if (a[i] == num) live = true;
                        }
                        for (int i = 0; i < M2; i++) {
                            if (b[i] == num) die = false;
                        }

                        lifegame[d + 1][x][y][z] = lifegame[d][x][y][z];
                        if (lifegame[d][x][y][z] > 0 && die) {

                            lifegame[d + 1][x][y][z] = 0;
                        } else if (lifegame[d][x][y][z] == 0 && live) {
                            lifegame[d + 1][x][y][z] = 1;
                        }
                    }
                }
            }
        }

        if (no > 1) cout << endl;
        cout << "Case " << no++ << ":" << endl;
        for (int z = 0; z < 5; z++) {
            if (z > 0) cout << endl;
            for (int x = 0; x < 5; x++) {
                for (int y = 0; y < 5; y++) {
                    cout << lifegame[N][x][y][z];
                }
                cout << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define MAX 100005
#define pb push_back
#define mp make_pair
#define pii pair<long long,long long>
#define read(a) scanf("%d",&a)
#define p1(a) cout<<"Check "<<a<<endl;
#define p2(a,b) cout<<"Check "<<a<<' '<<b<<endl;
#define p3(a,b,c) cout<<"Check "<<a<<' '<<b<<' '<<c<<endl;
#define fo(i,n) for(i=0;i<n;i++)
#define ll long long
#define clr(a) memset(a,0,sizeof(a))
#define MOD 10000000000
#define INF 10000000000000;

using namespace std;

int node,edge;
vector<int>v[MAX];
bool vis[MAX];
int dp[MAX];

int dfs(int u){
    if(v[u].size()==0){
        dp[u]=0;
        return 0;
    }
    for(int i=0;i<v[u].size();i++){
        int n=v[u][i];
        if(vis[n]==false){
            vis[n]=true;
            int x=dfs(n)+1;
            dp[u]=max(dp[u],x);
        }
        else dp[u]=max(dp[u],dp[n]+1);
    }
    return dp[u];
}

int main()
{
    //freopen("input.txt","r",stdin);
    cin>>node>>edge;
    int x,y;
    clr(dp);
    for(int i=0;i<edge;i++){
        scanf("%d%d",&x,&y);
        v[x].pb(y);
    }
    int mx=0,tr=0;
    for(int i=1;i<=node;i++){
        vis[i]=true;
        mx=max(mx,dfs(i));
    }
//    for(int i=1;i<=node;i++){
//        vis[i]=true;
//        mx=max(mx,dfs(i)+tr);
//        if(i==1) tr=1;
//    }
    cout<<mx<<endl;


    return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n);
int S=0;
rep(i,n){
    cin>>a[i];
    S=S^a[i];
}
rep(i,n){
    int b=S^a[i];
    cout<<b<<endl;
}
return 0;
}

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

using namespace std;

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

#define print(a) {for(auto xxxxx : (a)) cout << xxxxx << ' '; cout << '\n';}
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin() , (a).end()
#define rall(a) (a).rbegin() , (a).rend()

ll next(){ll x; cin >> x;return x;}
const int maxn = 2e5 + 2 , intf = 2e9;
const ll inf = 2e18 , mod = 1e9 + 7;
const ld eps = 1e-9;

int n , k; 
int F(int x , int y){
    if (x > y) return x - y;
    else return n - abs(x - y);
}

void solve(){
    cin >> n >> k;
    vector <int> a(k);
    for (auto &x : a) 
        cin >> x;

    int ans = intf;
    for (int i = 0; i < k; i++){
        ans = min(ans , n - F(a[(i + 1) % k] , a[i]));
    }

    cout << ans;
}


//#define DEBUG

signed main(){
	#ifdef DEBUG
        freopen("input.txt" , "r" , stdin);
    #else
        //freopen(".in" , "r" , stdin); freopen(".out" , "w" , stdout);
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
    #endif
 
    for (int t = 1; t--;) solve();
 
    #ifdef DEBUG
        cout << setprecision(3) << fixed << "\n\nRuntime: " << (long double)(clock()) / CLOCKS_PER_SEC << " s.\n";
    #endif

	return 0;
}
/*


*/



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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
 
int main(){
    int N, X, D, A[100];

    cin >> N >> D >> X;
    for(int i = 0; i < N; i++) cin >> A[i];

    int ans = 0;
    for(int i = 0; i < N; i++){
        int c = 1;
        while(c <= D){
            ans++;
            c += A[i];
        }
    }

    ans += X;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define what_is(x) cerr << #x <<" is " << x << endl;
typedef long long ll;
const int MOD = 998244353;
const double PI = 3.141592653589793;
const int INF =  1e9 + 7;
const int nax = 200005;

ll power(ll a, ll b, ll mod = MOD) {
	ll ans = 1;
	while (b) {
		if (b & 1) {
			ans = (ans * a) % mod;
		}
		a = (a * a) % mod;
		b = b >> 1;
	}
	return ans;
}


vector<ll> f(nax, 1);
void init() {
	for (int i = 2; i < nax; i++) {
		f[i] = (i * f[i - 1]) % MOD;
	}
}

ll inv(ll x) {
	return power(x, MOD - 2);
}

ll nCr(ll n, ll r) {
	ll ans = f[n];
	ans = (ans * inv(f[r])) % MOD;
	ans = (ans * inv(f[n - r])) % MOD;
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc = 1;
	init();
	// cin >> tc;
	while (tc--) {
		ll n, m, k;
		cin >> n >> m >> k;
		ll ans = 0;
		for (ll p = n - k; p <= n; p++) {
			ans = (ans + ((nCr(n - 1, p - 1) * m) % MOD) * power(m - 1, p - 1)) % MOD;
		}
		cout << ans;
	}
	return 0;
}




















Measured memory_bytes: 4684
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
	string a;
	cin >> a;
	if (a.size() == 2)
	{
		cout << a << endl;
	}
	if (a.size() == 3)
	{
		reverse(a.begin(), a.end());
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 888
/**
 *    author:  ismail
 *    created: 20.01.2020  19:16:10
 **/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << (n == m ? "Yes" : "No");
  return 0;
}

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

int main(){

  int N,line[54],j=0;
  long long ans=1;
  cin >> N;
  string S1,S2;
  cin >> S1;
  cin >> S2;
  rep(i,54) line[i] = 0;
  for(int i=0; i<S1.size()-1; i++){
    if(S1[i]==S1[i+1]){
      line[j] = 1;
      i++;
    } else {
      line[j] = 2;
    }
    j++;
  }
  if(S1[S1.size()-1]!=S1[S1.size()-2]) line[j] = 2;
  if(line[0]==1) ans *= 6;
  else ans *= 3;
  for(int i=1;i<54;i++){
    if(line[i]==0) break;
    if(line[i-1]==1 && line[i]==1){
      ans *= 3;
      ans %= M0D;
    }
    if(line[i-1]==1 && line[i]==2) ans *= 1;
    if(line[i-1]==2 && line[i]==1){
      ans *= 2;
      ans %= M0D;
    }
    if(line[i-1]==2 && line[i]==2){
      ans *= 2;
      ans %= M0D;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int l,r;cin>>l>>r;
    int m=0;
    if (r-l<=2019){
        m=2100;
        for(int i=l;i<r;++i){
            for(int j=i+1;j<=r;++j)
                m=min(m,int((ll)i*j%2019));
        }
    }
    cout << m;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

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

    for (int i = 0; i < T.size(); i++) {
        if (T[i] == '?') {
            T[i] = 'D';
        }
    }

    cout << T << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(3*n);
  rep(i, 3*n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  ll ans = 0;
  rep(i, 2*n) if (i % 2 == 1) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4588
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;

int dp[3009][3009]{};
int main()
{

    string s,t; cin>>s>>t;

    int n = s.length() ;
    int m = t.length();

    for(int i = 0 ; i<n ; i++)
    {
        for(int j = 0 ; j<m ; j++)
        {
            if(s[i]==t[j])
            {
                int add = 0;
                if(i-1>=0 && j-1>=0 )add= dp[i-1][j-1];
                dp[i][j] = 1+ add;
            }
            else
            {
                int row = 0; int col=0;
                if(i-1>=0)row = dp[i-1][j];
                if(j-1>=0)col = dp[i][j-1];
                dp[i][j] = max(row ,col);
            }
        }
    }

    string LCS = "";
    int i = n-1; int j=m-1;
    while(i>=0 && j>=0)
    {
            if(i==0 && j==0 )
            {
                if(dp[0][0]>0)
                    LCS+=s[0];

                break;
            }

            int row = 0 ;  int col=0;
            if(i-1>=0)row = dp[i-1][j];
            if(j-1>=0)col = dp[i][j-1];
            if(dp[i][j]> row  && dp[i][j]> col)
            {
                LCS += s[i];
                i-=1;
                j-=1;
            }
            else if(dp[i][j]==row)
            {
                i--;
            }
            else if(dp[i][j]==col)
            {
                j--;
            }
    }


    reverse(LCS.begin() , LCS.end());
    cout<<LCS<<endl;
    return 0;
}


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

int main() {
  int y, m , d;
  char s, t;
  cin >> y >> s >> m >> t >> d;

  if(m >= 5) {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }

}



Measured memory_bytes: 3564
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	bool cs[26] = {};
	string S;
	cin >> S;
	for (auto c : S) {
		auto i = c - 'a';
		if (cs[i]) {
			printf("no\n");
			return 0;
		}
		cs[i] = true;
	}
	printf("yes\n");
	return 0;
}

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

int main() {
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  const double PI = acos(-1);
  
  double theta_A = 2*PI*(H+M/60)/12;
  double theta_B = 2*PI*M/60;
  double x_A = A*sin(theta_A);
  double x_B = B*sin(theta_B);
  double y_A = A*cos(theta_A);
  double y_B = B*cos(theta_B);

  double ans = sqrt( (x_A - x_B)*(x_A - x_B) + (y_A - y_B)*(y_A - y_B)) ;
  cout << fixed << setprecision(10) << ans << endl;

}

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

int main() 
{
	int n, q = 0;
	cin >> n;
	int x[n], y[n], t[n];
	for ( int i = 0; i < n; i++ )
	{
		cin >> t[i] >> x[i] >> y[i];
		if ( x[i] + y[i] <= t[i] && ( x[i] + y[i] - t[i] ) % 2 == 0 )
			q++;
	}
	if ( q == n )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
		
	return 0;
}

Measured memory_bytes: 1408
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, K = iim()
    mod = 10**9 + 7

    if N == 1 or K == 1:
        print(1)
        return

    dp = [[0] * (K+1) for i in range(N+1)]
    dp[0][0] = 1

    def ik(n, k):
        for i in range(1, min(k,n+1)):
            yield (i, i)
        for i in range(i+1, n+1):
            yield (i, k)

    for i, kx in ik(N, K):
        for k in range(1, kx+1):
            dp[i][k] = dp[i-1][k-1] + dp[i-k][k]

    #for row in dp:
    #    print(row)

    print(sum(dp[N]) % mod)

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 32004
#include <iostream>

#define lint long long int

using namespace std;

 long long int max(long long int a,long long  int b) 

{long long int f=a>b?a:b;

return f;}

long long int knapsack (long long int n,  long long int w, long long int wt[], long long int v[]) 

{

//cout<<n<<endl;

return max(v[n-1]+knapsack (n-1, w-wt[n-1], wt, v), knapsack (n-1, w, wt, v)) ;

}

int main() {

	// your code goes here

int n, w;

cin>>n>>w;

long long int wt[n], v[n], k[n+1][w+1]={0};

for(int p=0;p<n;p++) 

cin>>wt[p]>>v[p];

for(int p=0;p<=n;p++) 

{

for(int q=0;q<=w;q++) 

{

if(p==0||q==0)

k[p][q]=0;

else if(wt[p-1]>q) 

k[p][q]=k[p-1][q];

else

{

k[p][q]=max(v[p-1]+k[p-1][q-wt[p-1]], k[p-1][q]) ;

}

}//inner for

}//outer for

/*

for(int p=0;p<=n;p++) 

{

for(int q=0;q<=w;q++) 

{ cout<<k[p][q]<<" ";}

cout<<endl;

}*/

//cout<<k[0][0];

//cout<<endl;

//cout<<knapsack(n, w, wt, v) ;

cout<<k[n][w];

	return 0;

}

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

using namespace std;

int N, C;
int a[101], b[101], c[101];

int dp[2][101][10101];

int main() {
  cin >> N >> C;
  for(int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];

  memset(dp, -1, sizeof(dp));
  int (*curr)[10101] = dp[0];
  int (*next)[10101] = dp[1];
  curr[0][0] = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 101; j++)
      for(int k = 0; k < 10101; k++) next[j][k] = -1;
    for(int j = C; j >= 0; j--) {
      for(int k = 10000; k >= 0; k--) {
	if(curr[j][k] == -1) continue;
	next[j][k] = curr[j][k];
	if(j+c[i] > C) continue;
	if(k+a[i] <= 10000) next[j+c[i]][k+a[i]] = max(next[j+c[i]][k+a[i]], curr[j][k]+b[i]);
	if(k+b[i] <= 10000) next[j+c[i]][k+b[i]] = max(next[j+c[i]][k+b[i]], curr[j][k]+a[i]);
      }
    }
    swap(curr, next);
  }

  /*
  for(int i = 0; i <= C; i++) {
    for(int j = 0; j < 10; j++) {
      cout << i << " " << j << " " << curr[i][j] << endl;
    }
  }
  */

  int ans = 0;
  for(int i = 0; i <= C; i++) {
    for(int j = 0; j <= 10000; j++) {
      ans = max(ans, min(j, curr[i][j]));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  int d,x; cin>>d>>x;
  int ans=0,tmp;
  for(int i=0;i<n;i++){
    cin>>tmp;
    ans+=(d-1)/tmp+1;
  }
  cout <<ans+x<<endl;
}

Measured memory_bytes: 256
puts [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381][0..gets.to_i-1].join("\s")

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long int n,k;
 
    
cin >> n >> k;
long int allhp=0;
    vector <long int> a(n);
    for (long int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        allhp+=a.at(i);
        
    }
    sort(a.begin(), a.end());
    if(n<k)
    {k=n;}
   for (long int l = 1; l <= k; l++)
    {    allhp-=a.at(n-l);
    }
    if(allhp < 0)
    {allhp=0;}
    cout << allhp << endl;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n, h[101];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	h[n] = 0;
	int min,last,cnt=0;
	for (int i = 0; i < n;) {
		min = h[i];
		for (int j = i + 1; j <= n; j++) {
			if (h[j] == 0) { last = j - 1; break; }
			else { if (h[j] < min)min = h[j]; }
		}
		for (int j = i; j <= last; j++) {
			h[j] -= min;
		}
		cnt+=min;
		if(h[i]==0)
			for (int j = i+1;j<n; j++) {
				if (h[j] != 0) { i = j; break; }
			}
		if (h[i] == 0) i = n;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

int main(void) {

    int A,B,C,D;
    cin>>A>>B>>C;

    D=100*A+B*10+C*1;

    if(D%4==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int maxN = 1e5 + 10;

typedef pair<int, int> ii;
struct TEdge{int x, color, w;};
struct Query{int id, color, dist, k;};

int             n, m, root;
int             h[maxN], p[20][maxN], d[maxN], cnt[maxN], res[maxN];
vector<Query>   q[maxN];
vector<TEdge>   adj[maxN];

void dfs1(int u, int par, int d){
    h[u] = d;

    for(auto t : adj[u]){
        int v = t.x;
        if(v == par) continue;
        p[0][v] = u;
        dfs1(v, u, d + 1);
    }
}

int lca(int x, int y){
    for (int k = 19; k >= 0; k--)
        if (h[p[k][x]] >= h[y])
            x = p[k][x];
    for (int k = 19; k >= 0; k--)
        if (h[p[k][y]] >= h[x])
            y = p[k][y];
    for (int k = 19; k >= 0; k--)
        if (p[k][x] != p[k][y]) {
            x = p[k][x];
            y = p[k][y];
        }
    while (x != y) {
        x = p[0][x];
        y = p[0][y];
    }
    return x;
}

void dfs2(int x, int par, int dist)
{
    for(int i = 0; i < q[x].size(); ++i){
        Query tmp = q[x][i];
        res[tmp.id] += tmp.k * (dist - d[tmp.color] + cnt[tmp.color] * tmp.dist);
    }

    for(int i = 0; i < adj[x].size(); ++i){
        TEdge u = adj[x][i];
        if(u.x == par) continue;
        cnt[u.color]++;
        d[u.color] += u.w;
        dfs2(u.x, x, dist + u.w);
        cnt[u.color]--;
        d[u.color] -= u.w;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    //freopen("ColorfulTree.inp", "r", stdin);

    cin >> n >> m;
    for(int i = 1; i <= n - 1; ++i)
    {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        adj[a].push_back({b,c,d});
        adj[b].push_back({a,c,d});
    }

    dfs1(1, 0, 1);

    for(int k = 1; k <= 19; ++k)
        for(int i = 1; i <= n; ++i)
            p[k][i] = p[k-1][p[k-1][i]];

    for(int i = 1; i <= m; ++i)
    {
        int color, dist, u, v;
        cin >> color >> dist >> u >> v;
        q[u].push_back({i, color, dist, 1});
        q[v].push_back({i, color, dist, 1});
        q[lca(u,v)].push_back({i, color, dist, -2});
    }

    dfs2(1, 0, 0);

    for(int i = 1; i <= m; ++i)
        cout << res[i] << " ";
}


Measured memory_bytes: 51108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Programminng
{
    class AOJ_Volume0017
    {
        public static void Main(string[] args)
        {
            string key_1 = "the",key_2 = "this",key_3 = "that";

            while(true)
            {
               string s = Console.ReadLine();
               if (string.IsNullOrEmpty(s)) break;
               
               for (int i = 0; i < 26; i++)
               {
                    char[] c = s.ToCharArray();
                    for (int j = 0; j < c.Length; j++)
                    {
                        if (c[j] != ' ' && c[j] != '.')
                        {
                            c[j]++;
                            if (c[j] > 'z') c[j] = (char)(c[j] - 26);
                        }
                    }
                    s = new string(c);
                    if (s.Contains(key_1)) Console.WriteLine(s);
                    else if (s.Contains(key_2)) Console.WriteLine(s);
                    else if(s.Contains(key_3)) Console.WriteLine(s);
                }
            }
        }
    }
}

Measured memory_bytes: 6228
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

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

    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using uint = unsigned int;

using namespace std;
struct Key{
    int val;
    vector<int> target;
    uint targetSum;
};
int memo[4100][1005];
int init(){
    for(int i = 0; i < 4100; i++){
        for(int j = 0; j < 1005; j++){
            memo[i][j] = 1 << 30;
        }
    }
    memo[0][0] = 0;
}

int main() {
    init();
    int N,M;
    cin >> N >> M;
    Key k[M];
    for(int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        k[i].val = a;
        k[i].target = vector<int>();
        k[i].targetSum = 0;
        for(int j = 0; j < b; j++){
            ll tmp;
            cin >> tmp;
            k[i].target.push_back(tmp - 1);
            k[i].targetSum += 1 << (tmp - 1);
        }
    }
    for(int i = 1; i <= M; i++){
        for(uint j = 0; j < (1 << N); j++){
            uint targetsum = k[i - 1].targetSum;
            uint result = targetsum | j;
            memo[result][i] = min(min(memo[result][i - 1],memo[j][i - 1] + k[i - 1].val),memo[result][i]);
            memo[j][i] = min(memo[j][i],memo[j][i - 1]);
        }
    }
    for(int i = 0; i < M; i++){
        for(int j = 0; j < (1 << N); j++){
            //cout << memo[j][i] << " ";
        }
        //cout << endl;
    }
    if(1073741824 == memo[(1 << N) - 1][M]){
        cout << -1 << endl;
        return 0;
    }
    cout << memo[(1 << N) - 1][M] << endl;

}


Measured memory_bytes: 16512
function Main(input) {
  // input[0] => １行目, input[1] => 2行目
  input = input.split(" ");

  const n = parseInt(input[0], 10);
  const a = parseInt(input[1], 10);
  const b = parseInt(input[2], 10);

  const train = n * a;
  const taxi = b;

  train > taxi ? console.log(taxi) : console.log(train)
}

// *型変換
// 文字列から10進数
// let a = parseInt(input[0], 10)

// *出力
// console.log('%d', number);
// console.log('%s', string);


// 編集しない
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < s.size() - 1; i++){
    if(s[i] == s[i+1]){
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
  }
  for(int i = 0; i < s.size() - 2; i++){
      if(s[i] == s[i+2]){
         cout << i + 1 << " " << i + 3 << endl;
         return 0;
      }
  }
  cout << "-1 -1" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> C(N);
  ll W = 0;
  ll temp = 0;
  for (ll i = 0; i < N; ++i) {
    char c;
    cin >> c;
    if (c == 'R') {
      C.at(i) = 0;
    }
    else {
      C.at(i) = 1;
      W += 1;
    }
  }
  ll ans = 0;
  for (ll i = N - 1; i > N - W - 1; --i) {
    if (C.at(i) == 0) {
      ans += 1;
    }
  }
  cout << ans << "\n";
}


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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));
    vector<vector<int>> A(H, vector<int>(W));
    for (int i = 0; i < 10; i++){
        for (int j = 0; j < 10; j++){
            cin >> c.at(i).at(j);
        }
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cin >> A.at(i).at(j);
        }
    }
    
    for (int i = 0; i < 10; i++){
        for (int j = 0; j < 10; j++){
            for (int k = 0; k < 10; k++){
                c.at(j).at(k) = min(c.at(j).at(k), c.at(j).at(i) + c.at(i).at(k));
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            if (A.at(i).at(j) == -1){
                continue;
            }
            else{
                ans += c.at(A.at(i).at(j)).at(1);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;
using namespace __gnu_pbds;

mt19937_64 gen(time(0));

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

//const int mod = 1e9 + 7;
//const int inf = 2e9 + 6555;
//const int maxn = 2e5 + 544;



signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (i % 2 == 0 && x % 2 == 1) ++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3632
N,K = map(int,input().split())
P = 0
for i in range(1,N+1):
  j = 0
  t = 1
  while t>0:
    t = K-i*2**j
    j = j+1
  P = P+(1/N)*(1/2)**(j-1)
print(P)

Measured memory_bytes: 9232
n, m, l = map(int, input().split())
a = [[0 for j in range(m)] for i in range(n)]
b = [[0 for k in range(l)] for j in range(m)]
c = [[0 for k in range(l)] for i in range(n)]

for i in range(n):
  a[i] = list(map(int, input().split()))
for i in range(m):
  b[i] = list(map(int, input().split()))
for i in range(n):
  for k in range(l):
    sum = 0
    for j in range(m):
      sum += a[i][j] * b[j][k]
    c[i][k] = sum
    if k == 0:
      print(c[i][k], end = "")
    else:
      print("", c[i][k], end = "")
  print()


Measured memory_bytes: 7168
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**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

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():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        ms = []
        for _ in range(n):
            m,l = LI()
            a = [LI() for _ in range(m)]
            b = 0
            for s,e in a:
                for i in range(s,e):
                    b |= 2**(i-6)
            ms.append((l,b))

        d = collections.defaultdict(int)
        d[0] = 0
        for l,b in ms:
            for k,v in list(d.items()):
                if b&k > 0:
                    continue
                if d[b|k] < v + l:
                    d[b|k] = v + l
        rr.append(max(d.values()))

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 17984
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    cout <<( (100 * r + 10 * g + b) % 4 == 0 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MOD 1000000007

typedef long long ll;

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

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

/*qsort(array,num_of_index,sizeof(int),compare_int); */
 int compare_int(const void *a,const void *b){
     return *(int*) a - *(int *) b; 
 } 

ll calc(ll num,ll len){
    ll tmp=1;
    for(ll i=0;i<len;i++){
        tmp *= num;
        tmp %= MOD;    
    }
    return tmp;
}
 
int main(){
    ll N;    
    scanf("%lld",&N);
    ll ans = 2*MOD + calc(10,N) + calc(8,N) - 2*calc(9,N);
    ans %= MOD;
    printf("%lld",ans);
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

//エラストテネスの篩(O(nloglogn))
struct sieve {
    int n;
    vector<int> f, primes;
    sieve(int n = 1) : n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; i++) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if(!f[j]) f[j] = i;
            }
        }
    }
    bool is_prime(int x) {return f[x] == x;}
    // 素因数分解したものを返す(12=2x2x3)
    vector<int> factor_list(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    // xが小さいときはエラストテネスの篩を用いて素因数分解
    vector<P> factor(int x) {
        vector<int> fl = factor_list(x);
        if (fl.size() == 0) return {};
        vector<P> res(1,P(fl[0],0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p,1);
            }
        }
        return res;
    }
    vector<pair<ll,int>> factor(ll x) {
        vector<pair<ll,int>> res;
        for (int p : primes) {
            int y = 0;
            while (x % p == 0) {
                x /= p;
                y++;
            }
            if (y != 0) res.emplace_back(p,y);
        }
        if (x != 1) res.emplace_back(x,1);
        return res;
    }
};

int main() {
    int n; cin >> n;
    sieve sv(1000000);
    int ans = 0;
    for (int c = 1; c < n; c++) {
        int x = n - c;
        vector<P> p = sv.factor(x);
        int sum = 1;
        rep(i,p.size()) {
            sum *= p[i].second + 1;
        }
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7832
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    //真ん中の仕切りを動かして全探索する
    //真ん中の仕切りを動かした後に最適に左右の仕切りを動かす．
    //この時，左右の仕切りは当然右にしか動かないので結局O(n)でこの問題は解けます．（きっと）

    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll A=a[0],B=a[1],C,D;
    int left=0;
    int right;{
        //2<=i<nとこでに分割して差を小さく
        ll p=0,q=0;int l=2,r=n-1;
        while(l<=r){
            if(p>q){
                // 右を進める
                q+=a[r];
                r--;
            }
            else{
                p+=a[l];
                l++;
            }
        }
        right=l;C=p;D=q;
    }
    right--;
    ll ans=max({A,B,C,D})-min({A,B,C,D});

    for(int center=2;center<n-2;center++){
        B+=a[center];C-=a[center];
        //貪欲に移動させる
        //left
        while(true){
            if(left<center&&abs(A-B)>abs(A+a[left+1]-B+a[left+1])){
                A+=a[left+1];B-=a[left+1];
                left++;
            }
            else break;
        }
        //right
        while(true){
            if(right<n&&abs(C-D)>abs(C+a[right+1]-D+a[right+1])){
                C+=a[right+1];D-=a[right+1];
                right++;
            }
            else break;
        }
        chmin(ans,max({A,B,C,D})-min({A,B,C,D}));
        // cout<<endl;
        // cout<<ans<<endl;
        // cout<<left<<' '<<center<<' '<<right<<endl;
        // cout<<A<<' '<<B<<' '<<C<<' '<<D<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int N = 100000 + 100;
const int MOD = 1000000007;
const int oo = 1e9;

string s;
int freq[27];

vector<int> S, E;

int main() {
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		freq[s[i] - 'a']++;
	}
	for (int i = 'a'; i <= 'z'; ++i) {
		if (!freq[i - 'a'])S.pb(i);
		else E.pb(i);
	}

	if (S.size()) {
		cout << s << (char)(S[0]) << endl;
		return 0;
	} else {
		if (s == "zyxwvutsrqponmlkjihgfedcba") {
			cout << -1 << endl;
			return 0;
		}

		while (1) {
			char bk = s[s.size()-1];
			freq[bk-'a']--;
			s.resize(s.size() - 1);
			for (int i = bk-'a'+1; i < 26; ++i){
				if(!freq[i]){
					s += char(i+'a');
					cout << s << endl;
					return 0;
				}
			}
	
		}
		cout << s << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#pragma warning(disable:4996)
//FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 0x7fffffff
#define NM 100005
#define MOD 1000000007
#define FOR(i,n,m) for (int i=(n);i<=(m);i++)
#define si(n) fscanf(in,"%d",&n)
#define sd(n) fscanf(in,"%lf",&n)
typedef long long int ll;
struct LIST {
	int x, y;
	LIST() {}
	LIST(int x, int y) :x(x), y(y) {}
	bool operator<(const LIST& rhs) {
		return x < rhs.x;
	}
}Q1[NM], Q2[NM];
int N1, N2;
vector<int> X1[NM], X2[NM], Y1[NM], Y2[NM];
int a[NM], n, m;
ll ans[NM];
void input() {
	si(n); si(m);
	FOR(i, 1, n) {
		si(a[i]);
		if (i == 1) continue;
		if (a[i] > a[i - 1]) {
			Q1[++N1] = LIST(a[i - 1], a[i]);
			X1[Q1[N1].x].push_back(N1);
			Y1[Q1[N1].y].push_back(N1);
		}
		else {
			Q2[++N2] = LIST(a[i], a[i - 1]);
			X2[Q2[N2].x].push_back(N2);
			Y2[Q2[N2].y].push_back(N2);
		}
	}
}
void solve_inc(LIST Q[], vector<int> X[], vector<int> Y[], int N) {
	int HN = 0;
	ll tot = 0;
	FOR(i, 1, N) tot += Q[i].y - Q[i].x;
	int cnt = 0;
	FOR(i, 1, m) {
		for (auto &idx: X[i - 1]){
			tot -= Q[idx].y - Q[idx].x;
			tot += Q[idx].y;
			cnt++;
		}
		ans[i] += tot - (ll)cnt * (i - 1);
		for (auto &idx:Y[i]){
			tot -= Q[idx].y;
			tot += Q[idx].y - Q[idx].x;
			cnt--;
		}
	}
}
void solve_dec(LIST Q[], vector<int> X[], vector<int> Y[], int N) {
	ll tot = 0, cnt = N;
	FOR(i, 1, N) tot += Q[i].x;
	ans[1] += tot;
	FOR(i, 2, m) {
		for (auto &idx : X[i - 1]) {
			tot -= Q[idx].x;
			tot += (m - Q[idx].y) + Q[idx].x;
			cnt--;
		}
		ans[i] += tot + cnt * (1 - i);
		for (auto &idx : Y[i]) {
			tot -= (m - Q[idx].y) + Q[idx].x;
			tot += m + Q[idx].x;
			cnt++;
		}
	}
}
int main() {
	input();
	solve_inc(Q1, X1, Y1, N1);
	solve_dec(Q2, X2, Y2, N2);
	ll res = 1e18;
	FOR(i, 1, m) res = min(res, ans[i]);
	fprintf(out, "%lld", res);
	return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%I64d",&x)
#define ss(s)	scanf("%s",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int N = 2e5;
vi g[N];
int a[N];

int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i;
	ll a, b;
	cin>>a>>b;
	string p = "Positive";
	string n = "Negative";
	string z = "Zero";
	
	if (a<=0 and b>=0){
		cout<<z<<endl;
		return 0;
	}
	if (a==0 or b==0){
		cout<<z<<endl;
		return 0;
	}
	
	if (a>0 and b>0){
		cout<<p<<endl;
		return 0;
	}
	
	ll nt = b-a+1;
	if (nt&1){
		cout<<n<<endl;
	}
	else{
		cout<<p<<endl;
	}
	
	return 0;
} 

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
string s;
int cnt[30];
int f=1;

char win(int l,int r){
  if(l==r)return s[l];
  int cnts=0;
  int k;
  for(int i=l+1;i<r;i++){
    if(s[i]=='[')cnts++;
    if(s[i]==']')cnts--;
    if(cnts==0&&s[i]=='-'){
      k=i;
      break;
    }
  }
  char a=win(l+1,k-1);
  char b=win(k+1,r-1);
  int p1=cnt[a-'a']--;
  int p2=cnt[b-'a']--;
  if(p1==0&&p2==0)f=0;
  if(p1>0&&p2>0)f=0;
  if(p1>0)return a;
  if(p2>0)return b;
  return 'a';
}

int main(){
  cin>>s;
  int n=0;
  for(int i=0;i<s.size();i++)
    if('a'<=s[i]&&s[i]<='z')n++;
  
  for(int i=0;i<n;i++){
    char a;
    int v;
    cin>>a>>v;
    cnt[a-'a']=v;
  }

  if(cnt[win(0,s.size()-1)-'a']!=0)f=0;
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}



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

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

Measured memory_bytes: 3604
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: August 20 , 2019
 * 
 */

#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {
    // your solution goes here 
    ivv(a);
    cv(ch);
    ivv(b);
    cout<<((ch=='+'?a+b:a-b))<<endl;
    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

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

typedef long long ll;

int main()
{
    int n;
    int i;
    cin >> n;
    vector<int> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int temp;
    if(a.at(n-1)%2 == 1){
        temp = (a.at(n-1)+1)/2;
    }else{
        temp = a.at(n-1)/2;
    }
    int temp_id = lower_bound(a.begin(),a.end(),temp) - a.begin();
    if(temp_id == 0){
        cout << a.at(n-1) << " " << a.at(temp_id) << endl;
    }else{
        int o_id = temp_id-1;
        int ans;
        if(abs(temp -1 - a.at(o_id)) < abs(temp-a.at(temp_id))){
            ans = o_id;
        }else{
            ans = temp_id;
        }
        cout << a.at(n-1) << " " << a.at(ans) << endl;
    }
    return 0;
}

Measured memory_bytes: 640
n=int(input())
p=list(map(int, input().split()))
p_sort=sorted(p)
count=0
for i in range(n):
  if p[i]!=p_sort[i]:
    count+=1
  else:
    continue
if count==2 or count==0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060