akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

bool dpX[4005][16005];  // dpX[i+1][j] : i番目の演算まででx座標がjの位置にいられるならtrue
bool dpY[4005][16005];  // dpY[i+1][j] : i番目の演算まででy座標がjの位置にいられるならtrue
 
int main() {
    string s;
    ll gx, gy;
    cin >> s >> gx >> gy;
    ll n = s.size();
    // x,y座標ともに+nだけ平行移動して考える
    gx += n;  gy += n;

    vl vx, vy;
    ll cntF = 0, cntT = 0; 
    rep(i, n) {
        if(s[i] == 'F') {
            cntF++;
        }
        else if(s[i] == 'T') {
            if(cntT%2 == 0) {
                vx.pb(cntF);
            }
            else {
                vy.pb(cntF);
            }
            cntF = 0;
            cntT++;
        }
    }
    if(s[n-1] == 'F' && cntT%2 == 0) {
        vx.pb(cntF);
    }
    if(s[n-1] == 'F' && cntT%2 == 1) {
        vy.pb(cntF);
    }

    ll mx = vx.size();
    dpX[0][n] = true;
    rep(i, mx) {
        exrep(j, 0, 2*n) {
            if(j - vx[i] >= 0 && dpX[i][j - vx[i]]) {
                dpX[i+1][j] = true;
            }
            if(i > 0 && j + vx[i] <= 2*n && dpX[i][j + vx[i]]) {
                dpX[i+1][j] = true;
            }
        }
    }

    ll my = vy.size();
    dpY[0][n] = true;
    rep(i, my) {
        exrep(j, 0, 2*n) {
            if(j - vy[i] >= 0 && dpY[i][j - vy[i]]) {
                dpY[i+1][j] = true;
            }
            if(j + vy[i] <= 2*n && dpY[i][j + vy[i]]) {
                dpY[i+1][j] = true;
            }
        }
    }
    
    if(dpX[mx][gx] && dpY[my][gy]) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

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

using namespace std;


int main(){
	int l,r,d;
  	cin >> l >> r >> d;
  	int count  = 0;
  	for(int i = l; i<=r; i++){
    	if(i%d == 0)
          count++;
    }
  cout << count <<endl;
  	


}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll N;
    cin>>N;
    vector<ll> A(N+1);
    for(ll x=1;x<=100;x++){
        for(ll y=1;y<=100;y++){
            for(ll z=1;z<=100;z++){
                ll D=x*x+y*y+z*z+x*y+y*z+z*x;
                if(D<=N)A.at(D)++;
            }
        }
    }
    for(ll i=1;i<=N;i++){
        cout<<A.at(i)<<endl;
    }
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll a,b,c,d;
    cin >>a>>b>>c>>d;

    if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    



    return 0;
    

}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x;
    while(n>0)
    {
        x=n%10;
        n=n/10;
        if(x==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3640
sa = input()
sb = input()
sc = input()

la = list(sa)
lb = list(sb)
lc = list(sc)

s = la.pop(0)

while True:
    if s=="a":
        if len(la)==0:
            print("A")
            break
        else:
            s = la.pop(0)
    elif s=="b":
        if len(lb)==0:
            print("B")
            break
        else:
            s = lb.pop(0)
    elif s=="c":
        if len(lc)==0:
            print("C")
            break
        else:
            s = lc.pop(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7  ))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
#define endl '\n'
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi;




	
int32_t main()
{
	IOS
	int n , m ; cin >> n >> m ;
	vector<int>a(n);
	int sum = 0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	int cnt = 0;
	for(int i=0;i<n;i++)
	{
		if( a[i] * 4* m < sum )continue;
		cnt++;
	}
	cout << ( cnt >= m ? "Yes" : "No" ) << endl;
	
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var aaa = Console.ReadLine().Split(' ');
            var T = double.Parse(aaa[0]);
            var A = int.Parse(aaa[1]);
            var hei = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            double min = 2222222220;
            var ans = 0;

            for(var x=0; x<N; ++x)
            {
                var temp = T - hei[x]*0.006;
                var tempa = Math.Abs(temp - A);

                if (min>tempa)
                {
                    ans = x + 1;
                    min = tempa;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main(int argc, char *argv[]){
  long long N,M;
  cin>>N>>M;
  int maxgcd=1;
  vector<long long> vec;
  for(int i=1; i<=sqrt(M); i++){
    if(M%i==0){
      vec.push_back(i);
      vec.push_back(M/i);
    }
  }
  sort(vec.begin(),vec.end());

  for(int i=0; i<vec.size(); i++){
    //cout<<vec[i]<<endl;
    long long tmp=vec[i];
    long long t=M-(tmp*(N-1));
    if(t<=0) continue;
    if(t%tmp==0){
     // cout<<vec[i]<<endl;
      maxgcd=tmp;
    }
  }
  cout<<maxgcd<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string x,y;
    cin >> x >> y;
    rep(i,y.length())
    {
        cout << x[i] << y[i];
    }
    
    if (x.length() != y.length())
    {
        cout << x[x.length()-1];
    }
    cout << endl;

}


Measured memory_bytes: 256
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    string m = s.substr(5, 2);
    int mi = 10 * (m[0] - '0') + (m[1] - '0');
    if (mi >= 5) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
    return 0;
}

Measured memory_bytes: 256
import math

n = int(input())

x = ["a"]
alps = "abcdefghijk"
i = 1
while i < n:
    y = []
    for t in x:
        for s in alps[:len(set(t)) + 1]:
            y.append(t + s)
    x = y
    i += 1

print("\n".join(x))


Measured memory_bytes: 19944
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 20;

vector<vector<char>> MAP(102,vector<char>(102,'0'));
vector<vector<int>> streak(102,vector<int>(102,0));
int H,W;

int dfs(int row, int col){
    int ue, hidari;

    if(row==1){
        if(MAP[row][col]!=MAP[row][col-1]){
            hidari = streak[row][col-1]+1;
        }else{
            hidari = streak[row][col-1];
        }
        streak[row][col]=hidari;
    }else if(col==1){
        if(MAP[row][col]!=MAP[row-1][col]){
            ue = streak[row-1][col]+1;
        }else{
            ue = streak[row-1][col];
        }
        streak[row][col]=ue;
    }else{
        if(MAP[row][col]!=MAP[row-1][col]){
            ue = streak[row-1][col]+1;
        }else{
            ue = streak[row-1][col];
        }

        if(MAP[row][col]!=MAP[row][col-1]){
            hidari = streak[row][col-1]+1;
        }else{
            hidari = streak[row][col-1];
        }
        streak[row][col]=min(ue, hidari);
    }


}

int main(void){


    cin>>H>>W;

    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            cin>>MAP[i][j];
        }
    }

    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            if(i==1 && j==1) continue;
            dfs(i,j);
        }
    }

    if(MAP[1][1]=='.'){
        cout<<(streak[H][W]+1)/2<<endl;
    }else{
        cout<<((streak[H][W]+2)/2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  ll n, k ,q;
  cin >> n >> k >> q;
  vector<ll> a(q);
  for(int i; i < q; i++) cin >> a.at(i);
  
  vector<ll> ans(n);
  for(int i; i < q; i++) ans.at(a.at(i)-1)++;
  for(int i; i < n; i++){
    if(k-q+ans.at(i) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 2176
Scanf.scanf "%d" (fun n ->
    let xy = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
    Array.sort (fun (x0, y0) (x1, y1) ->
        compare (atan2 (float y0) (float x0)) (atan2 (float y1) (float x1))) xy;
    let sum = Array.make (2 * n + 1) (0, 0) in
    for i = 1 to 2 * n do
        let (x, y) = sum.(i - 1) in
        let (vx, vy) = xy.((i - 1) mod n) in
        sum.(i) <- x + vx, y + vy
    done;
    let rec loop0 i acc =
        let rec loop1 j acc =
            if j = 2 * n + 1 || j >= i + n + 1 then loop0 (i + 1) acc else
                let (x0, y0) = sum.(i) in
                let (x1, y1) = sum.(j) in
                let x = x1 - x0 in
                let y = y1 - y0 in
                let acc = max acc (x * x + y * y) in
                loop1 (j + 1) acc
        in
        if i = 2 * n then float acc |> sqrt else loop1 (i + 1) acc
    in
    loop0 0 0 |> Printf.printf "%.12f\n"
)

Measured memory_bytes: 4332
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7
mod = 998244353


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: int(x) - 1, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)


def main():
    N = int(input())
    A = [(int(input()), n % 2) for n in range(N)]
    A.sort()

    res = 0
    for i, (_, j) in enumerate(A):
        if i % 2 != j:
            res += 1

    print(res // 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13804
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
ll INF = 1e10;

queue<int> que_g;
vector<vector<int>> edge_list;
vector<int> par;
void dfs(int);

int main()
{
	int n, q;
	cin >> n >> q;
	edge_list = vector<vector<int>>(n);
	rep(i, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge_list[a].push_back(b);
		edge_list[b].push_back(a);
	}
	vector<int>c(n);
	rep(i, q)
	{
		int p, x;
		cin >> p >> x;
		c[p - 1] += x;
	}
	par = vector<int>(n, -1);
	par[0] = 0;
	que_g.push(0);
	dfs(0);
	while (!que_g.empty())
	{
		int v = que_g.front(); que_g.pop();
		if (v>0)
		{
			c[v] += c[par[v]];
		}
	}
	rep(i, n)cs(c[i]);
	return 0;
}

void dfs(int v)
{
	vector<int> buf;
	rep(i, edge_list[v].size())
	{
		int to = edge_list[v][i];
		if (par[to]<0)
		{
			par[to] = v;
			que_g.push(to);
			buf.push_back(to);
		}
	}
	if (buf.empty())return;
	rep(i, buf.size())dfs(buf[i]);
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

int main(void)
{
    ll a,b,k; cin>>a>>b>>k;
    vector<ll> gcd;
    for(int i=1;i<=min(a,b);++i){
        if(a%i==0&&b%i==0) gcd.push_back(i);
    }
    reverse(gcd.begin(),gcd.end());
    cout<<gcd[k-1]<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b;
    int tmp;
    
    scanf("%d %d",&a, &b);
    
    tmp = a - b;
    
    if (tmp > 0){
        printf("a > b\n");
    }else if (tmp < 0){
        printf("a < b\n");
    }else {
        printf("a == b\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define MAX 101
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main()
{
  int n,m,c[MAX];
  while(cin>>n && cin>>m && n){
    fill(c,c+MAX,0);
    FOR(i,0,n){
      int d,v;
      cin>>d>>v;
      c[d]=max(c[d],v);
    }
    int ans = 0;
    FOR(i,1,m+1)ans+=c[i];
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int ll;
int main()
{
  int K, X; cin >> K >> X;
  const int MAX_NUM = 1000000;
  const int MIN_NUM = -1000000;
  
  int from = max(X - (K -1), MIN_NUM);
  int to = min(X + (K -1), MAX_NUM);
  

  for (int i=from; i<=to; i++){
    cout << i << ' ';
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int K = scanner.nextInt();

        ArrayList<Integer> ok = new ArrayList<>();

        for(int i=1; i<=100; i++){
            if(A%i ==0 && B%i==0){
                ok.add(i);
            }
        }

        Collections.sort(ok, Comparator.reverseOrder());

        System.out.println(ok.get(K-1));

    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <bitset>

using namespace std;

int n;
bitset<2005> a[2005], dp[2005];
bitset<2005> mask[2005], mask2[2005];

int main(void)
{
	cin >> n;
	char c;
	for(int i = 2; i <= n; i++){
		for(int j = 1; j < i; j++){
			cin >> c;
			a[i][j] = c-'0';
			a[j][i] = !a[i][j];
		}
	}
	
	for(int i = 1; i <= n; i++) dp[i][i] = 1;
	for(int len = 2; len <= n; len++){
		for(int l = 1; l <= n; l++){
			int r = l + len - 1;
			if(r > n) continue;
			mask[l][r-1] = 1;
			dp[l][r] = (a[r] & dp[l] & dp[r-1] & mask[l]).any();
			mask2[r][l+1] = 1;
			dp[r][l] = (a[l] & dp[l+1] & dp[r] & mask2[r]).any();
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(dp[1][i] && dp[n][i]) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

ll N;
char op[100010];
ll A[100010];
ll dp[3][100010];

int main ()
{
    cin >> N;
    op[0] = '+';
    cin >> A[0];
    REP(i,N - 1) {
        cin >> op[i + 1] >> A[i + 1];
    }

    REP(i,3)REP(j,100010) dp[i][j] = -1e18;
    dp[0][1] = A[0];

    for (int i = 1; i < N; i++) {
        if (op[i] == '+') {
            dp[0][i + 1] = dp[0][i] + A[i];
            dp[1][i + 1] = dp[1][i] - A[i];
            dp[2][i + 1] = dp[2][i] + A[i];
        } else {
            dp[0][i + 1] = dp[1][i] + A[i];
            dp[1][i + 1] = max(dp[0][i], dp[2][i]) - A[i];
            dp[2][i + 1] = dp[1][i] + A[i];
        }
        dp[1][i + 1] = max(dp[1][i + 1], dp[2][i + 1]);
        dp[0][i + 1] = max(dp[0][i + 1], dp[1][i + 1]);
    }

    ll ans = 0;
    REP(i,3) ans = max(ans, dp[i][N]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int s[n];
    for (int i = 0; i < n; i++) cin >> s[i];
    vector<int> dp(n, (int) 1e9 + 5);

    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j <= k+i; j++) {
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(s[i] - s[j]));
        }
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 3e7 + 5;
const int MOD = 1e9 + 7;

int l,r;

int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   cin >> l >> r;
   if(r - l >= 2019) {
      cout << 0 << endl;
      return 0;
   }
   int ans = 2019 * 2019;
   for(int i = l; i <= r; i++)
      for(int j = i + 1; j <= r; j++)
         ans = min(ans, (i % 2019) * (j % 2019) %2019);
    cout << ans << endl;
   return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 2e5 + 5;

int n, k;

int main()
{
  while(cin >> n >> k){
    if(n == 1 && k == 1){
      puts("-1");
    }else if(k == 0){
      for(int i = 0 ; i < (1 << n) ; i++){
        if(i) cout << " ";
        cout << i << " " << i;
      }
      cout << endl;
    }else if(k < (1 << n)){
      vector<int> v;
      v.push_back(k);
      for(int i = 0 ; i < (1 << n) ; i++)
        if(i != k)
          v.push_back(i);
      v.push_back(k);
      for(int i = (1 << n) - 1 ; i >= 0 ; i--)
        if(i != k)
          v.push_back(i);
      for(auto& x : v)
        cout << x << " ";
      cout << endl;
    }else{
      puts("-1");
    }
  } 
  return 0;
}

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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ( c > a+b ) cout << "NA" << endl;
  else {
    cout << max(0LL, c-a) << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#define s(a,b) (t=a,a=b,b=t)
char p[9],m;q,a,b,c,d,e,f,t,r;main(n){while(scanf("%d",&n),n){r=a=1,b=6,c=2,d=5,e=3,f=4;while(n--){scanf("%s",p);m=*p;if(m==76||m==82){s(c,e);s(d,f);q=m^76?s(e,f):s(c,d);}else if(77<m&&m<84){s(a,c);s(b,d);q=m^83?s(c,d):s(a,b);}else{s(a,e);s(b,f);q=m^69?s(e,f):s(a,b);}r+=a;}printf("%d\n",r);}}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;

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

    ll N;
    cin >> N;
    vector<ll> A(N + 1, 0);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll sum = 0;
    ll ans = 0;
    for (ll i = 0; i <= N; i++) {
        if (A[i] == 0) {
            ans += sum / 2;
            sum = 0;
        } else {
            sum += A[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

const int MAX_V=1e4+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> dp(n+1,MOD);
    dp[0]=-1;
    rep(i,n){
        int x=lower_bound(all(dp),a[i])-dp.begin();
        chmin(dp[x],a[i]);
    }
    int ans=0;
    rep(i,n+1) if (dp[i]!=MOD) ans=i;
    cout << ans << endl;
}


Measured memory_bytes: 3544
#include <stdio.h>

int main () {
	long long int n;
	scanf("%lld", &n);
	long long int sum = 0;
	
	for (int i = 1 ; i <= n ; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			sum += i;
		}
	}
	printf("%lld\n", sum);
	
	return 0;
}

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

using namespace std;

#define int long long

const int mod = 1e9 + 7, N = 2e5 + 5;
int n, m, a, b, fact[N], _fact[N], nans[N], ans;

int binpow(int _a, int _m) {
    int res = 1, now = _a;
    for (; _m; _m >>= 1, now = (now * now) % mod) if(_m & 1) res = (res * now) % mod;
    return res;
}

int C(int _k, int _n) {
    return ( (fact[_n] * _fact[_k]) % mod * _fact[_n - _k]) % mod;
}

signed main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> a >> b;
    fact[0] = 1; for (int i = 1; i < N; ++i) fact[i] = (fact[i - 1] * i) % mod;
    for (int i = 0; i < N; ++i) _fact[i] = binpow(fact[i], mod - 2);

    for (int i = 1; i <= n - a; ++i) {
        nans[i] = C(b - 1, b + i - 2);
        ans += (nans[i] * C(n - i, n - i + m - b - 1) ) % mod; ans %= mod;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	string str;
	cin >> str;
	string rts;
	for (int i = str.size(); i > 0; --i) {
		rts += str[i-1];
	}
	cout << rts << endl;
	return 0;
}

Measured memory_bytes: 3068
import java.util.*;

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

        Map<String, Long> m = new TreeMap<>();

        for (int i=0; i<n; i++){
            String st = sc.next();
            char[] c = st.toCharArray();
            Arrays.sort(c);
            st = new String(c);
//            System.out.println(st);
            if (m.containsKey(st)){
                m.put(st, m.get(st)+1);
            }else{
                m.put(st, 1L);
            }
        }
//        System.out.println(m);

        long ans = 0;

        for (Long v: m.values()){
            ans += v*(v-1)/2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 49968
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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! {
        n: usize,
        b: [usize; n-1],
    }
    let mut ans = 0;
    for i in 0..b.len() - 1 {
        ans += min(b[i], b[i + 1]);
    }
    ans += b[0];
    ans += b[n - 2];
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int divide2(int i) {
    int cnt = 0;
    while (i % 100 == 0) {
        i /= 100; cnt++;
    }
    return cnt;
}

int main() {
    int D, N; cin >> D >> N;

    int num = 0;
    for (int i = 0; i < N;) {
        num++;
        if (divide2(num) == D) i++; 
    }
    cout << num << endl;
}

Measured memory_bytes: 3632
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



vector<long long> vec(110000);

int main() {
 long long dp[110000];
 int a,b;
 cin>>a>>b;
 rep(i,a){
   cin>>vec.at(i);
 }
 rep(i,110000){
   dp[i]=1LL << 60;
 }
 dp[0]=0;
 rep(i,a){
   for(long long j=1;j<=b;j++){
     chmin(dp[i+j],dp[i]+abs(vec.at(i)-vec.at(i+j)));
   }
 }
 cout<<dp[a-1]<<endl;
 

}


Measured memory_bytes: 1920
n, x, y = map(int, input().split())

d = [[0] * n for i in range(n)]
x = x -1
y = y - 1
for i in range(n-1):
    d[i][i+1] = 1
    for j in range(i+2, n):
        d[i][j] = min(j-i, abs(x-i)+1+abs(y-j))

cnt = [0] * (n+1)
for i in range(n-1):
    for j in range(i+1, n):
        mind = d[i][j]
        cnt[mind] += 1

for i in range(1, n):
    print(cnt[i])
    

Measured memory_bytes: 83192
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
  int N;
  cin>>N;
  int h[N+1];
  for(int i=1;i<=N; ++i) cin>>h[i];
  int dp[N+1];
  dp[1]=0;
  dp[2]=abs(h[2]-h[1]);
  for(int i=3; i<=N; ++i){
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<dp[N]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define s(a, x, y) sort(a.begin()+x, a.begin()+y);
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
ll a, b, c, d, e;
int main() {
	cin>>a>>b;
	if(b%2!=0||b>4*a||b<2*a) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3636
//ガード句を適切に置くと定数倍変わる？
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

int res[101010];
string s;

int main(){
  cin >> s;
  int n = s.size();
  s.push_back('R');
  
  int left = 0, mid = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == s[i + 1]) continue;
    
    if(s[i] == 'R' && s[i + 1] == 'L'){
      mid = i;
      continue;
    }
    
    res[mid] = (i - mid) / 2 + ((mid - left) / 2) + 1;
    res[mid + 1] = (mid - left + 1) / 2 + (i - mid - 1) / 2 + 1;
    left = i + 1;
  }
  
  rep(i, n) cout << res[i] << ((i == n - 1)? "\n" : " ");
    
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;


int main(){
  int n; string s; cin >> n >> s;
  
  rep(i,s.size()){
    int tmp;
    tmp = s[i] - 'a' + n;
    if(tmp >= -6) tmp -= 26;
    char ans = 'a' + tmp;
    cout << ans;
  }
  
  return 0;
}

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

using namespace std;

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


int main(){
    string s;
    cin >> s;
    string w[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for (int i = 0; i < 7; i++){
        if (w[i] == s){
            cout << 7 - i << endl;;
        }
    }
}

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

int main()
{
    int n; cin>>n;
    vector<long> a(n); for(auto& e: a) cin>>e;
    vector<long> b(n); for(auto& e: b) cin>>e;

    for(int T=0; T<10000; ++T) {
        long x=0;
        for(int i=0; i<n; ++i) {
            if (a[i]<b[i]) {
                long t=(b[i]-a[i]+1)/2;
                x+=t;
                a[i]+=2*t;
            }
        }
        for(int i=0; i<n; ++i) {
            if (a[i]>b[i] && x>0) {
                long t=min(x, a[i]-b[i]);
                b[i]+=t;
                x-=t;
            }
        }
    }
    cout<<(a==b ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 384
#include <cstdint>

class modint {
  using u64 = std::uint_fast64_t;

public:
  static u64 mod;

  u64 v;

  modint(const u64 x = 0) : v(x % mod) {}
  modint operator+(const modint rhs) const { return modint(*this) += rhs; }
  modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
  modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
  modint operator/(const modint rhs) const { return modint(*this) /= rhs; }
  modint &operator+=(const modint rhs) {
    v += rhs.v;
    if (v >= mod)
      v -= mod;
    return *this;
  }
  modint &operator-=(const modint rhs) {
    if (v < rhs.v)
      v += mod;
    v -= rhs.v;
    return *this;
  }
  modint &operator*=(const modint rhs) {
    v = v * rhs.v % mod;
    return *this;
  }
  modint &operator/=(modint rhs) {
    u64 exp = mod - 2;
    while (exp != 0) {
      if (exp % 2 != 0)
        *this *= rhs;
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typename modint::u64 modint::mod = 0;

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  using mint = modint;

  mint::mod = 1000000007;

  int n, x;
  std::cin >> n >> x;
  std::vector<int> s(n);
  for (auto &e : s) {
    std::cin >> e;
  }
  std::sort(s.begin(), s.end());

  std::vector<std::vector<mint>> dp(n + 1, std::vector<mint>(x + 1));

  for (int i = 0; i <= x; ++i) {
    dp[0][i] = i;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= x; ++j) {
      dp[i + 1][j] = dp[i][j] * i + dp[i][j % s[i]];
    }
  }

  std::cout << dp[n][x].v << std::endl;
}


Measured memory_bytes: 158592
# Coding is about expressing your feeling, and
# there is always a better way to express your feeling_feelme
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=int(1e9 + 7)

n=ii1()
arr=iia()
count=0
for i in range(n):
    if (i+1)%2==1:
        if arr[i]%2==1:
            count+=1
print(count)


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

using namespace std;

int main()
{
    int q, k;
    cin >> q;
    set <pair<int,int>> Se;
    set <pair<int,int>> :: iterator it;
    long long S0=0, S1=0, S2=0, l=0, r=0, a, b, v;
    for (int i = 0; i < q; i++)
    {
        cin >> k;
        if (k == 1)
        {
            cin >> a >> b;
            S0 += b;
            if (Se.size() == 0)
            {
                Se.insert({a,0});
                it = Se.find({a,0});
                v = a;
            }
            else
            {
                Se.insert({a,i});
                if (a < v)
                {
                    l++;
                    S1 += a;
                }
                else
                {
                    S2 += a;
                    r++;
                }
                if (r - l >= 2)
                {
                    l++;
                    r--;
                    S1 += v;
                    it++;
                    S2 -= it->first;
                }
                else if (l - r >= 1)
                {
                    l--;
                    r++;
                    S2 += v;
                    it--;
                    S1 -= it->first;
                }
                v = it->first;
            }
        }
        else
        {
            cout << v << " " << S0 + (v*l - S1) + (S2 - v*r) << "\n";
        }
    }
    return 0;
}


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

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

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

    int c[3][3];
    int a[3];
    int b[3];
    int sub_a2, sub_a3, sub_a22, sub_a33;

    REP(i, 3) REP(j, 3){
        cin >> c[i][j];
    }

    a[0] = 0;
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    if (a[1] == c[1][1] - b[1] && a[1] == c[1][2] - b[2]){
        if (a[2] == c[2][1] - b[1] && a[2] == c[2][2] - b[2]){
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	ll n;
	vector<ll>list;

	cin >> n;

	ll index = 1, sum=0;

	for (int i = 0; i < n; i++) {
		ll num;
		cin >> num;
		list.push_back(num);
	}

	for (int i = 0; i < n; i++) {
		if (list[i] == index) {
			index++;
		}
		else {
			sum++;
		}
	}

	if (sum == n){
		cout << -1 << endl;
	}
	else {
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int H = scanner.nextInt();
        int W = scanner.nextInt();
        scanner.nextLine();//Tricky

        String[][] S = new String[W][H];

        for (int i = 0; i < H; i++) {
            String[] inputArray = scanner.nextLine().split("");
            for (int j = 0; j < W; j++) {
                S[j][i] = inputArray[j];
            }
        }

        boolean isPossible = true;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ("#".equals(S[j][i]) && !isExistingPound(S, j, i)) {
                    isPossible = false;
                    break;
                }
            }
        }
        if (isPossible) {
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }
    }

    private static boolean isExistingPound(String[][] S, int i, int j) {
        return isEquals(S, i, j - 1)
                || isEquals(S, i - 1, j)
                || isEquals(S, i + 1, j)
                || isEquals(S, i, j + 1);
    }

    private static boolean isEquals(String[][] S, int i, int j) {
        try {
            return "#".equals(S[i][j]);
        } catch (Exception e) {
            return false;
        }
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  if(n == 1){
    print(1);
    return 0;
  }
  int now = 0;
  rep(i,n){
    now += i;
    if(now >= n)break;
  }
  
  
  int tmp = n;
  int cnt = 1;
  while(tmp){
    if(cnt != abs(now-n)){
      tmp -= cnt;
      print(cnt);
    }
    cnt++;
  }

  return 0;
}



Measured memory_bytes: 256
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N)]

AB.sort(key=lambda x:x[0])

ans = 0
for a,b in AB:
    if b < M:
        ans += a*b
        M -= b
    else:
        ans += a*M
        break
print(ans)

Measured memory_bytes: 18128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    char A[10][10];
    for(int i=0; i<10; i++)
        fill_n(A[i], 10, '.');

    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++)
            cin >> A[i][j];

    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(A[i][j] == '.') continue;
            if((A[i-1][j] == '#' && A[i][j-1] == '#') ||
                    (A[i+1][j] == '#' && A[i][j+1] == '#')){
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;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>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

template< typename T >
struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g) {
    for(int k = 0; k < g.size(); k++) {
        for(int i = 0; i < g.size(); i++) {
            for(int j = 0; j < g.size(); j++) {
                if(g[i][k] == INF || g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}


signed main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    cin >> r;
    Matrix<int> mat(N + 1, vector<int>(N + 1, INF));
    for (int i = 0; i < M; i++) {
        int A, B, C;
        cin >> A >> B >> C;
        mat[A][B] = C;
        mat[B][A] = C;
    }
    warshall_floyd(mat);
    int ans = INF;
    sort(r.begin(), r.end());
    do {
        int temp = 0;
        for (int i = 0; i < R - 1; i++) {
            temp += mat[r[i]][r[i + 1]];
        }
        ans = min(ans, temp);
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
}


Measured memory_bytes: 512