akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;

#define forn(i, n) for(int i = 0; i < n; i++)
#define forsn(i, s, n) for(int i = s; i < n; i++)
#define all(x) x.begin(), x.end()

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n, m;
	cin >> n >> m;
	vi done(n + 1), wront_cnt(n + 1);
	forn(i, m){
		int x;
		string s;
		cin >> x >> s;
		if(s == "AC"){
			done[x] = 1;
		}
		else{
			if(!done[x]){
				wront_cnt[x]++;
			}
		}
	}
	int ac = 0, pen = 0;
	for(int i = 1; i <= n; i++){
		if(done[i]){
			ac++;
			pen += wront_cnt[i];
		}
	}
	cout << ac << " " << pen << endl;
}		


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {
bool is_not_int(double x) {
  return floor(x)!=x;
}

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

ll lcm(ll a, ll b) {
   return a * b / gcd(a, b);
}


int main(void) {
  int n,m;cin>>n>>m;
  int a[n+10];
  int tmp[n+10];

  ll l = 1;

  rep(i,0,n-1) {
    cin >> a[i];
    tmp[i] = a[i];
    l = lcm(l,a[i]);
  }

  while(true) {
    int mark = 0;
    rep(i,0,n-1) {
      if (tmp[i]%2==0) {
        mark++;
        tmp[i] = tmp[i] / 2;
      }
    }
    if(0 < mark && mark < n) {
      pr(0);
      return 0;
    }
    if(0 == mark) {
      break;
    }
  }

  ll ans=floor((m+l/2)/l);
  pr(ans);

  // rep(i,1,m) {
  //   bool mark = true;
  //   // cout << i << ": ";
  //   rep(k,0,n-1) {
  //     int p = (1.0*i)/a[k] - 0.5;
  //     // cout << a[k] << " " << (1.0*i)/a[k] - 0.5 << " | ";
  //     // cout << a[k] << " " << (1.0*i)/a[k] << " | ";
  //     // cout << p << " " << (1.0*i)/a[k] - 0.5 << " | ";
  //     if(p < 0 || is_not_int((1.0*i)/a[k] - 0.5)) {
  //       mark = false;
  //       // break;
  //     }
  //   }
  //   // cout << endl;
  //   if(mark) {
  //     ans++;
  //   }
  // }
  return 0;
}

#if 0
2 3  2 5
2 7  2 11  2 2 2 5

3 1000
14 20 40

3 4000
14 20 40


2 70
6 10

2 50
3 15
#endif


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

ll pow_l(ll a){
  return a*a*a*a*a;
}

int main(){
  ll x; cin >> x;
  for(ll i = 1; i <= 200; i++){
    for(ll j = -200; j <= 200; j++){
      if(pow_l(i)-pow_l(j)==x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }

  
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;

struct st
{
	int kt,d;
}a[100010];

bool cmp(st x,st y)
{
	return x.d>y.d;
}

int n,k;
long long cnt,tp,ans,now;
bool vis[100010];
stack<int> s;

int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i].kt>>a[i].d;
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++)
	{
		if(cnt<k)
		{
			if(!vis[a[i].kt])
			{
				++tp;
				vis[a[i].kt]=true;
			}
			else
				s.push(a[i].d);
			++cnt;
			now+=a[i].d;
			ans=max(ans,now+tp*tp);
		}
		else
		{
			if(s.empty())
				break;
			if(vis[a[i].kt])
				continue;
			vis[a[i].kt]=true;
			now+=a[i].d;
			now-=s.top();
			s.pop();
			++tp;
			++cnt;
			ans=max(ans,now+tp*tp);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280
/**Hey, What's up?*/

#include<bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<long long>v;
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    string s;
    cin>>s;
    n=s.size();
    p=0;
    for(i=n-1;i>=0;i--){
        if(s[i]=='W')p++;
        else{
            f+=p;
        }
    }
    cout<<f<<'\n';
    return 0;
}


Measured memory_bytes: 3760
// Reverse polish notation                                                                                                           
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int i, x, y;
  char n[7], op;
  int a[200];

  // input                                                                                                                           
  i = 0;
  while(scanf("%s", n) != EOF) {
    op = n[0];

    if((op == '+') || (op == '-') || (op == '*') || (op == '/')) {
      i--;
      x = a[i - 1];
      y = a[i];
      // pop the two number and calculate
      switch(op) {
      case '+':
        a[i - 1] = x + y;
        break;
      case '-':
        a[i - 1] = x - y;
	break;
      case '*':
        a[i - 1] = x * y;
	break;
      default:
        a[i - 1] = x / y;
	break;
      }
      a[i] = 0;
    }
    
    else {
      // push the number
      a[i] = atoi(n);
      i++;
    }
  }

  printf("%d\n", a[0]);

  return 0;
}



Measured memory_bytes: 2144
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


		int[] array = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

		FastScanner fs = new FastScanner();
		int K = fs.nextInt();
		System.out.println(array[K-1]);

	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
const int mxN=1e9;
const ll mod = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
    ll n,w;
    cin>>n>>w;

    vector<vector<ll>> v(n,vector<ll>(2));

    for(int i=0;i<n;i++){
        cin>>v[i][0]>>v[i][1];
    }

    ll dp[n+1][100005];
    memset(dp,0,sizeof(dp));

    for(int i=1;i<=100004;i++) dp[0][i]=INT_MAX;
    ll ans = 0;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=100004;j++){
            dp[i][j]=dp[i-1][j];
            if(j>=v[i-1][1])dp[i][j] = min(dp[i][j],dp[i-1][j-v[i-1][1]]+v[i-1][0]);
            if(i==n){
                if(dp[i][j]<=w){
                    ans=j;
                }
            }
        }
    }

    cout<<ans;
}

Measured memory_bytes: 82492
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N,A,B;
	string s;
	cin>>N>>A>>B>>s;
	int S=A+B;
	rep(i,N){
		if(s[i]=='a'){
			if(S){
				puts("Yes");
				S--;
			}else{
				puts("No");
			}
		}
		if(s[i]=='b'){
			if(S&&B){
				puts("Yes");
				S--;
				B--;
			}else{
				puts("No");
			}
		}
		if(s[i]=='c'){
			puts("No");
		}
	}
}


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

long long int i,j,ans=1;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;


long long int solve(long long int a,long long int b){
	long long int check=0;
	if(b>a){
		check = a;
		a=b;
		b=check;
	}
	if(a*b==0){
		return a+b;
	}else if(a%b==0){
		return b;
	}else{
		solve(b,a%b);
	}
}

int main(){
	int n;
	cin >> n;
	long long int ans=1;
	long long int a[100];
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	ans = a[0];
	for(i=1;i<n;i++){
		ans = (ans/solve(ans,a[i])) * (a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

s = input()[:-1]
hl = len(s) // 2
s1, s2 = s[:hl], s[:-hl - 1:-1]
ans = 0

for i1, i2 in zip(s1, s2):
    if i1 != i2:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
int n,m;
int main(){
  cin >> n >> m;
  char a[n][n],b[m][m];
  for (int i = 0; i < n; i++) {
    for (int l = 0; l < n; l++) {
      cin >> a[l][i];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int l = 0; l < m; l++) {
      cin >> b[l][i];
    }
  }
  bool can=false;
  for (int ny = 0; ny < n-(m-1); ny++) {
    for (int nx = 0; nx < n-(m-1); nx++) {
      bool ac=true;
      for (int my = 0; my < m; my++) {
        for (int mx = 0; mx < m; mx++) {
          if(b[mx][my] != a[nx+mx][ny+my]) ac=false;
        }
      }
      if(ac)can=true;
    }
  }
  cout << (can ? "Yes":"No") << endl;
}


Measured memory_bytes: 256
line = readlines
line.each{|n|
    x,y = n.split.map(&:to_i)
    if (x == 0) && (y == 0)
        break
    end
    if x < y
        puts x.to_s + ' ' + y.to_s
    else
        puts y.to_s + ' ' + x.to_s
    end
}


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

int main(){
  int n,m;
  cin>>n>>m;
  map<int,int> mp;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    mp[a]++;
    mp[b]++;
  }
  bool ans=1;
  for(auto x : mp){
    if(x.second%2!=0) ans=0;
  }
  if(ans) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}



Measured memory_bytes: 7476
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val (n,mi) = f.readLine().split(" ").map{it.toInt()}
	val m = mi.toLong()

	val array = f.readLine().split(" ").map{it.toLong()}

	fun check(x : Long) : Boolean{
		var count = 0L
		for(k in 0 until n){
			count += (array[k] + x-1)/x-1
		}
		return count <= m
	}

	var l = 1L
	var r = 1000000000L
	var ans = 1000000000L
	while(l <= r){
		val mid = l + (r-l)/2
		if(check(mid)){
			ans = mid
			r = mid-1
		} else {
			l = mid+1
		}
	}

	println(ans)
}


Measured memory_bytes: 63900
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int sum=0,x=n;
    while(n>0){
      sum+=n%10;
      n/=10;
    }
    if(x%sum==0){
      System.out.println("Yes");
      return ;
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 23124
import sys

n = int(input())
A = [int(a) for a in input().split()]

q = int(input())
M = [int(m) for m in input().split()]

makable = set()

for i in range(2 ** n):
    total = 0

    for j in range(n):
        b = i % 2
        total += A[j] * b
        i //= 2

    makable.add(total)

# print(makable)

for m in M:
    if m in makable:
        print("yes")
    else:
        print("no")

Measured memory_bytes: 7748
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m;cin>>n>>m;
   while(m--)
   {
       int x;cin>>x;
       n-=x;
   }
   if(n<0)
    cout<<"-1\n";
   else
    cout<<n<<endl;
}


Measured memory_bytes: 3636
n, m = gets.split.map(&:to_i)
al = 1
ar = n
m.times do |i|
  l, r = gets.split.map(&:to_i)
  al = [al, l].max
  ar = [ar, r].min
  if al > ar
    puts 0
    exit
  end
end
puts ar - al + 1


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

const int N = 3005;
const int MOD = 998244353;

void addMod(int& x, int y) {
    x += y;
    while (x >= MOD) x -= MOD;
}

int dp[N][N];
int a[N];

void solve() {
    int n, s;
    scanf("%d%d", &n, &s);

    for (int i = 1; i <= n; i++) scanf("%d", a+i);

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= s; j++) {
            addMod(dp[i][j], dp[i-1][j]*2);
            if (j >= a[i]) {
                addMod(dp[i][j], dp[i-1][j-a[i]]);
            }
        }
    }

    printf("%d\n", dp[n][s]);

}

int main(){

    solve();
	return 0;
}


Measured memory_bytes: 38972
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#include <set>
#include <map>
#define maxn 105

using namespace std;
typedef long long ll;

int h, w, f[maxn][maxn];
char s[maxn][maxn];
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 1; i <= h; i++) scanf("%s", s[i] + 1);
  f[1][1] = (s[1][1] == '#');
  for (int i = 2; i <= w; i++)
    f[1][i] = f[1][i - 1] + (s[1][i] == '#' && s[1][i - 1] != '#');
  for (int i = 2; i <= h; i++)
    f[i][1] = f[i - 1][1] + (s[i][1] == '#' && s[i - 1][1] != '#');
  for (int i = 2; i <= h; i++) {
    for (int j = 2; j <= w; j++) {
      f[i][j] = min(f[i - 1][j] + (s[i][j] == '#' && s[i - 1][j] != '#'),
                    f[i][j - 1] + (s[i][j] == '#' && s[i][j - 1] != '#'));
    }
  }
  printf("%d\n", f[h][w]);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll n,k,a[200010],ans=0,visit[200010]={};
V<ll> v[200010];
VV<ll> inc;
set<ll> s;

void init(){
	cin>>n>>k;
	ll b=-1;
	inc.push_back({});
	reg(i,1,n){
		cin>>a[i];
		if(b<a[i]){
			inc[inc.size()-1].push_back(i);
		}else{
			inc.push_back({i});
		}
		b=a[i];
	}
}

int main(void){
	init();
	reg(i,1,k)s.insert(a[i]);
	// 同じになるやつを結ぶ
	reg(i,k+1,n){
		s.erase(a[i-k]);
		if(a[i-k]<*s.begin() && *prev(s.end())<a[i]){
			v[i].push_back(i-1);
			v[i-1].push_back(i);
		}
		s.insert(a[i]);
	}
	// 変化しない分
	bool unchange_exist=false;
	rep(i,inc.size()){
		// cerr<<"inc_size:"<<inc[i].size()<<endl;
		if(inc[i].size()>=k)unchange_exist=true;
		reg(j,k-1,inc[i].size()-1){
			v[k-1].push_back(inc[i][j]);
			v[inc[i][j]].push_back(k-1);
		}
	}
	if(!unchange_exist)ans--;  // 変化するやつが無いなら、同値類 k-1 は無意味
	// 同値類計算
	reg(i,k-1,n){
		if(visit[i]==0){
			ans++;
			queue<ll> Q;
			visit[i]=i;
			Q.push(i);
			while(!Q.empty()){
				ll p = Q.front();Q.pop();
				for(ll q:v[p]){
					if(visit[q]==0){
						visit[q]=i;
						Q.push(q);
					}
				}
			}
		}
		// cerr<<"同値類"<<i<<": "<<visit[i]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 23216
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());
        String answer = "No ";
        if(a>b){
            for(int i = b;i<a;i++){
                if(c == i){
                    answer = "Yes";
                    break;
                }
            }
        }else{
            for(int i = a;i<b;i++){
                if(c == i){
                    answer = "Yes";
                    break;
                }
            }
        }


        PrintWriter out = new PrintWriter(System.out);
        out.println(answer);
        out.flush();
        scan.close();
    }
}

Measured memory_bytes: 23764
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        H: isize,
        W: isize,
        Sij: [chars; H]
    }
    let dx = [1, 0, -1, 0];
    let dy = [0, 1, 0, -1];

    for i in 0..H {
        'outer: for j in 0..W {
            if Sij[i as usize][j as usize] == '#' {
                for d in 0..4 {
                    if (j + dx[d]) != -1
                        && (i + dy[d]) != -1
                        && (j + dx[d]) != W
                        && (i + dy[d]) != H
                    {
                        if Sij[(i + dy[d]) as usize][(j + dx[d]) as usize] == '#' {
                            continue 'outer;
                        }
                    }
                }
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define scs(x) scanf("%s",x)
#define pr(x) printf("%d",x)
#define prn(x) printf("%d\n",x)
#define memc(x,y) memcpy(&x,&y,sizeof(x))
#define mems(x,y) memset(x,y,sizeof(x))
#define fli() freopen("in.txt","r",stdin)
#define flo() freopen("out.txt","w",stdout)
#define rep(i,v) for(int i=0;i<v;i++)
#define repe(i,v) for(int i=0;i<=v;i++)
#define Rep(i,x,v) for(int i=x;i<v;i++)
#define Repe(i,x,v) for(int i=x;i<=v;i++)
#define repv(i,x) for(auto i=x.begin();i!=x.end();i++)
#define reprv(i,x) for(auto i=x.rbegin();i!=x.rend();i++)
#define dbg(x) cout << #x << " : " << x << endl
#define pb push_back
#define bl putchar('\n')
#define gcc getchar()
#define pcc putchar
#define si size
#define fi first
#define se second
#define MAX 300000
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair<int,int> ii;
using namespace std;

int main(){
  // fli();
  int n,mx=0,x;
  long long int ans=0;
  sc(n);
  rep(i,n){
    sc(x);
    if(i){
      if(mx>=x){
        ans+=(mx-x);
      }else{
        mx = x;
      }
    }else{
      mx=x;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3736
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	static final int uncal = -1;
	static final double pi = 3.14159;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=1;i<n;i++) {
			a[sc.nextInt()-1]++;
		}
		for(int i:a)
			out.println(i);
		out.close();
	}
	static void shuffle(int[] array) {
		Random rand = new Random();
		for (int i = 0; i < array.length; i++) {
			int randomIndexToSwap = rand.nextInt(array.length);
			int temp = array[randomIndexToSwap];
			array[randomIndexToSwap] = array[i];
			array[i] = temp;
		}
	}
	static boolean isPalindrome(String s) {
		int l = s.length();
		char[] sa = s.toCharArray();
		for(int i=0;i<l/2;i++) {
			if(sa[i] != sa[l-i-1])
				return false;
		}
		return true;
	}
	static class Point extends java.awt.Point implements Comparable<Point>{
		public Point(int x,int y) {
			// TODO Auto-generated constructor stub
			super(x,y);
		}
		public String toString() {
			return x+" "+y;
		}
		@Override
		public int compareTo(Point p) {
			// TODO Auto-generated method stub
			if(x == p.x)
				return y - p.y;
			return x - p.x;
		}
		
	}
	static class Scanner{
		private BufferedReader br;
		private StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		public Scanner(String filename) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(filename));
		}
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		public double nextDouble() throws IOException{
			return Double.parseDouble(next());
		}
		public int[] inArr(int n) throws Exception{
			int a [] = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				a[i] = Integer.parseInt(next());
			}
			return a;
		}
	}

}

Measured memory_bytes: 54604
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
struct node{
	ll num,time;
};
bool cmp(node a,node b){
	return a.time<b.time;
}
int main(){
	fast;
	ll a,b;
	cin>>a>>b;
	ll x=gcd(a,b);
	ll bound=sqrt(x);
	ll ans=1;
	for(ll i=2;i<=bound;i++){
		if(x%i==0)ans++;
		while(x%i==0)x/=i;
	}if(x!=1)ans++;cout<<ans<<endl;return 0;
}/*『你强归你强，我永不示弱』*/




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

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define nl '\n'
void solve(){
  int n;
  cin>>n;
  ll ans=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        ans+=(__gcd(__gcd(i,j),k));
      }
    }
  }
  cout<<ans<<endl;
}
int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n,testCase;
    solve();
    return 0;
}


Measured memory_bytes: 3600
using System;

namespace ABC153A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] ss = Console.ReadLine().Split(' ');
            a = int.Parse(ss[0]);
            b = int.Parse(ss[1]);
            if (a % b != 0)
                Console.WriteLine(a / b + 1);
            else
                Console.WriteLine(a / b);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main() {
    int n;
    VE v;
    int V;
    cin >> n;
    REP(i, n){
        cin >> V;
        v.push_back(V);
    }
    sort(v.begin(), v.end());
    print(v[n - 1] - v[0]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     return p.first>q.first;//descending by first
//     return p.first<q.first;//ascending by first
//     return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }
    return 0;
}
int clue() {

    int m;
    string s;
    cin>>m;
    cin>>s;
    int n=s.size();
    if(n<=m) {
        cout<<s<<endl;
    }
    else {
        s.erase(m,n-m);
        cout<<s<<"..."<<endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PIP;

#define INF INT_MAX/3
#define MAX_N 100010

struct union_find {
    int rank[MAX_N], par[MAX_N];
    int cnt = 0;

    union_find(int n) { rep(i, n) rank[i] = 1, par[i] = i; }

    int find(int x) {
        if(x == par[x]) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y, int cost) {
        x = find(x); y = find(y);
        if(x == y) return;
        cnt += cost;
        if(rank[x] > rank[y]) par[y] = x;
        else {
            par[x] = y;
            if(rank[x] == rank[y]) rank[y]++;
        }
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    P x[n], y[n];
    rep(i, n) {
        cin >> x[i].fi >> y[i].fi;
        x[i].se = y[i].se = i;
    }
    sort(x, x + n), sort(y, y + n);

    vector<PIP> v;
    rep(i, n - 1) {
        v.pb(PIP(x[i + 1].fi - x[i].fi, P(x[i].se, x[i + 1].se)));
        v.pb(PIP(y[i + 1].fi - y[i].fi, P(y[i].se, y[i + 1].se)));
    }
    sort(v.begin(), v.end());

    union_find uf(n);
    rep(i, v.size()) uf.unite(v[i].se.fi, v[i].se.se, v[i].fi);
    cout << uf.cnt << endl;
    return 0;
}

Measured memory_bytes: 6516
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a-1].add(b-1)
        adj[b-1].add(a-1)
    Q = int(input())
    queries = [None] * Q
    dp = [[-1] * 11 for _ in range(N)]
    for i in range(Q):
        v, d, c = map(int, input().split())
        queries[i] = (v, d, c)
    for i in range(Q)[::-1]:
        v, d, c = queries[i]
        if dp[v-1][d] == -1:
            dp[v-1][d] = i
    for j in range(10)[::-1]:
        for i in range(N):
            dp[i][j] = max(dp[i][j], dp[i][j+1])
            for nxt in adj[i]:
                dp[i][j] = max(dp[i][j], dp[nxt][j+1])
    for i in range(N):
        x = dp[i][0]
        if x == -1:
            print(0)
        else:
            print(queries[x][2])


if __name__ == "__main__":
    main()


Measured memory_bytes: 108336
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>H(N);
  
  for(int i=0;i<N;i++)
    cin>>H.at(i);
  vector<int>A={-1};
  for(int i=0;i<N-1;i++)
    if(H.at(i)<H.at(i+1))
      A.push_back(i);
  A.push_back(N-1);
  int n=A.size();
  int ans=0;
  for(int i=0;i<n-1;i++)
    if(ans<=A.at(i+1)-A.at(i)-1)
      ans=A.at(i+1)-A.at(i)-1;
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;
 
 
int main(){
    int n;cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<=n-1;i++)cin>>a[i];
    for(int i=0;i<=n-1;i++)cin>>b[i];
    for(int i=0;i<=n-1;i++)cin>>c[i];
    sort(a,a+n),sort(b,b+n),sort(c,c+n);
    ll  i=0,j=0,k=0;
    long long int ans=0;
    for(j=0;j<=n-1;j++){
        while(a[i]<b[j]&&i<=n-1)i++;
        while(b[j]>=c[k]&&k<=n-1)k++;
        ans+=i*(n-k);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
	long n, res = 0;
	cin >> n;
	while (n > 4)
	{
		if (n >= 500)
		{
			n -= 500;
			res += 1000;
		}
		else
		{
			n -= 5;
			res += 5;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
(defun digit-sum (x)
  (reduce #'+ (mapcar #'digit-char-p (concatenate 'list (write-to-string x)))))


(defun judge (lst p q)
  (let* ((z (car lst)))
    (if (null lst)
      nil
      (if (not (and (<= p z) (<= z q)))
        (cons 0 (judge (cdr lst) p q))
        (cons 1 (judge (cdr lst) p q))))))


(defun inner-product (lst1 lst2)
  (if (or (null lst1) (null lst2))
    0
    (+ (* (car lst1) (car lst2))
       (inner-product (cdr lst1) (cdr lst2)))))

(let* ((n (read))
       (a (read))
       (b (read))
       (l (loop for i from 1 to n
                collect i))
       (l2 (loop for i from 1 to n
                 collect (digit-sum i))))

 ;  (format t "~A~%" l)
 ;  (format t "~A~%" l2)
 ;  (format t "~A~%"
 ;          (judge l2 a b))


  (format t "~A~%"
          (inner-product l (judge l2 a b))))


Measured memory_bytes: 27164
#include<stdio.h>
#define N 25

typedef struct{
  int parent;
  int sibling;
  int degree;
  int left;
  int right;
  int depth;
  int height;
}node;

int height(int);
node T[N];

int main(){
  int n, i, j;
  int id, c1, c2, p;

  scanf("%d\n",&n);
  for(i = 0 ; i < n ; i++){
    T[i].parent = -1;
    T[i].sibling = -1;
    T[i].degree = 0;
    T[i].left = -1;
    T[i].right = -1;
    T[i].depth = 0;
    T[i].height = 0;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d", &id, &c1, &c2);
    T[id].left = c1;
      T[c1].parent = id;
      T[c1].sibling = c2;
      T[id].right = c2;
      T[c2].parent = id;
      T[c2].sibling = c1;
    if(c1 != -1 && c2 != -1){
      T[id].degree = 2;
    }
    else if(c1 != -1 || c2 != -1){
      T[id].degree = 1;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    j = i;
    while(1){
      p = T[j].parent;
      if(p == -1) break;
      j = p;
      T[i].depth++;
    }
  }
    
  for(i=0 ; i<n ; i++){
    T[i].height = height(i);
  }

  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,",i, T[i].parent, T[i].sibling, T[i].degree, T[i].depth, T[i].height);
    if(T[i].parent == -1){
      printf(" root\n");
    }
    else if(T[i].height == 0){
      printf(" leaf\n");
    }
    else{
      printf(" internal node\n");
    }
  }
  return 0;
}

int height(int x)
{
  int h1=0,h2=0;
 
  if(T[x].left == -1 && T[x].right == -1){
    return 0;
  }
  else {
    if(T[x].left == -1){
      h2 += (height(T[x].right)+1);
    }
    else if(T[x].right == -1){
      h1 += (height(T[x].left)+1);
    }
    else{
      h1 += (height(T[x].left)+1);
      h2 += (height(T[x].right)+1);
    }
    if( h1 > h2 ) return h1;
    else return h2;
  }
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

map< ll, ll > prime_factor(ll n) {
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}


int main() {
    ll N;
    cin >> N;
    // cout << N << ":";
    // for(auto p : prime_factor(N)) {
    //     while(p.second--) cout << " " << p.first;
    // }
    // cout << endl;

    map<ll,ll> mp = prime_factor(N);

    ll ans = 0;
    for(auto v : mp){
        // cout << v.first << " " << v.second << endl;
        ll cnt = v.second;
        ll tmp = 1;
        while (cnt >= tmp){
            cnt -= tmp;
            tmp++;
        }
        ans += tmp-1;
    }
    cout << ans << endl;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

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

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const int N = 2e5 + 5;
int fact[N], invfact[N];

int pow(int a, int b, int m)
{
   int ans=1;
   while(b)
   {
      if(b&1)
         ans=(ans*a)%m;
      b/=2;
      a=(a*a)%m;
   }
   return ans;
}

int modinv(int k)
{
   return pow(k, MOD-2, MOD);
}

void precompute()
{
   fact[0]=fact[1]=1;
   for(int i=2;i<N;i++)
   {
      fact[i]=fact[i-1]*i;
      fact[i]%=MOD;
   }
   invfact[N-1]=modinv(fact[N-1]);
   for(int i=N-2;i>=0;i--)
   {
      invfact[i]=invfact[i+1]*(i+1);
      invfact[i]%=MOD;
   }
}

int nCr(int x, int y)
{
   if(y>x)
      return 0;
   int num=fact[x];
   num*=invfact[y];
   num%=MOD;
   num*=invfact[x-y];
   num%=MOD;
   return num;
}

int32_t main(){
   fast;
   precompute();
   int n,k;
   cin >> n >> k;
   int ans =0;

   f(i,k,n+2){
      int mnsum = i*(i-1)/2;
      int mxsum = (n)*(n+1)/2 - (n-i)*(n-i+1)/2;
      ans += (mxsum - mnsum + 1 + MOD)%MOD;
      ans %= MOD;
   }
   cout << ans;
}

Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  bool p = false;
  bool w = false;
  bool g = false;
  bool y = false;
  
  for(int i = 0; i < N; i++) { 
    char color;
    cin >> color;
    
    if (color == 'P') {
      p = true;
    } else if (color == 'W') {
      w = true;
    } else if (color == 'G') {
      g = true;
    } else if (color == 'Y') {
      y = true;
    }
  }
  if (p && w && g && y) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  } 
}

Measured memory_bytes: 3600
n = int(input())
a = map(int, input().split())
cnt = -1
flg = False
while True:
    cnt += 1
    tmp_a = []
    for ai in a:
        if ai%2 == 0:
            tmp_a.append(ai//2)
        else:
            flg = True
            break
    if flg:
        break
    a = tmp_a
print(cnt)


Measured memory_bytes: 3060
#18 ABC132B
n=int(input())
p=list(map(int,input().split()))
res=0
for i in range(1,n-1):
    if p[i-1]<=p[i]<=p[i+1] or p[i-1]>=p[i]>=p[i+1]:
        res+=1
print(res)

Measured memory_bytes: 38384
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=m-n+1;i<n+m;i++)
    cout<<i<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }
ll kaijyo(ll a){
    ll ans=1;
    for(ll i=0;i<a;i++){
        ans*=a-i;
        ans%=MOD;
    }
    return ans;
}
int main(){
    ll N,M,ans=0,n,m;
    cin>>N>>M;
    if(N==M||abs(N-M)==1){
        n=kaijyo(N);
        m=kaijyo(M);
        ans=n*m;
        ans%=MOD;
        if(N==M){
            ans*=2;
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

# b -= a
# counter = 1
# while b > 0:
#     b -= a - 1
#     counter += 1

# print(counter)

sum_tap = 1

for i in range(100):
    if sum_tap >= b:
        print(i)
        break
    sum_tap += a - 1

Measured memory_bytes: 8992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt() - 1;
            }

            int[] inverse = new int[N];
            for (int i = 0; i < inverse.length; i++) {
                inverse[A[i]] = i;
            }

            for (int i = 0; i < inverse.length; i++) {
                if (i > 0) {
                    System.out.print(" ");
                }
                System.out.print(inverse[i] + 1);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 49824
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))

if p is None or not x in p:
  print(x)
else:
  for i in range(1, n + 1):
    if not (x - i) in p:
      print(x - i)
      break
    elif not (x + i) in p:
      print(x + i)
      break

Measured memory_bytes: 9180
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int n;
	cin >> n;

	map<char, int> m;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
			m[s[0]] += 1;
	}

	if (!m.size())
	{
		cout << "0" << endl;
		return 0;
	}

	string a = "MARCH";
	int64_t count = 0;
	for (int i = 0; i < m.size(); ++i)
		for (int j = i + 1; j < m.size(); ++j)
			for (int k = j + 1; k < m.size(); ++k)
				count += 1LL * m[a[i]] * m[a[j]] * m[a[k]];

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>

using namespace std;

string removedFirst(string str) {
  string ans;

  if(str.length() == 1) {
    return ans;
  }

  else {
    for(int i=1; i<str.length(); i++) {
      ans += str[i];
    }
    return ans;
  }
}

int main() {
  string str;
  getline(cin, str);
  while(str != "#") {
    char where = 'A';

    while(str.length() != 0) {
      char oldWhere = where;
      switch(where) {
      case 'A':
	if(str[0] == '0') {
	  where = 'X';
	}
	else {
	  where = 'Y';
	}
	break;
      case 'B':
	if(str[0] == '0') {
	  where = 'Y';
	}
	else {
	  where = 'X';
	}
	break;
      case 'X':
	if(str[0] == '1') {
	  where = 'Z';
	}
	break;
      case 'Y':
	if(str[0] == '0') {
	  where = 'X';
	}
	break;
      case 'Z':
	if(str[0] == '0') {
	  where = 'W';
	}
	else {
	  where = 'B';
	}
	break;
      case 'W':
	if(str[0] == '0') {
	  where = 'B';
	}
	else {
	  where = 'Y';
	}
      }
      str = removedFirst(str);
      if(where == oldWhere) {
	where = 'N';
	str.clear();
      }
    }

    if(where == 'B') {
      cout<<"Yes"<<endl;
    }
    else {
      cout<<"No"<<endl;
    }
    getline(cin, str);
  }
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    string S;
    cin >> S;
    int now;
    int size = S.size();
    now = size-1;
    for(int i=0;i<size;i++){
        
        string S1,S2;
        if(now%2==0){
            
            REP(j,now/2) S1 += S[j]; 
            for(int j = now/2;j<now;j++){
                int i=0;
                S2 += S[j];
            }
            
            
            if(S1==S2){
                cout << S1.size()*2<< endl;
                return 0;
            
            }
        
        }

        now --;
    }
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <iomanip>
using namespace std;

int main(int argc, char const *argv[]) {
  int k,s;cin>>k>>s;
  long long res=0;
  for(int i=0;i<=k;++i){
    for(int j=0;j<=k;++j)if(i+j<=s&&s-i-j<=k)res++;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#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() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  int n2 = 1 << n;
  vector<int> a(n2);
  rep(i, n2) { cin >> a[i]; }
  sort(a.begin(), a.end());
  vector<int> s;
  s.push_back(a.back());
  a.back() = -1;
  rep(i, n) {
    vector<int> p = s;
    sort(p.begin(), p.end());
    int ai = n2 - 1;
    while (p.size() > 0 && ai >= 0) {
      if (a[ai] == -1) {
        --ai;
        continue;
      }
      if (a[ai] < p.back()) {
        s.push_back(a[ai]);
        p.pop_back();
        a[ai] = -1;
      }
      --ai;
    }
    if (p.size() > 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
int64_t n, q, t, cnt = 0;
vector<int64_t> S(10001);

int linearSearch(int64_t target, vector<int64_t> A)
{
  for (int i = 0; i < A.size(); i++)
  {
    if (A.at(i) == target)
    {
      return i;
    }
  }
  return -1;
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> S.at(i);
  }
  cin >> q;
  for (int i = 0; i < q; i++)
  {
    cin >> t;
    if (linearSearch(t, S) != -1)
      cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3292