akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<string>S;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    S.push_back(s);
  }
  string T;
  cin >> T;
  vector<string>S1;
  int start = 0, last = 0;
  for(int i=0;i<N;i++){
      string s = S[i];    
    for(int j=0;j<s.size();j++){
      if(s[j] == '?') s[j] = 'z';
    }
    S1.push_back(s);
  }
  S1.push_back(T);
  sort(S1.begin(), S1.end());

  for(int i=0;i<N+1;i++){
    //    cout << S1[i] << endl;
    if(S1[i] == T){
      start = i;
      break;
    }
  }

  S1.clear();
  for(int i=0;i<N;i++){
      string s = S[i];    
    for(int j=0;j<s.size();j++){
      if(s[j] == '?') s[j] = 'a';
    }
    S1.push_back(s);
  }
  
  S1.push_back(T);
  sort(S1.begin(), S1.end());

  for(int i=0;i<N+1;i++){
    //    cout << S1[i] << endl;    
    if(S1[i] == T){
      last = i;
    }
  }  
  for(int i=start+1;i<=last;i++){
    cout << i << " ";
  }
  cout << last+1 << endl;
  return 0;
}


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

int main(){
  int i, j, k, n, u, m;
  int V[100][100] = {};

  scanf("%d",&n);
  if( n<1 || 100<n ) exit(1);

  for( i=0 ; i<n ; i++ ){
    scanf("%d",&u);

    scanf("%d",&m);

    for( j=0 ; j<m ; j++ ){
      scanf("%d",&k);
      V[u-1][k-1] = 1;
    }
  }

  for( i=0 ; i<n ; i++ ){
    for( j=0 ; j<n ; j++ ){
      if( j == n-1 ) printf("%d\n",V[i][j]);
      else printf("%d ",V[i][j]);
    }
  }

  return 0;
}

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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;

int main() {
    int N; cin>>N;
    cout << N*800 - N/15*200 << endl;
    return 0;
}

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

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

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

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

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

using namespace std;

bool dp[5000][16001];
bool dp2[5000][16001];

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s; s.pb('T');
    int x,y; cin>>x>>y;
    int n = s.size();
    int f=0;
    rep(i,n){
        if (s[i]=='T') break;
        f++;
    }
    x-=f;
    s=s.substr(f+1); n=s.size();
    vi ax,ay;
    bool mode=false;
    int cnt=0;
    rep(i,n){
        if (s[i]=='F') cnt++;
        if (s[i]=='T'){
            if (cnt>0) (mode?ax:ay).pb(cnt);
            cnt=0;
            mode=!mode;
        }
    }
    if (cnt>0) (mode?ax:ay).pb(cnt);
    int m = ax.size();
    int l = ay.size();
    dp[0][8000]=true;
    rep(i,m)FOR(j,-8000,8000){
        if (j-ax[i]>=-8000 && dp[i][j+8000-ax[i]]) dp[i+1][j+8000]=true;
        if (j+ax[i]<=8000 && dp[i][j+8000+ax[i]]) dp[i+1][j+8000]=true;
    }
    dp2[0][8000]=true;
    rep(i,l)FOR(j,-8000,8000){
        if (j-ay[i]>=-8000 && dp2[i][j+8000-ay[i]]) dp2[i+1][j+8000]=true;
        if (j+ay[i]<=8000 && dp2[i][j+8000+ay[i]]) dp2[i+1][j+8000]=true;
    }
    if (dp[m][x+8000] && dp2[l][y+8000]){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 64384
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 5e5+7;
int n;
void nhap()
{
    cin >> n;
}
void solve()
{
    map <long long,int> m;
    long long oo = 1e15;
    m[0 + oo] = 1;
    long long s = 0;
    long long res = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        s += x;
        res += m[s + oo];
        m[s + oo]++;
    }
    cout << res;
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 12800
#include <iostream>
#include <climits>
#include <string>
using namespace std;
const int MAXSEQ = 1000;
const int INFY = -INT_MAX;

string X, Y;

int max(int m, int n){
    int max = INFY;
    printf("\n");
    return max;
}
int LSCLength(void){
    int m = X.size();
    int n = Y.size();
    int c[m+1][n+1];
    for (int i = 0; i <= m; i++){
        c[i][0] = 0;
    }
    for (int j = 0; j <= n; j++){
        c[0][j] = 0;
    }
    /*
    for (int i = 0; i <= m; i++){
        for (int j = 0; j <= m; j++){
        */
    /*
    if (m > n){
        cout << "will change X =" <<  X << endl;
        swap(m, n);
        swap(X, Y);
        cout << "changed X =" <<  X << endl;
    }*/
    for (int i = 1; i <= m; i++){
        for (int j = 1; j <= n; j++){
            if (X[i-1] == Y[j-1]){
                c[i][j] = c[i-1][j-1] + 1;
            }else if (c[i-1][j] >= c[i][j-1]){
                c[i][j] = c[i-1][j];
            }else{
                c[i][j] = c[i][j-1];
            }
        }
    }
    int max = INFY;
    //printf("\n");
    /*
    for (int i = 0; i <= m; i++){
        for (int j = 0; j <= n; j++){
            printf("%d ", c[i][j]);
        if (max < c[m][i]) max = c[i][j];
        }
        printf("\n");
    }
    */
    for (int j = 1; j <= n; j++){
        if (max < c[m][j]) max = c[m][j];
    }
    return max;
}

int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> X >> Y;
        cout << LSCLength() << endl;
    }
    return 0;
}



Measured memory_bytes: 7132
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
h,w=map(int,input().split())
d=[list(map(int,input().split())) for i in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
a=[list(map(int,input().split())) for i in range(h)]
# for i in range(10):
#     print(d[i])
ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]!=-1:
            ans+=d[a[i][j]][1]
print(ans)

Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder
{
    public static class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var targets = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            targets.Sort();
            Console.WriteLine(targets[N / 2] - targets[N / 2 - 1]);
        }
    }
}


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

using namespace std;

int main(){

	string b;
	cin>> b;

	if(b=="A") cout<< "T" << endl;
	if(b=="T") cout<< "A" << endl;
	if(b=="C") cout<< "G" << endl;
	if(b=="G") cout<< "C" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool triangle_cons(int a,int b,int c){
	if(a+b>c&&a+c>b&&b+c>a&&a!=b&&a!=c&&b!=c){
		return true;
	}
	return false;
}
signed main() {
	int n,cnt=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			for(int k=j+1;k<=n;k++){
				if(triangle_cons(a[i],a[j],a[k])){
					cnt++;
				}
			}
		}
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3620
import scala.collection.mutable.HashMap
import scala.annotation.tailrec

object Main extends App {
  val Array(n, k) = io.StdIn.readLine.split(" ").map(_.toLong)
  val map = HashMap.empty[Int, Long]
  Iterator.continually(io.StdIn.readLine)
    .take(n.toInt)
    .map(_.split(" "))
    .foreach(e => {
      val key   = e(0).toInt
      val value = e(1).toLong
      if(!map.contains(key)) map += key -> value
      else map(key) += value
    })

  def f(map:HashMap[Int, Long], k:Long):Int = {
    val ite = map.keys.toList.sorted.iterator

    @tailrec
    def rec(acc:Long, key:Int, k:Long ):Int = {
      val res = acc + map(key)
      if(res >= k) key
      else rec(res, ite.next, k)
    }

    rec(0L, ite.next, k)
  }

  println(f(map, k))
}

Measured memory_bytes: 49176
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
char s[1010][1010];
char f3[3][10]={"aa.","..a","..a"};
char f4[4][10]={"aabc",
				"ddbc",
				"bcaa",
				"bcdd"};
char f5[5][10]={"aabba",
				"bcc.a",
				"b..cb",
				"a..cb",
				"abbaa"};
char f6[6][10]={"aabc..",
				"ddbc..",
				"..aabc",
				"..ddbc",
				"bc..aa",
				"bc..dd"};
char f7[7][10]={"aabbcc.",
				"dd.dd.a",
				"..d..da",
				"..d..db",
				"dd.dd.b",
				"..d..dc",
				"..d..dc"};
int main(){
	int n=gi();
	if(n==2)return puts("-1"),0;
	if(n==3){
		puts("aa.");
		puts("..a");
		puts("..a");
		return 0;
	}
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)s[i][j]='.';
	int N=n;
	while(n>7||n==4){
		for(int i=0;i<4;++i)
			for(int j=0;j<4;++j)
				s[n-i][n-j]=f4[i][j];
		n-=4;
	}
	if(n==5)
    	for(int i=0;i<5;++i)
			for(int j=0;j<5;++j)
				s[n-i][n-j]=f5[i][j];
	if(n==6)
    	for(int i=0;i<6;++i)
			for(int j=0;j<6;++j)
				s[n-i][n-j]=f6[i][j];
	if(n==7)
    	for(int i=0;i<7;++i)
			for(int j=0;j<7;++j)
				s[n-i][n-j]=f7[i][j];
	for(int i=1;i<=N;++i)printf("%s\n",s[i]+1);
	return 0;
}


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

using ll = long long;

int main() {
    int x, y, a, b, c, temp;
    cin >> x >> y >> a >> b >> c;
    priority_queue<int> aa, bb, cc, d;
    for (int i = 0; i < a; i++) {
        cin >> temp;
        aa.push(temp);
    }
    for (int i = 0; i < b; i++) {
        cin >> temp;
        bb.push(temp);
    }
    for (int i = 0; i < c; i++) {
        cin >> temp;
        cc.push(temp);
    }
    ll s=0;
    for (int i = 0; i < x; i++) {
        s += aa.top(); d.push(-aa.top()); aa.pop();
    }
    for (int i = 0; i < y; i++) {
        s += bb.top(); d.push(-bb.top()); bb.pop();
    }

    while (!cc.empty() && !d.empty() && -d.top() < cc.top()) {
        s += (cc.top() + d.top());
        cc.pop(); d.pop();
    }
    cout << s;
}


Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	cin >> s;
	vc v;
	REP(i, s.size())
	{
		c = s[i];
		v.push_back(c);
	}
	sort(ALL(v));
	REP(i, v.size() - 1)
	{
		if (v[i] == v[i + 1]) {
			cout << "no" << endl;
			return 0;
		}
	}
	if (v[v.size() - 2] == v[v.size() - 1]) {
		cout << "no" << endl;
		return 0;
	} else {
		cout << "yes" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n;
int M[MAX][MAX];
int prim(){
  int u,minv,i,v;
  int d[MAX],p[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && minv>d[i] ){
        minv=d[i];
        u=i;
      }
    }
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
        if(d[v]>M[u][v]){
          d[v]=M[u][v];
          p[v]=u;
          color[v]=GRAY;
        }
      }
    }
    if(minv==INFTY)break;
    color[u]=BLACK;
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}
int main(){
  int i,j;
  int e;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INFTY:e;//                                                
     }
  }
  printf("%d\n",prim());
  return 0;
}


Measured memory_bytes: 2052
#include <iostream>

using namespace std;

int main() {
    int A,  B;
    string op;
    cin >> A >> op >> B ;

    if(op == "+"){
        cout << (A + B) << endl;
    }
    else
    {
        cout << (A - B) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

int main() {
    ll X, A, B;  cin >> X >> A >> B;

    if (B - A <= 0) print("delicious");
    else if (B - A <= X) print("safe");
    else print("dangerous");
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from operator import itemgetter

N,C = map(int, input().split())
T = 0
record = []
for _ in range(N):
    s,t,c = map(int, input().split())
    T = max(T, t)
    record.append((s,t,c))
record.sort(key=itemgetter(2,0,1))

tl = [0]*(T+1)
curr_channel = None
for r in record:
    s,t,c = r
    if curr_channel==c:
        if curr_time==s:
            tl[s] += 1
            tl[t] -= 1
        else:
            tl[s-1] += 1
            tl[t] -= 1
        curr_time = t
    else:
        tl[s-1] += 1
        tl[t] -= 1
        curr_channel = c
        curr_time = t

s = 0
res = 0
for t in tl:
    s += t
    res = max(res, s)
print(res)


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

//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define mod1 998244353
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef priority_queue <ll> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
ll min(ll a,ll b){if(a>b)return b;else return a;}
ll max(ll a,ll b){if(a>b)return a;else return b;}
const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int t;
t=1;
//cin>>t;
while(t--){
	int n,k;
	cin>>n;
	int a[n],dp[n];
  k=2;
	fo(i,n)cin>>a[i],dp[i]=10e8;
	dp[0]=0;
	fo(i,n){
		fo1(j,k){
			if(i-j>=0)dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
		}
	}
	cout<<dp[n-1];

}
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

inline string itos(int i) { stringstream ss; ss << i; return ss.str(); }

int main() {
  int n, d;
  cin >> n;
  string s = "";
  rep(i,n) { cin >> d; s += string(1,(char)('0'+d)); }
  set<string> S;
  rep(i,n) if( s[i] == '0' ) { S.insert("0"); break; }
  rep(i,n) if( s[i] != '0' ) REP(j,i,n) S.insert(s.substr(i,j-i+1));
  for(int i=0;;++i) if( !S.count(itos(i)) ) { cout << i << endl; break; }
  return 0;
}

Measured memory_bytes: 192780
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
  int N;
  string S;
  cin >> N;
  cin >> S;
  vector<int> number(S.size()+1);
  int cnt = 0;
  for (int i = 0; i < (int)S.size(); i++)
  {
    if(S.at(i)=='I'){
      cnt++;
      number.at(i) = cnt;
    }
    else
    {
      cnt--;
      number.at(i) = cnt;
    }
  }
  number.push_back(0);

  sort(number.begin(), number.end());
  reverse(number.begin(), number.end());
  
  // for (int i = 0; i < (int)S.size()+1; i++)
  // {
  //   cout << number.at(i) << endl;
  // }
  cout << number.at(0) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {

			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			if (a <= c && c <= b) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}


int main(){

   int n;
   cin >> n;
   int d[n];
   rep(i,n) cin >> d[i];
   ll sum = 0;
   rep(i,n-1)for(int k=i+1;k<n;k++){
      sum += d[i]*d[k];
   }
   cout << sum << endl;
   return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807
#define array(N, t) (t*)calloc(N, sizeof(t))

int main() {
  int X;
  int rating[] = {400,600,800,1000,1200,1400,1600,1800,2000};

  scanf("%d", &X);

  int ans = 8;
  rep(i, 8) {
    if (X >= rating[i]) {
      if (X < rating[i + 1]) {
        ans -= i;
        break;
      }
    }
  }

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

  return 0;
}


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

int64_t f(int64_t x, int64_t y) {
  if(x < y) {
    return f(y, x);
  }
  else if(x % y == 0) {
    return y;
  }
  else {
    return f(y, x % y);
  }
}

int main() {
  int64_t A, B;
  cin >> A >> B;
  int64_t gcd = f(A, B);
  int64_t ans = 1;
  int64_t limit = gcd;
  for(int64_t i = 2; i * i <= limit; i++) {
    if(gcd % i == 0) {
      ans++;
    }
    while(gcd % i == 0) {
      gcd /= i;
    }
  }
  if(gcd != 1) {
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long d = in.nextLong();
        long t = in.nextLong();
        long s = in.nextLong();
        long covered = s * t;
        System.out.println(covered >= d ? "Yes" : "No");
        in.close();
    }
}

Measured memory_bytes: 27036
A = []
b = []

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

for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    b.append(int(input()))

for i in range(n):
    print(sum([x*y for x,y in zip(A[i],b)]))

Measured memory_bytes: 8028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
#define vec(n) vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll V=1000000007;

int main() {
  int A,B,C,K; cin>>A>>B>>C>>K;
  if(A>K)AA(K);
  if(A<=K&&K<A+B)AA(A);
  if(B+A<=K)AA(A-(K-A-B));
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;
import java.io.BufferedInputStream;
import java.lang.Math;
import java.util.*;

public class Main{
    public static void main(String [] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int N = sc.nextInt();
        int r0 = 0;
        int r2 = 0;
        int r4 = 0;
        for(int i = 0; i < N; i++) {
            int x = sc.nextInt();
            if(x % 4 == 0) {
                r4++;
            } else if (x % 2 == 0) {
                r2++;
            } else {
                r0++;
            }
        }
        if(ok(N,r0,r2,r4)){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    static boolean ok(int n,int r0,int r2,int r4) {
        if(r0 > r4 + 1) return false;
        if(r0 == r4 + 1) return (r2 == 0);
        return true;
    }
}


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

using namespace std;

#define int long long

map<int, bool> mp1, mp2;

void divisorFirst(int n){
	while(n%2 == 0){
		mp1[2] = true;
		n/=2;
	}
	for(int i = 3; i*i <= n; i+=2){
		while(n%i == 0){
			mp1[i] = true;
			n/=i;
		}
	}
	if(n > 2) mp1[n] = true;
}

void divisorSecond(int n){
	while(n%2 == 0){
		mp2[2] == true;
		n/=2;
	}
	for(int i = 3; i*i <= n; i+=2){
		while(n%i == 0){
			mp2[i] = true;
			n/=i;
		}
	}
	if(n > 2) mp2[n] = true;
}

int findDivisor(int A, int B){
	int cnt = 1;
	divisorFirst(A);
	divisorSecond(B);
	map<int, int >mp;
	
	for(auto it : mp1) mp[it.first]++;
	
	
	for(auto it : mp2) mp[it.first]++;

	for(auto it : mp){
		if(it.second == 2) cnt++;
	}
	return cnt;
}


signed main(){
	int A, B; cin>>A>>B;
	cout<<findDivisor(A, B)<<"\n";
	return 0;
}

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

int main(){
    long long K, N;
    cin >> K >> N;
    long long i;
    long long A[N+1];
    for(i = 1; i <= N; i++){
        cin >> A[i];
    }

    long long i_memo;
    long long MAXkyori = 0;
    for(i = 2; i <= N; i++){
        if(MAXkyori < A[i]-A[i-1]){
            i_memo = i;
            MAXkyori = A[i]-A[i-1];
        }
    }
    if(MAXkyori < K-A[N] + A[1]){
        i_memo = 1;
        MAXkyori = K-A[N] + A[1];
    }

    cout << K-MAXkyori << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll long_;
    ll flag = false; 
    sort(a.begin(), a.end(), greater<>());
    rep(i, n - 3){
        if(a[i] == a[i + 3] and !(flag)){
            cout << a[i] * a[i] << endl;
            return 0;
        }
        if(a[i] == a[i + 1] and a[i] != a[i + 3] and !(flag)){
            long_ = a[i];
            flag = true;
            i++;
        }else if(a[i] == a[i + 1] and a[i] != a[i + 3] and (flag)){
            cout << a[i] * long_ << endl;
            return 0;
        }
    }
    if(a[n - 2] == a[n - 1] and (flag)){
        cout << long_ * a[n - 1] << endl;
        return 0;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 1024
function main(arg) {
    let n = Number(arg.split("\n")[0])
    let a = arg.split("\n")[1].split(" ").map(Number)
    
    let dp = []
    for(let i=0; i<n+1; i++)dp[i]=0
    dp[0] = 1000
    
    let stock = 0
    for(let i=1; i<n+1; i++) {
        if(i==n) {
        // 売却
            dp[i] = dp[i-1] + stock*a[i-1]
        }else if(a[i]>a[i-1]) {
        // 購入
            let addStock = parseInt(dp[i-1]/a[i-1])
            dp[i] = dp[i-1] - addStock * a[i-1]
            stock += addStock
            //console.log(`addStock=${addStock}`)
        } else {
        // 売却
            let rmStock = stock
            dp[i] = dp[i-1] + rmStock * a[i-1]
            stock -= rmStock
            //console.log(`rmStock=${rmStock}`)
        }
            //console.log(`stock=${stock}`)
    }
    console.log(dp[n])
    

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29864
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;cin>>n;
  int i,j,k;
  vector<int> v;
  for(i=0;i<n;i++){
    cin >> k;
    v.push_back(k);
  }
  for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  for(i=1;i<n;i++){
    for(j=0;j<i;j++){
      if(v[j]>v[i]){
	      k=v[i];
        v.erase(v.begin()+i);
        v.insert(v.begin()+j,k);
	      break;
      }
    }
    for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin >> n >> k;
	int arr[n];
	for(int i=0;i<n;i++)cin >> arr[i];
	vector<int>dp(n,INT_MAX);
	dp[0]=0;
	
	for(int i=1;i<n;i++){
	for(int j=i-1;j>=max(i-k,0);j--){
	dp[i]=min(dp[i],dp[j]+abs(arr[j]-arr[i]));
	}
	//cout << dp[i] << " ";
	}
	//cout << endl;
	cout << dp[n-1];
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()

	r, _ := strconv.Atoi(stdin.Text())
	var round float64
	rf := float64(r)
	round = 2 * math.Pi * rf
	fmt.Println(round)
}


Measured memory_bytes: 1752
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CAntiDivision {
        long gcd(long a, long b) {
            if (b == 0)
                return a;
            return gcd(b, a % b);
        }

        public void solve(int testNumber, InputReader s, PrintWriter w) {
            long a = s.nextLong(), b = s.nextLong(), c = s.nextLong(), d = s.nextLong();
            long divC = b / c - (a - 1) / c;
            long divD = b / d - (a - 1) / d;
            long lcm = c * d / gcd(c, d);
            long divCD = b / lcm - (a - 1) / lcm;
            w.println(b - a + 1 - (divC + divD - divCD));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22868
#include <iostream>
#include <vector>
#define int long long
#define MOD 1000000007
using namespace std;

int mod_inv(int X){
	int a = X, b = MOD, u = 1, v = 0;
	while(b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if(u < 0) u += MOD;
	return u;
}

vector<int> fact,factinv;

void nCr_init(int N){
	N = min(N,(int)MOD);
	fact.resize(N + 1);
	factinv.resize(N + 1);
	fact[0] = 1;
	for(int i = 1;i <= N;i++) fact[i] = fact[i - 1] * i % MOD;
	factinv[N] = mod_inv(fact[N]);
	for(int i = N;i >= 1;i--) factinv[i - 1] = factinv[i] * i % MOD;
}

int nCr(int ncr_n,int ncr_r){
	if(ncr_n >= MOD) return nCr(ncr_n % MOD, ncr_r % MOD) * nCr(ncr_n / MOD, ncr_r / MOD) % MOD;
	return ncr_r > ncr_n ? 0 : fact[ncr_n] * factinv[ncr_n - ncr_r] % MOD * factinv[ncr_r] % MOD;
}

signed main(){
	int h,w,a,b,ans;
	nCr_init(200010);
	cin >> h >> w >> a >> b;
	ans = nCr(h + w - 2,h - 1);
	for(int i = h - a;i < h;i++){
		ans = (ans - nCr(i + b - 1,i) * nCr(h - i - 2 + w - b,h - i - 1) % MOD + MOD) % MOD; 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#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() {
  string s,t; cin>>s>>t;
  if(s == t.substr(0,s.size())){
    if(t.size() == s.size()+1){
      cout << "Yes" << endl;
    }
  }
  else cout << "No" << endl;
}


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

int main() {
  int a, b, mod;
  cin >> a >> b;
  mod = (a * b) % 2;
  if (mod == 1){
   cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }
}

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

void solve() {
	string x,y;
	cin>>x>>y;
	int Ans = 0;
	for(int i=0,j=0;i<(int)x.length();i++,j++){
		if(x[i]!=y[j]){
			Ans++;
		}
	}
	cout<<Ans<<"\n";
}

int main()
{
    //freopen("in.txt","r",stdin);
    //int tc;cin>>tc;
    //while(tc--)
	solve();
    return 0; 
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vec< vec< int > > g;
vec< int > r;
int N, M, R;
int dfs(int id, vec< bool > &flg, int depth) {
  flg[id] = true;

  if (depth != R - 1) {
    int val = INF;
    REP(i, R) {
      if (!flg[i]) {
        vec< bool > newflg(flg);
        int tmpval = g[r[id]][r[i]] + dfs(i, newflg, depth + 1);
        chmin(val, tmpval);
      }
    }
    return val;
  } else {

    return 0;
  }
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> N >> M >> R;
  r.resize(R);
  REP(i, R) {
    cin >> r[i];
    r[i]--;
  }
  g.resize(N, vec< int >(N, INF));
  REP(i, M) {
    int a0, a1, a2;
    cin >> a0 >> a1 >> a2;
    a0--, a1--;
    g[a0][a1] = a2;
    g[a1][a0] = a2;
  }
  // REP(i, N) { PRINTALL(g[i]); }
  REP(k, N) {
    REP(i, N) {
      REP(j, N) { chmin(g[i][j], g[i][k] + g[k][j]); }
    }
  }
  // REP(i, N) { PRINTALL(g[i]); }
  int ans = INF;
  REP(i, R) {
    vec< bool > visited(R, false);
    int tmpans = dfs(i, visited, 0);
    chmin(ans, tmpans);
  }
  print(ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
	ll n; cin >> n; P a[n]; ll s[n]; fill(s, s+n, 1);
	for(int i=0; i<n; i++) {cin >> a[i].first; a[i].second=i+1;}
	sort(a, a+n, greater<P>()); vector<P> v;
	bool ok = true; ll ss[n]; fill(ss, ss+n, 0);

	for(int i=0; i<n-1 && ok; i++) {
		ll p = a[i].first - n + 2 * s[i];
		if (n - 2 * s[i] <= 0) ok = false;
		ll x = lower_bound(a+i+1, a+n, make_pair(p, 0), greater<P>()) - a-1 ;
		//if (x == n) ok = false;
		if (a[x].first != p) ok = false;
		s[x] += s[i]; ss[x] += ss[i] + s[i];
		ll v1 = min(a[x].second, a[i].second);
		ll v2 = max(a[x].second, a[i].second);
		v.push_back(make_pair(v1, v2));
		//cout << i << " " << x << " " << p << " " << s[x] << " " << ok << " " << a[x].first << endl;
	}
	if (ss[n-1] != a[n-1].first) ok = false;
	if (ok == false) {cout << -1 << endl; return 0;}
	sort(v.begin(), v.end());
	for(P y:v){
		cout << y.first << " " << y.second << endl;
	}
}

Measured memory_bytes: 6256
import math

S = input()

h1 = math.ceil(len(S)/2)
h2 = math.floor(len(S)/2)

s1 = S[:h1]
s2 = S[h2:][::-1]

count = 0
for i in range(len(s1)):
	if s1[i] != s2[i]:
		count += 1
		
print(count)

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

if  N % 2 == 0:
    M =  N // 2
    even_A = [A[i* 2] for i in range(M)]
    odd_A = [A[i* 2 + 1] for i in range(M)]
    even_sum = []
    _sum = 0
    for a in even_A:
        _sum += a
        even_sum.append(_sum)
    odd_sum = []
    _sum = 0
    for a in odd_A:
        _sum += a
        odd_sum.append(_sum)
    ans = max(odd_sum[-1], even_sum[-1])
    for i in range(M):
            x = even_sum[i] + odd_sum[-1] - odd_sum[i]
            ans = max(ans, x)
    print(ans)
    exit()
M =  N // 2
# evenが元一つ多い
even_A = [A[i* 2] for i in range(M+1)]
odd_A = [A[i* 2 + 1] for i in range(M)]
even_sum = []
_sum = 0
for a in even_A:
    _sum += a
    even_sum.append(_sum)
odd_sum = []
_sum = 0
for a in odd_A:
    _sum += a
    odd_sum.append(_sum)
# 全て奇数
all_even = even_sum[-1] - min(even_A)
diff_odd_even = [odd_sum[k] - even_sum[k+1] for k in range(M)]
diff_max_odd_even = []
diff_max = diff_odd_even[-1]
for k in range(M):
    diff_max = max(diff_max, diff_odd_even[-k-1])
    diff_max_odd_even.append(diff_max)
diff_max_odd_even.reverse()

ans = all_even
for i in range(M):
        x = even_sum[i] + odd_sum[-1] - odd_sum[i]
        y = odd_sum[i] + even_sum[-1] - even_sum[i+1]
        z = even_sum[i] + - odd_sum[i] + even_sum[-1] + diff_max_odd_even[i]
        ans = max(ans, x, y, z)
print(ans)



Measured memory_bytes: 113220
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  =1e6+1 , limit = 1e17 , mod=1e9+7;
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}
int32_t main(){
    boost;
        
    int n;    
    int k;
    cin>>n>>k;
    
    int dp[k+1];
    
    for(int i=1;i<=k ; i++ ){
        int v1 = k/i;
        dp[i] = pow(v1,n,mod);
    }
    
    
    for(int i = k ; i >=2 ; i-- ){
        
        for(int p = 1 ; p*p  <=  i ; p++  ){
            
            if(i%p ==0 ){
                
                    dp[p] = dp[p] - dp[i] ;
                    while(dp[p] <0)dp[p]+=mod;
                    
                    
                    dp[p]=dp[p]%mod;
            
                int cp = i/p;
                if(cp!=p && p!=1){
                    
                     dp[cp] = dp[cp] - dp[i];
                    
                     while(dp[cp] <0)dp[cp]+=mod;
                    
                    
                    dp[cp]=dp[cp]%mod;
                }
                
                
            }
            
        }
        
        
    }
    
    int res =0 ;
    for(int i =1 ;i<=k ;i++ ){
        // cout<<dp[i]<<" ";
        res = res + (dp[i]*i)%mod;
        res = res%mod;
    }
    cout<<res<<endl;
        
    
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
uint64_t negabinary(int64_t num) {
    const uint64_t mask = 0xAAAAAAAAAAAAAAAA;
    return (mask + num) ^ mask;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<ll>v;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            for(int k=1;k<=9;k++){
                if(i+j+k>9)continue;
                string s=string(i,'3')+string(j,'5')+string(k,'7');
                do{
                    stringstream ss(s);
                    ll n=0;
                    ss>>n;
                    v.push_back(n);
                }while(next_permutation(s.begin(),s.end()));
            }
        }
    }
    sort(v.begin(),v.end(),[&](ll x,ll y){return x<y;});
    ll n;
    cin>>n;
    int cnt=0;
    for(auto x: v){
        if(x>n)break;
        cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n],ans=n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int up=0,down=0;
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			ans--;
		}else if(a[i]<a[i+1]){
			up++;
			if(down!=0){
				up=0;
				down=0;
			}else{
				ans--;
			}
		}else{
			down++;
			if(up!=0){
				up=0;
				down=0;
			}else{
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int K, A, B;
    cin >> K >> A >> B;

    int ans = K + 1;
    if (A < B) {
        K -= A - 1;
        K -= 2;
        if (K >= 0) {
            int tmp = B + (K / 2) * (B - A) + (K % 2);
            chmax(ans, tmp);
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b,mx=0;
    cin>>a>>b;
    mx=max(a+b,mx);
    mx=max(a+a-1,mx);
    mx=max(b+b-1,mx);
    cout<<mx<<endl;


    return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;


int main() {

	int n;
	cin >> n;
	VI a(n);
	REP(i, n)cin >> a[i];

	sort(ALL(a));

	REP(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 1024
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
ans='U'*dy+'R'*dx+'D'*dy+'L'*dx+'L'+'U'*(dy+1)+'R'*(dx+1)+'D'+'R'+'D'*(dy+1)+'L'*(dx+1)+'U'
print(ans)

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536870912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// bit: &/and, |/or, ^/xor, ~/not

#define	MOD 1000000007

const double PI=3.14159265358979323846;

int	main() {
	long double a, b, x;
	cin >>a >>b >>x;
	//long double t=atanl((b-(x/a/a))/a*2.0);
	long double t=atanl((b*a*a-x)*2.0/(a*a*a));
	if (x/a/a*2.0<b)
		//t=atanl(b*b/2.0/x*a);
		t=atanl(b*b*a/(x*2.0));
	cout <<fixed;
	cout <<setprecision(10) <<t/PI*180.0 <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n,m,x; cin >> n >> m >> x;
    ll c[n], a[n][m];
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    ll ans = LONG_MAX;
    for(int i = 1; i < pow(2,n); i++){

        ll s[m], cost = 0;
        for(int j = 0; j < m; j++) s[j] = 0;

        for(int j = 0; j < n; j++){
            if(i & (1<<j)){
                cost += c[j];
                for(int k = 0; k < m; k++){
                    s[k] += a[j][k];
                }
            }
        }

        bool f = true;
        for(int j = 0; j < m; j++){
            if(s[j] < x) {f = false; break;}
        }
        if(!f) continue;
        ans = min(ans, cost);
    }

    if(ans != LONG_MAX) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 4100
import numpy as np
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)


Measured memory_bytes: 48780
#include<iostream>

using namespace std;

int main(){

	int n;
	cin >> n;
	bool test = false;
	
	while( n-- ) {
		
		int A[10] = {0};
		int B[10] = {0};
	
		int j = 0, k = 0;
		int a;
		
		for(int i=0;i<10;i++) {
			
			cin >> a;
			
			if( a > A[j] ) {
				
				A[j] = a;
				A[j+1] = a;
				j++;
				
			}
			else {
				if( a > B[k]) {
					
					B[k] = a;
					B[k+1] = a;
					k++;
					
				}
			}
		}
		if ( j + k == 10)
			cout << "YES\n";
		else
			cout << "NO\n"; 
		
	}
	
    return 0;
}


Measured memory_bytes: 2876
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional;

void main() {
  auto S = readln.chomp;

  if(S == "Sunny") {
    "Cloudy".writeln;
  } else if (S=="Cloudy") {
    "Rainy".writeln;
  } else if(S=="Rainy") {
    "Sunny".writeln;
  }
}


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

int main() {
	int n, w; cin >> n >> w;
	vector<int>wg(n), vl(n);
	for (int i = 0; i < n; i++) {
		cin >> wg[i] >> vl[i];
	}
	long long x = wg[0];
	for (auto&& xx : wg) {
		xx -= x;
	}
	vector<vector<vector<long long>>>dp(n + 1, vector<vector<long long>>(200, vector<long long>(n + 1, 0)));
	for (int i = 0; i < n; i++)for (int j = 0; j < 200; j++)for (int k = 0; k < i + 1; k++) {
		dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
		if (j >= wg[i]) {
			dp[i + 1][j][k + 1] = max(dp[i + 1][j][k + 1], dp[i][j - wg[i]][k] + vl[i]);
		}
	}
	long long ans = 0;
	for (int i = 0; i < 200; i++)for (int j = 0; j < n + 1; j++) {		
		if (i + j * x <= w) {
			ans = max(ans, dp[n][i][j]);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 17024