akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int maxn = 1e5 + 4;
long long n, k, dp[maxn], arr[maxn];

long long solve(int indx)
{
    if(indx >= n)
        return 1e17;
    if(indx == n - 1)
        return 0;
    if(dp[indx] != -1)
        return dp[indx];
    long long aux = 1e17,ans = INT_MAX;
    for(int i = 1; i <= k; i++)
    {
        aux = solve(indx + i) + abs(arr[indx] - arr[indx + i]);
        if(aux < 1e13)
        {
            ans = min(ans,aux);
        }
    }
    return dp[indx] = ans;
}

int main()
{
    IO;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 6528
n = int(input())
h = list(map(int, input().split()))
ans = 0
now = 0
for i in range(len(h)):
    now += 1
    if i == len(h)-1:
        if now > ans:
            ans = now
        now =0
        break
    if h[i] < h[i+1]:
        if now > ans:
            ans = now
        now = 0
print(ans-1)


Measured memory_bytes: 15020
//#include <bits/stdint.h>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/
int main() {
    string s;
    cin >> s;
    REP(i, s.size()){
      if(s[i]=='?') s[i]='D';
    }
    cout << s << endl;
    }

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;
bool sr(int a, int b)
{
	return a > b;
}
bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(ll n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}
bool ssign(int a,int b){
	if(a>0&&b>0){
		return true;
	}else if(a<0&&b<0){
		return true;
	}else{
		return false;
	}
}
bool larger(int a,int b){
	if(a<b){
		return true;
	}else{
		return false;
	}
}
int main()
{
	string s;
	cin>>s;
	int tc_g=0,tc_p=0;
	int ac_g=0,ac_p=0,win=0,lose=0;
	int n=s.size();
	rep(i,n){
		if(s[i]=='g'){
			tc_g++;
			if(ac_p<ac_g){
				ac_p++;
				win++;
			}else{
				ac_g++;
			}
		}else{
			tc_p++;
			if(ac_p<ac_g){
				ac_p++;
			}else{
				ac_g++;
				lose++;
			}
		}
		
	}
	cout<<win-lose<<endl;

}

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

int main(){
	long a,b;
	cin >> a >> b;
	if (a==b){
		cout << "Draw" << endl;
	}else if (a==1){
		cout << "Alice" << endl;
	}else if (b==1) {
		cout << "Bob" << endl;
	}else if (a<b){
		cout << "Bob" << endl;
	}else if (a>b){
		cout<< "Alice" << endl;
	}
	
	return 0;
}

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

int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if (a==0) {
    cout << 1 << endl;
  }
   if (b==0) {
    cout << 2 << endl;
  }
   if (c==0) {
    cout << 3 << endl;
  }
   if (d==0) {
    cout << 4 << endl;
  }
   if (e==0) {
    cout << 5 << endl;
  }
}


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

from collections import defaultdict
dp = [defaultdict(lambda: 0) for _ in range(N+1)]
dp[0][0] = 1
for i,x in enumerate(X):
    for j in range(i,-1,-1):
        for k,v in dp[j].items():
            dp[j+1][k+x] += v

ans = 0
for i in range(1,N+1):
    ans += dp[i][i*A]
print(ans)

Measured memory_bytes: 11296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll mod = 1e9+7;
ll INF = 1e17;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
/*ll power(ll a,ll b,ll p)
{
	ll res=1;
	a%=p;
	while(b>0)
	{
		if(b&1)
		res=res*a%p;
		a=a*a%p;
		b>>=1;
	}
	return(res);
}*/
/*void dfs(ll x)
{
	vis[x]=true;
	for(ll i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==false)
		dfs(v[x][i]);
	}
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
	ll l=0,r=n-1;
	while(l<=r)
	{
		ll mid=l+(r-l)/2;
		if(arr[mid]==s)
		return(mid);
		if(arr[mid]<s)
		l=mid+1;
		else
		r=mid-1;
	}
	return(-1);
}*/
 
void solve()
{
	ll k;
	cin>>k;
	set<ll> s;
	for(ll i=1;i<=9;i++)
	s.insert(i);
	if(k<=9)
	{
		cout<<k<<endl;
		return;
	}
	set<ll> :: iterator it;
	k-=9;
	while(k)
	{
		it=s.begin();
		s.erase(it);
		ll c=(*it)%10;
		ll c1=(*it);
		//cout<<c1<<endl;
		if(c==0)
		{
			k--;
			if(k>0)
			s.insert((c1)*10+0);
			else
			{
				cout<<(c1)*10+0<<endl;
				return;
			}
			k--;
			if(k>0)
			s.insert((c1)*10+1);
			else
			{
				cout<<(c1)*10+1<<endl;
				return;
			}
		}
		else if(c==9)
		{
			k--;
			if(k>0)
			s.insert(c1*10+8);
			else
			{cout<<c1*10+8<<endl;
			return;}
			k--;
			if(k>0)
			s.insert(c1*10+9);
			else
			{
				cout<<c1*10+9<<endl;
				return;
			}
		}
		else
		{
			k--;
			if(k>0)
			{
				s.insert(c1*10+c-1);
			}
			else
			{
				cout<<c1*10+c-1<<endl;
				return;
			}
			//cout<<c1*10+c-1<<endl;
			k--;
			if(k>0)
			{
				s.insert(c1*10+c);
			}
			else
			{
				cout<<c1*10+c<<endl;
				return;
			}
			//cout<<c1*10+c<<endl;
			k--;
			if(k>0)
			{
				s.insert(c1*10+c+1);
			}
			else
			{
				cout<<c1*10+c+1<<endl;
				return;
			}
			//cout<<c1*10+c+1<<endl;	
		}
	}
	
}
 
int main()
{
	IOS
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
    return(0);
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b,c;
  cin>>a>>b>>c;
  c-=min(c,a-b);
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;cin>>A>>B;
  string S;cin>>S;int flag=0;
  for(int i=0;i<A;i++)
    if(S.at(i)=='-')flag++;
  if(S.at(A)!='-')flag++;
  for(int i=A+1;i<A+B+1;i++)
    if(S.at(i)=='-')flag++;
  if(flag==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_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) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) 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, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  string S;
  cin >> N >> S;
  rep(i, 0, sz(S)) { S[i] = (S[i] - 'A' + N) % 26 + 'A'; }
  cout << S << endl;
  return (0 ^ _ ^ 0);
}



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

int main(void){
  int N,i=0;
  scanf("%d",&N);
  char* s;
  s = (char *)malloc((N+1) * sizeof(char));
  for(i = 0; i < N; i++) {
    scanf(" %c", &s[i]);
  }
  s[N] = '\0';
  int p=0,w=0,g=0,y=0;
  for(i=0;i<N;i++){
    if(s[i] == 'P'){
      p=1;
    }else if(s[i] == 'W'){
      w=1;
    }else if(s[i] == 'G'){
      g=1;
    }else if(s[i] == 'Y'){
      y=1;
    }
    if(p==1&&w==1&&g==1&y==1){
      printf("Four\n");
      fflush(stdout);
      return 0;
    }
  }
  printf("Three\n");
  fflush(stdout);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	int t=1;
	//cin>>t;
	
	while(t--)
	{
		int n;
		cin>>n;
		
		int *a=new int[n];
		int *b=new int[n];
		int *c=new int[n];
		
		for(int i=0;i<n;i++)
		{
			cin>>a[i]>>b[i]>>c[i];
		}
		
		int **dp=new int*[n];
		for(int i=0;i<n;i++)
		{
			dp[i]=new int[3];
		}
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<3;j++)
			{
				dp[i][j]=3;
			}
		}
		
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(i==0)
				{
					if(j==0)dp[i][j]=a[i];
					else if(j==1)dp[i][j]=b[i];
					else dp[i][j]=c[i];
				}else
				{
					for(int k=0;k<3;k++)
					{
						if(j==k)continue;
						if(j==0)
						{
							dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i]);	
						}
						else if(j==1)
						{
							dp[i][j]=max(dp[i][j],dp[i-1][k]+b[i]);
						}
						else
						{
							dp[i][j]=max(dp[i][j],dp[i-1][k]+c[i]);
						} 
					}
				}
			}
		}
		cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 8656
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1e18


void solve()
{
   string a,b;
   cin>>a>>b;
   int SIZE=b.size();
   a+=b[SIZE-1];
   if(a==b) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

int main()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //sieve();
    //int cnt=1;
    //int t; cin>>t; while(t--) solve();
    solve();
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    int a=N%10;
    if(a==2 || a==4 || a==5 || a==7 || a==9) {cout << "hon" << endl;}
    else if(a==3) {cout << "bon" << endl;}
    else {cout << "pon" << endl;}
    return 0;
}

Measured memory_bytes: 3572
a[100],v,j,k,n;main(i){scanf("%d",&n);for(;j<n;scanf("%d",&a[j++]));for(;k<n-1;){printf("%d ",a[k++]);}printf("%d\n",a[n-1]);for(;i<n;i++){v=a[i];j=i-1;for(;j+1&&a[j]>v;a[j+1]=a[j--]);a[j+1]=v;for(k=0;k<n-1;printf("%d ",a[k++]));printf("%d\n",a[n-1]);}exit(0);}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int digit(ll a,ll b)
{
  ll c=0,d=0;
  while(a>0)
  {
    c+=1;
    a/=10;
  }
  while(b>0)
  {
    d+=1;
    b/=10;
  }
  if(c>d)
    return c;
  else
    return d;
}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n;
    int mn=INT_MAX;
    cin>>n;
    vi v;
    for(int i=1;i<=sqrt(n);i++)
    {
      if(n%i==0)
      {
        
          v.pb(n/i);
          v.pb(i);
        
      }
    }
    v()
     
  for(int i=0;i<v.size();i++)
  {
    for(int j=i+1;j<v.size();j++)
    {  
      if(v[i]*v[j]==n)
      {
        int temp=digit(v[i],v[j]);
         mn=min(temp,mn);
    }
  }
  }
  cout<<mn<<endl;


}
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,m,s;
  char a[9],b[9];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",a,b);
    m=1;
    s=0;
    for(j=0;a[j]!=0;j++){
      if('0'<=a[j]&&a[j]<='9'){
	m=a[j++]-'0';
      }
      if(a[j]=='m')m*=1000;
      else if(a[j]=='c')m*=100;
      else if(a[j]=='x')m*=10;
      s+=m;
      m=1;
    }//printf("%d ",s);
    for(j=0;b[j]!=0;j++){
      if('0'<=b[j]&&b[j]<='9'){
	m=b[j++]-'0';
      }
      if(b[j]=='m')m*=1000;
      else if(b[j]=='c')m*=100;
      else if(b[j]=='x')m*=10;
      s+=m;
      m=1;
    }//printf("%d\n",s);
    if(s/1000>1)printf("%d",s/1000);
    if(s/1000)printf("m");
    s%=1000;
    if(s/100>1)printf("%d",s/100);
    if(s/100)printf("c");
    s%=100;
    if(s/10>1)printf("%d",s/10);
    if(s/10)printf("x");
    s%=10;
    if(s>1)printf("%d",s);
    if(s)printf("i");
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#include<iostream>
#define N 100001
#define LL long long int
using namespace std;
LL GCD(LL a,LL b)
{
	LL t;
	if(b>a)
	{
		t=a;
		a=b;
		b=t;
	}
	if(b==0)
		return a;
	return(GCD(b,a%b));
}
int main()
{
	LL a,b;
	cin>>a>>b;
	cout<<b*(a/GCD(a,b))<<endl;
	return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;
    ll cnt = 0;
    rep(i, n){
        ll in;
        cin >> in;
        if(i+1 != in){
            cnt++;
        }
    }

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

    return 0;
}

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

int main(void){
	while(1){
		string s;
		getline(cin,s);
		if(cin.eof()) break;
		stringstream ss(s);
		vector<double> stk;
		while(1){
			if(ss.eof()) break;
			string n;
			ss >> n;
			if(n.size()==1&&!isdigit(n[0])){
				double b=stk.back();
				stk.pop_back();
				double a=stk.back();
				stk.pop_back();
				switch(n[0]){
					case '+':
						stk.push_back(a+b);
						break;
					case '-':
						stk.push_back(a-b);
						break;
					case '*':
						stk.push_back(a*b);
						break;
					case '/':
						stk.push_back(a/b);
						break;
				}
			}else{
				int num=stoi(n);
				stk.push_back(1.0*num);
			}
			//for(auto &i:stk) cout << i << endl;
		}
		cout.precision(10);
		cout << fixed << stk[0] << endl;
	}
	return 0;
}

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

int n,k,q;
int a[2005];
vector<P> vi;
bool flag[2005];

int main(void){
	scanf("%d%d%d",&n,&k,&q);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		vi.push_back(P(a[i],i));
	}
	sort(vi.begin(),vi.end());
	int ans=INF;
	for(int i=0;i<n;i++){
		memset(flag,false,sizeof(flag));
		for(int j=0;j<n;j++){
			if(a[j]<vi[i].first){
				flag[j]=true;
			}
		}
		bool used=false;
		priority_queue<P,vector<P>,greater<P> > que;
		priority_queue<int,vector<int>,greater<int> > que2;
		for(int j=0;j<n;j++){
			if(flag[j]){
				while(que.size()>k-1){
					P v=que.top();
					que.pop();
					if(v.second==-1)used=true;
					que2.push(v.first);
				}
				while(que.size()){
					que.pop();
				}
			}else{
				if(j==vi[i].second){
					que.push(P(a[j],-1));
				}else{
					que.push(P(a[j],j));
				}
			}
		}
		while(que.size()>k-1){
			P v=que.top();
			que.pop();
			if(v.second==-1)used=true;
			que2.push(v.first);
		}
		//printf("%d\n",que2.size());
		if(used && que2.size()>=q){
			int bi=0;
			for(int j=0;j<q;j++){
				bi=que2.top();
				que2.pop();
			}
			ans=min(ans,bi-vi[i].first);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    int a,b,k;
    cin>>a>>b>>k;
    vector<int> dev;
    for(int i=1;i<=a;i++){
        if(a%i==0 and b%i==0){
            dev.push_back(i);
        }
    }
    cout<<dev.at(dev.size()-k)<<endl;
}


Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
using namespace std;
 
using ll = long long;

ll dfs(int v, vector<vector<int>>& g, vector<ll> const& A, int prev) {
    vector<ll> child(g[v].size());
    if(prev != -1 && g[v].size() == 1) {
        return A[v];
    }
    ll sum = 0, ma = -1;
    for(int i=0; i<g[v].size(); ++i) {
        if(g[v][i] == prev) {
            continue;
        }
        child[i] = dfs(g[v][i], g, A, v);
        if(child[i] == -1) {
            return -1;
        }
        sum += child[i];
        ma = max(ma, child[i]);
    }
    ll up = 2*A[v] - sum;
    ll p_cnt = (sum - up) / 2;
    //cout << "v: " << v << " up: " << up << " p_cnt: " << p_cnt << endl;
    if(up > sum || up < 0 || p_cnt * 2 != sum - up || p_cnt > sum - ma) {
        return -1;
    }
    return up;
}
 
int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; ++i) {
        cin >> A[i];
    }
    vector<vector<int>> g(N);
    for(int i=0; i<N-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if(N == 2) {
        if(A[0] == A[1]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
        return 0;
    }
    for(int i=0; i<N; ++i) {
        if(g[i].size() != 1) {
            if(dfs(i, g, A, -1) != 0) {
                cout << "NO" << endl;
            } else {
                cout << "YES" << endl;
            }
            return 0;
        }
    }
}


Measured memory_bytes: 18560
#include <stdio.h>
int main()
{
    char s[256], r[256],r_1[256],r_2[256];
    int i, n, hantei;

    //文字列の入力
    scanf("%s", s);

    //文字数を数える
    for(i=0; s[i] != 0x00; i++);
    n = i;
    

    //rにsの最後の文字から逆に代入
    for(i=0; i<n; i++){
      r[i] = s[n-1-i];
      //printf("%c",r[i]);
    }
    //printf("\n");
    for(i=0; i<(n-1)/2; i++){
      r_1[i] = s[(n-1)/2-i-1];
      //printf("%c",r_1[i]);
    }
    printf("\n");
    for(i=(n+1)/2; i <n+1; i++){
      r_2[i] = s[n-i +(n-1)/2];
      //printf("%c",r_2[i]);
    }
    //printf("\n");
    r_2[n] = 0;
    r_1[n/2] = 0;
    //最後に文字列の終わりのマークを代入
    r[n] = 0;

  

    //回文判定用変数の初期化
    hantei = 0;

    //sとrが同じかどうか、各要素を比較
    for(i=0; i<n-1; i++){
      //printf("A%c%c\n",s[i],r[i]);
        if(s[i] != r[i]) {
          hantei++;}
    }
    
    for(i = 0;i < n/2;i++){
      //printf("B%c%c\n",s[i],r_1[i]);
        if(s[i] != r_1[i]) {    
          hantei++;}
    }

    
    for(i = (n+2)/2;i<n;i++){
     // printf("C%c%c\n",s[i],r_2[i]);
        if(s[i] != r_2[i]) {
          
          hantei++;}
    }
    

    //判定結果の表示
    if(hantei){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    unsigned long int a = 0, b = 0, x = 0, y = 0, min = 0, max = 0, ans = 0;
    bool flag = false;
    
    cin >> a >> b;
    x = a / 0.08;
    y = b / 0.1;
    if(x < y){
        min = x;
        max = y;
    }else{
        min = y;
        max = x;
    }
    for(int i = min - 1 ; i <= max + 1 ; i++){
        if(int(i * 0.08) == a && int(i * 0.1) == b){
            ans = i;
            flag = true;
            break;
        }
    }
    if(flag){
        cout << ans << endl;   
    }else{
        cout << -1 << endl;
    }
    return 0;
}

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

int a[300], b[300];

void re(){
	for(int i = 0;i<300;i++){
		a[i] = 100;
	}
}


void res(){
	for (int i = 0; i<300; i++) {
		b[i] = 0;
	}
}
int main(){
	int k;
	string input, ans;
	while(cin >> k){
		re();
		for(int i = 0;i<k;i++){
			cin >> input;
			res();
			for(int j = 0;j<input.size();j++){
				int v = input[j];
				b[v]++;
			}
			for (int z = 0; z<300; z++) {
				if (a[z] > b[z])a[z] = b[z];
			}
		}
		ans = "";
		for (int i = 97; i<300; i++) {
			if(a[i] != 0){
				for(int j = 0;j<a[i];j++){
					ans += i;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int n,ans,last;
    cin >> n;
    int A[n],B[n],C[n-1];
    REP(i,n)cin >> A[i];
    REP(i,n)cin >> B[i];
    REP(i,n-1)cin >> C[i];
    ans = 0;
    last = -1;
    REP(i,n){
        if((last+1)==A[i]){
            ans += C[A[i]-2];
        }
        REP(j,n){
            if ((j+1) == A[i]){
                ans += B[j];
                last = j+1;
            } 
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define N  99999
#define f first 
#define em emplace
#define s second
using lint=long long int;

typedef pair<lint, lint> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

 
#define fori(n) for(int i=0; i<int(n); i++)
 
#define cins(s) string s; cin>>s;
#define cini(i) lint i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }
#define z 1000000007 


void solve(){
  
   cini(n); cini(w);
  lint arr[n+1][w+1];
  memset(arr,0,sizeof(arr));
   
   vector<pii> v(n+1);

   for(int i=1;i<=n;i++)
   {  
          cini(a); cini(b);
           v[i]={a,b};

   }
  
   sort(v.begin()+1,v.end());

    
     for(lint i=1;i<=n;i++){
       for(lint j=1;j<=w;j++){
         if(j-v[i].f>=0)
        arr[i][j]= max(arr[i-1][j],arr[i-1][j-v[i].f]+v[i].s);
         else
          arr[i][j]=arr[i-1][j];
        }
     }

     cout<<arr[n][w]<<endl;



   
    
}
 
 
int main()
{ 
  fast;
  
  



  solve();
 }

Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
int main(){
    ll a[4],result=-1000000000000000000LL;
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    result = max(result,a[0]*a[2]);
    result = max(result,a[0]*a[3]);
    result = max(result,a[1]*a[2]);
    result = max(result,a[1]*a[3]);
    cout << result << endl;
}


Measured memory_bytes: 3608
n = int(input())
t, a = map(int, input().split())
hs = list(map(int, input().split()))

for i in range(len(hs)):
    b = t - hs[i] * 0.006
    sa = abs(a-b)
    hs[i] = sa

print(hs.index(min(hs))+1)

Measured memory_bytes: 3060
#include <cstring>
#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 <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 3e5 + 100;
const long long MNN = 2e3 + 10;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, b[MXN], ans, t[MXN * 4];

void build(int v, int tl, int tr){
	if(tl == tr){
		t[v] = b[tl];
		return ;
	}
	int tm = (tl + tr) / 2;
	build(v * 2, tl, tm);
	build(v * 2 + 1, tm + 1, tr);
	t[v] = min(t[v * 2], t[v * 2 + 1]);
}

llong get(int v, int tl, int tr, int L, int R){
	if(L <= tl && tr <= R){
		return t[v];
	}
	if(R < tl || tr < L || L > R){
		return INF;
	}
	int tm = (tl + tr) / 2;
	return min(get(v * 2, tl, tm, L, R), get(v * 2 + 1, tm + 1, tr, L, R));
}

llong getL(llong R, llong x){
	R--;
	llong l = 1, r = R;
	while(r - l > 1){
		llong m = (r + l) / 2;
		if(get(1, 1, n, m, R) > x){
			r = m;
		}else{
			l = m;
		}
	}
	if(get(1, 1, n, l, R) > x) return l;
	else if(get(1, 1, n, r, R) > x) return r;
	else return R + 1;
}

llong getR(llong L, llong x){
	L++;
	llong l = L, r = n;
	while(r - l > 1){
		llong m = (r + l) / 2;
		if(get(1, 1, n, L, m) > x){
			l = m;
		}else{
			r = m;
		}
	}
	if(get(1, 1, n, L, r) > x) return r;
	else if(get(1, 1, n, L, l) > x) return l;
	else return L - 1;
}

int main(){
	ios;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> b[i];
	}
	build(1, 1, n);
	for(int i = 1; i <= n; i++){
		llong cntL = abs(getL(i, b[i]) - i) + 1, cntR = abs(getR(i, b[i]) - i) + 1;
		ans += cntL * cntR * b[i];
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    int n, m, x, mn = INT_MAX;
    cin >> n >> m >> x;
    vector<int> price, upgrade[n];
    for(int i = 0; i != n; ++i){
        price.push_back(input());
        for(int j = 0; j != m; ++j) upgrade[i].push_back(input());
    }
    for(int msk = 0; msk < (1<<n); ++msk){
        vector<int> skill(m);
        int money = 0, sw = true;
        for(int i = 0; i < n; ++i){
            if(msk&(1<<i)){ //buy
                money += price[i];
                for(int j = 0; j != m; ++j) skill[j]+=upgrade[i][j];
            }
        }
        for(int cur : skill){
            if(cur < x){
                sw = false;
                break;
            }
        }
        if(sw) mn = min(money, mn);
    }
    (mn == INT_MAX) ? cout << -1 : cout << mn;
}

Measured memory_bytes: 3640
=begin
1, 多重配列でA(i,j)の配列を作る
2, b = [m個]の配列を作る
3, A をindex付きで回し、a[i]とb[i]を掛けて ans に足していく
=end

n, m = gets.split.map(&:to_i)

A = []
n.times do
  num = gets.split.map(&:to_i)
  A << num
end

b = []
m.times do
  b << gets.to_i
end

A.each{|a|
  ans = 0
  a.each_with_index{|n, i|
    ans += a[i] * b[i]
  }
  puts ans
}


Measured memory_bytes: 6976
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vc<ll> h(n),dp(n,INF);
    rep(i,n) cin >> h[i];
    
    dp[0] = 0;
    rng(i,1,n){
        chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
        if(i > 1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define PI acos(-1)
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a) * (b)).imag()
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define Y imag()
#define X real()
#define EPS 1e-7
#define mod 1000000007
#define N 1e2
using namespace std;
typedef complex <ld> point;
typedef vector <point> polygon;
typedef tuple <ld, ld, ld> line;
typedef vector <point> spolygon;

line lineeq(point x, point y){
	ll a = y.Y - x.Y;
	ll b = x.X - y.X;
	ll c = -a * x.X - b * x.Y;
	ll gcd = abs(__gcd(a, __gcd(b, c)));
	if(a < 0 || (a == 0 && b < 0)) gcd *= -1;
	a /= gcd; b /= gcd; c /= gcd;
	return line(a, b, c);
}

point getpoint(line l1, line l2){
	ld y = (get<0>(l1) * get<2>(l2) - get<0>(l2) * get<2>(l1)) / (get<0>(l2) * get<1>(l1) - get<0>(l1) * get<1>(l2));
	ld x = (get<2>(l1) * get<1>(l2) - get<2>(l2) * get<1>(l1)) / (get<0>(l2) * get<1>(l1) - get<0>(l1) * get<1>(l2));
	return point(x, y);
}

bool onray(point a, point b, point c){
	return dot(b - a, c - a) > -EPS;
}

ll fact(ll n){
	if(n == 0) return 1;
	return n * fact(n - 1);
}

bool isPrime(ll q){
	if(q == 0 || q == 1) return false;
	for(int i = 2; i * i <= q; i++) if(q % i == 0) return false;
	return true;
}

point rotate(point p, ld a){
	return p * polar((ld)1, a * PI / 180);
}

bool canBe(line l1, line l2){
	if(get<0>(l2) * get<1>(l1) - get<0>(l1) * get<1>(l2) != 0) return true;
	return false;
}

ld getangle(point p){
	return arg(p) * 180 / PI;
}

ll fp(ll base, ll x){
	if(x == 0) return 1;
	ll ans = fp(base, x / 2);
	ans = (ans * ans) % mod;
	if(x % 2)
		ans = ((base % mod) * ans) % mod;
	return ans;
}

ll GCD(ll a, ll b){
	if(b == 0) return a;
	if(a == 0) return b;
	return GCD(b, a % b);
}

ll LCM(ll a, ll b){
	return (a * b) / GCD(a, b);
}


ll fac[(int)1e4 + 7], inv[(int)1e4 + 7];

void calcFacAndInv(ll n){
    fac[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fac[i] = (i * fac[i - 1]) % mod;
        inv[i] = fp(fac[i], (ll)mod - 2);
    }
}

ll ncr(ll n, ll r){
    return ((fac[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r){
    return (fac[n] * inv[n - r]) % mod;
}

ll p[55][55] = {};

void pascal(){
    p[0][0] = 1;
    for(int i = 1; i < 55; i++) {
        p[i][0] = 1;
        for(int j = 1; j <= i; j++) p[i][j] = p[i - 1][j] + p[i - 1][j - 1];
    }
}

int main() {
	Data_Nerd
	int n, k; cin >> n >> k;
	int arr[n], sum[n];
	for(int i = 0; i < n; cin >> arr[i++]);
	sum[0] = 0, sum[1] = abs(arr[0] - arr[1]);
	for(int i = 2; i < n; i++){
		sum[i] = 1e9;
		for(int j = i - 1; j >= max(0, i - k); j--){
			sum[i] = min(sum[i ], abs(arr[i] - arr[j]) + sum[j]);
		}
	}
	cout << sum[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
using ll = long long;

int main() {
  ll N,R=26,C=1,i;
  cin>>N;
  while((N-1)/R>0) {
    N-=R;
    R*=26;
    C++;
  }
  string ans = "";
  N--;
  for (i=0;i<C;i++) {
    char c = ('a' + (N%26));
    ans = c + ans;
    N/=26;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
int num[200010], n, k; set<int> s;
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
	int res = 1, ct = 0, hh = 0;
	for (int i = 1; i <= k; i++) s.insert(num[i]);
	for (int i = 1; i < n; i++) {
		if (num[i] < num[i + 1]) ct++;
		else ct = 0;
		if (ct == k - 1) hh++;
	}
	for (int i = k + 1; i <= n; i++) {
		s.erase(num[i - k]);
		if (num[i - k] > *s.begin() || num[i] < *s.rbegin()) 
			res++;
		s.insert(num[i]);
	}
	printf("%d\n", res - max(0, hh - 1));
}

Measured memory_bytes: 10368
n=int(input())
*a,=map(int,input().split())
s=sum(a)%(10**9+7)
c=0
b=0
for i in range(n):
    b+=a[i]
    amod=a[i]%(10**9+7)
    c+=(s-b)*amod
print(c%(10**9+7))

Measured memory_bytes: 31604
#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<functional>
#include<bitset>
#include<stack>
#define e exp(1)
#define eps 0.01
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n;
int a, b;
int main() {
    while (cin >> n >> a >> b) {
        int Max = min(a, b);
        int Min;
        if (a + b <= n) {
            Min = 0;
        }
        else if(a == n && b == n){
            Min = n;
        }
        else {
            Min = (a + b) - n;
        }
        cout << Max << " " << Min << endl;
    }
    return 0;
}

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

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;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int n,m;
  scanf("%d%d",&n,&m);

  int X,Y;
  scanf("%d%d",&X,&Y);

  int x,y;
  int x_max = X, y_min = Y;
  for(int i = 0; i < n; ++i){
    scanf("%d",&x);
    x_max = max(x_max, x);
  }
  for(int i = 0; i < m; ++i){
    scanf("%d",&y);
    y_min = min(y_min, y);
  }

  if(x_max < y_min){
    printf("No War");
  }else{
    printf("War");
  }

  return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
static const int INF   = (1 << 21);
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;
static const int NIL   = -1;
static const int MAX   = 10000;

int n;
vector<vector<pair<int, int>>> M(MAX);

void dijstra(int s) {
  vector<int> color(n, WHITE);
  vector<int> d(n, INF);
  d[s] = 0;
  priority_queue<pair<int, int>> pq;
  pq.push(make_pair(0, 0));

  while (!pq.empty()) {
    pair<int, int> tmp = pq.top();
    pq.pop();

    int u    = tmp.second;
    color[u] = BLACK;
    if (d[u] < tmp.first * (-1)) continue;

    int size = M[u].size();
    for (int i = 0; i < size; i++) {
      int v = M[u][i].second;
      if (color[v] == BLACK) continue;

      if (d[u] + M[u][i].first < d[v]) {
        d[v]     = d[u] + M[u][i].first;
        color[v] = GRAY;
        pq.push(make_pair(d[v] * (-1), v));
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    for (int j = 0; j < k * 2; j += 2) {
      pair<int, int> p;
      cin >> p.second >> p.first;
      M[id].push_back(p);
    }
  }
  dijstra(0);
}


Measured memory_bytes: 7988
use std::io;

/// https://beta.atcoder.jp/contests/agc005/tasks/agc005_a
fn main() {
    let x = read_one::<String>();
    let mut buf = Vec::new();

    for c in x.chars() {
        match c {
            'S' => buf.push(c),
            'T' => {
                if let Some(&'S') = buf.last() {
                    buf.pop();
                } else {
                    buf.push(c);
                }
            },
            _ => (),
        }
    }

    println!("{}", buf.len());
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_H 8
using namespace std;

int h, w;

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

  cin >> h >> w;
  string a[MAX_H];
  for(int i = 0; i < h; i++){
    cin >> a[i];
  }

  int count = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(a[i][j] == '#') ++count;
    }
  }

  if(count == h + w - 1){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }

  return 0;
}


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

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	int i = 0;
	int coin = 0;

	while( coin < C ) {
		++i;
		coin += A;

		if( i % 7 == 0 ) {
			coin += B;
		}
	}

	cout << i << endl;
}



Measured memory_bytes: 3104
#include <stdio.h>

int main(void){
    int num;
    long int sum = 0;

    scanf("%d", &num);

    for (int i = 1; i <= num; i++){
        if (i%3 != 0 && i% 5 != 0)
            sum += i;
    }

    printf("%ld", sum);

    return 0;
}

Measured memory_bytes: 1680
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b&&b<c&&a<c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1708
def CheckPalindrome(S, L):
    result = True
    for i in range((L+1)//2):
        if S[i] != S[-i-1]:
            result = False
            break
    return result

result = True
S = input()
L = len(S)

result = CheckPalindrome(S, L)

if result:
    S2 = S[:(len(S)-1) // 2]
    L2 = len(S2)
    result = CheckPalindrome(S2, L2)

if result:
    S3 = S[(L+3)//2-1:]
    L3 = len(S3)
    result = CheckPalindrome(S3, L3)

if result:
    print('Yes')
else:
    print('No')

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

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	string s;cin>>s;
  	int n=s.length();
  	s+=(s[n-1]=='s')?"es":"s";
  	cout<<s<<"\n";
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ulli unsigned long long int
#define lli long long int
#define d double
#define mod 1000000007
#define mx 200001
using namespace std;
void add_me(lli &a,lli b){
	a+=b;
	if(a>=mod) a-=mod;
}
void sub_me(lli &a,lli b){
	a-=b;
	if(a<0) a+=mod;
}
struct disjointset{
	int parent[mx];
	disjointset(){
		for(int i=1;i<mx;i++) parent[i]=i;
	}
	int find(int x){
		int par=parent[x];
		if(par==x) return x;
		return find(parent[x]);
	}
	void union_(int x,int y){
		int par1=find(x);
		int par2=find(y);
		if(par1==par2) return;
		parent[par2]=par1;
	}
};
int main() {
	FIO;
	lli n;
	cin>>n;
	int A[n],x[n][15],y[n][15];
	for(int i=0;i<n;i++){
		cin>>A[i];
		for(int j=0;j<A[i];j++){
			cin>>x[i][j]>>y[i][j];
		}
	}
	int ans=0;
	for(int i=1;i<(1<<n);i++){
		bool ok=true;
		for(int bit=0;bit<n;bit++){
			if(!(i&(1<<bit))) continue;
			for(int j=0;j<A[bit];j++){
				int person=x[bit][j];
				int prediction=y[bit][j];
				if((i&(1<<(person-1)))){
					if(!prediction) ok=false;
				}
				else{
					if(prediction) ok=false;
				}
			}
		}
		if(ok) ans=max(ans,__builtin_popcount(i));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  if(M1 != M2){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
N,M=map(int,input().split())
S=[]
zentai=0
for i in range(M):
    K=list(map(int,input().split()))
    S.append(K[1:])
P=list(map(int,input().split()))
for i in range(2**N):
    switch=["off"]*N
    count=0
    ON_switch=[]
    for j in range(N):
        if ((i>>j)&1):
            ON_switch.append(j+1)
    """ for k in range(N):
        if switch[k]=="on": """            
    for m in range(M):
        cnt=0
        for n in range(len(S[m])):
            if S[m][n] in ON_switch:
                cnt+=1
        else:
            if cnt%2==P[m]:
                count+=1
    else:
        if count==M:
            zentai+=1
print(zentai)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  vector<int> d(n);
  for (int j = 0; j < n-1; j++) {
    d.at(j) = a.at(j+1)-a.at(j);
  }
  d.at(n-1) = a.at(0) + k - a.at(n-1);
  int max = 0;
  for (int j = 0; j < n; j++) {
    if (max < d.at(j)) {
      max = d.at(j);
    }
  }
  cout << k-max;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(void){
  int n;
  cin>>n;
  int A[3][111];
  int a;
  for(int i=1;i<=2;i++){
    for(int j=1;j<=n;j++){
      cin>>a;
      A[i][j]=a;
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    int tmp=0;
    int t=1;
    for(int j=1;j<=n;j++){
      tmp+=A[t][j];
      if(j==i) {
	t=2;
	tmp+=A[t][j];
      }
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
vector<int>a;
main()
{
	for(int i=1;7*i-1<300000;i++)
	{
		int n=i*7-1;
		bool flag=0;
		for(int j=0;j<a.size()&&a[j]*a[j]<=n;j++)flag|=n%a[j]<1;
		if(!flag)a.push_back(n);
		n=i*7+1;
		flag=0;
		for(int j=0;j<a.size()&&a[j]*a[j]<=n;j++)flag|=n%a[j]<1;
		if(!flag)a.push_back(n);
	}
	int s;
	while(cin>>s,s-1)
	{
		cout<<s<<":";
		for(int i=0;i<a.size();i++)
		{
			if(s%a[i]<1)cout<<" "<<a[i];
		}
		cout<<endl;
	}
}



Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n, at = 0, ax = 0, ay = 0, t, x, y;
  scanf("%d", &n);
  rep(i,n)
  {
    scanf("%d%d%d", &t, &x, &y);
    if (abs(t - at) >= abs(x - ax) + abs(y - ay) && (x + y + t) % 2 == 0) {
      at = t, ax = x, ay = y;
    } else {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}


Measured memory_bytes: 256