akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    private static int[][] c;
    private static int[] min;

    private static void dfs(int currentIdx, int sum, int startIdx) {
        for (int i = 0; i <= 9; i++) {
            if (i == currentIdx || sum + c[currentIdx][i] >= min[startIdx]) {
                continue;
            }
            if (i == 1) {
                min[startIdx] = Math.min(min[startIdx], sum + c[currentIdx][i]);
            }
            dfs(i, sum + c[currentIdx][i], startIdx);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        c = new int[10][10];
        int[][] a = new int[h][w];
        min = new int[10];
        for (int i = 0; i <= 9; i++) {
            for (int j = 0; j <= 9; j++) {
                c[i][j] = sc.nextInt();
                if (j == 1) {
                    min[i] = c[i][j];
                }
            }
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i <= 9; i++) {
            dfs(i, 0, i);
        }
        int ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (a[i][j] == -1 || a[i][j] == 1) {
                    continue;
                }
                ans += min[a[i][j]];
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 50092
#include<bits/stdc++.h>
using namespace std;
#define fast_input ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
   fast_input; 
   int n;
   cin>>n;
   long int a[n];
   int i;
   for(i=0;i<n;i++)
     cin>>a[i];
   int maxm=0;
   int cnt=0;
   for(i=n-1;i>0;i--){
       if(a[i-1]>=a[i]){
           cnt++;
       }
       else{
           maxm=max(cnt,maxm);
           cnt=0;
       }
   }
   maxm=max(cnt,maxm);
   cout<<maxm<<endl;
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
List=[]
for i in range(N):
  List.append(list(map(int,input().split())))
List_K=[]
List_A=[]
for j in range(N):
  List_K.append(List[j][0])
  List_A.append(List[j][1:])
count=0
for k in range(M+1):
  count1=0
  for l in range(N):
    if k in List_A[l]:
      count1+=1
  if count1==N:
    count+=1
print(count)
    

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	if(S.size()%2==1) return _P("No\n");
	FOR(i,S.size()) {
		if(i%2==0 && S[i]!='h') return _P("No\n");
		if(i%2==1 && S[i]!='i') return _P("No\n");
	}
	cout<<"Yes"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    if i < N-1 and a[i] == i+1:
        ans += 1
        a[i], a[i+1] = a[i+1], a[i]
if a[-1] == N:
    ans += 1
    a[-1], a[-2] = a[-2], a[-1]
print(ans)

Measured memory_bytes: 14008
#include<stdio.h>
int n,min=0x7fffffff,max=-0x7fffffff;
long long sum;
int data[10000];
int main(){
 scanf("%d",&n);
 for(int i=0;i<n;i++){
  scanf("%d",&data[i]);
  sum+=data[i];
  min=min>data[i]?data[i]:min;
  max=max<data[i]?data[i]:max;
 }
 printf("%d %d %lld\n", min, max, sum);
 return 0;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll mod=1e9+7;
typedef vector<vector<ll> > Matrix;
Matrix ones(int n) {
	Matrix r(n,vector<ll>(n));
	fore(i,0,n)r[i][i]=1;
	return r;
}
Matrix operator*(Matrix &a, Matrix &b) {
	int n=SZ(a),m=SZ(b[0]),z=SZ(a[0]);
	Matrix r(n,vector<ll>(m));
	fore(i,0,n)fore(j,0,m)fore(k,0,z)
		r[i][j]+=a[i][k]*b[k][j],r[i][j]%=mod;
	return r;
}
Matrix be(Matrix b, ll e) {
	Matrix r=ones(SZ(b));
	while(e){if(e&1LL)r=r*b;b=b*b;e/=2;}
	return r;
}

ll n, k;

int main(){FIN;
	cin >> n >> k;
	Matrix g(n,vector<ll>(n));
	fore(x,0,n)fore(y,0,n)cin>>g[x][y];
	g = be(g,k);
	ll ans = 0;
	fore(x,0,n)fore(y,0,n)ans=(ans+g[x][y])%mod;
	cout<<ans<<"\n";
}

Measured memory_bytes: 384
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

s,t = ns().split()
a,b = nm()
u = ns()
if u == s:
    a -= 1
else:
    b -= 1
print(a,b)


Measured memory_bytes: 3316
from collections import Counter
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    d = Counter(A)
    # print(d)
    ans = sum(A)

    for i in range(Q):
        b, c = map(int, input().split())
        if d[b] != 0:
            ans -= d[b] * b
            ans -= d[c] * c
            d[c] += d[b]
            d[b] = 0
            ans += d[c] * c

        print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 20992
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int N, Q, q;
	long long int D, d[500001], x[500001];
	scanf("%d %lld", &N, &D);
	x[0]=D;
	for(int i=1; i<=N; i++){
		scanf("%lld", &d[i]);
		x[i]=min(x[i-1], abs(x[i-1]-d[i]));
	}
	scanf("%d", &Q);
	long long int imp[500001];
	imp[N]=0;
	for(int i=N-1; i>=0; i--){
		if(abs(imp[i+1]+1-d[i+1])>=imp[i+1]+1){
			imp[i]=imp[i+1];
		}else{
			imp[i]=imp[i+1]+d[i+1];
		}
	}
	for(int i=0; i<Q; i++){
		scanf("%d", &q);
		if(x[q-1]>=imp[q]+1){
			printf("%s\n", "YES");
		}else{
			printf("%s\n", "NO");
		}
	}
	return 0;
}

Measured memory_bytes: 13568
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;
//import org.apache.commons.lang3.StringUtils;
 
 
/**
 *
 * @author aj
 */
public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            String[] nmc = in.readLine().split(" ");
            int n = Integer.parseInt(nmc[0]);
            int m = Integer.parseInt(nmc[1]);
            
            TreeMap<Long,List<Integer>> map = new TreeMap();
            long c = 0;
            long[] a = new long[n];
            long[] b = new long[n];
            for(int i=0;i<n;i++){
                
                String[] ab = in.readLine().split(" ");
                a[i] = Integer.parseInt(ab[0]);
                b[i] = Integer.parseInt(ab[1]);
                if  (map.get(a[i])==null) map.put(a[i], new LinkedList());
                map.get(a[i]).add(i);
            }
            int nc = 0;
            
            for(long key:map.keySet()){
                for(int i:map.get(key)){
                    c += Math.min(m, b[i])*key;
                    m -= Math.min(m, b[i]);
                }
            }

            out.write((c+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        
    }
    
    
    
}

Measured memory_bytes: 65460
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		MoveAndWin solver = new MoveAndWin();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}
	static class MoveAndWin {
		private int n;
		private int a;
		private int b;

		private String output;
		private Scanner scanner;

		public MoveAndWin() {
			this.scanner = new Scanner(System.in);
		}

		public void readInput() {
			n = Integer.parseInt(scanner.next());
			a = Integer.parseInt(scanner.next());
			b = Integer.parseInt(scanner.next());
		}

		public void solve() {
			if(Math.abs(a-b)%2 != 0) {
				output = "Borys";
			} else {
				output = "Alice";
			}
		}

		public void writeOutput() {
			System.out.println(output);
		}

	}
}

Measured memory_bytes: 21844
a,b,m = map(int,input().split())
a_L = list(map(int,input().split()))
b_L = list(map(int,input().split()))
ans = min(a_L) + min(b_L)
for _ in range(m):
    x,y,c = map(int,input().split())
    price = a_L[x-1] + b_L[y-1] - c
    ans = min(ans,price)
print(ans)

Measured memory_bytes: 70508
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		long K = nextLong();
		int[] A = nextInts();
		int[] to = new int[N+1];
		to[0]=1;
		HashMap<Integer,Integer> map = new HashMap<>();
		map.put(1, 0);
		int loopN=0;
		for(int i=1;i<=N;i++){
			to[i]=A[to[i-1]-1];
			if(map.containsKey(A[to[i-1]-1])){
				loopN = i-map.get(A[to[i-1]-1]);
				break;
			}
			map.put(A[to[i-1]-1], i);
		}
		int idx;
		if(K<map.size()){
			idx=(int)K;
		}else{
			idx=(int)((K-(map.size()+1-loopN))%loopN)+map.size()+1-loopN;
		}
		System.out.println(to[idx]);
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 67568
#include<bits/stdc++.h>
using namespace std;
long long n,a,x,ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;++i)
	{
		cin>>a;
		if(a<x) ans+=x-a;
		else x=a;
	}
	cout<<ans;
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;


int main() {
    cin >> n >> m;
    if (n % 2 > 0) {
        rep(i, m) {
            cout << (i + 1) << " " << (2 * m - i) << endl;
        }
        return 0;
    } else {
        rep(i, m) {
            if (n - i - i - 1 <= n / 2) {
                cout << (i + 2) << " " << (n - i) << endl;
            } else {
                cout << (i + 1) << " " << (n - i) << endl;
            }
        }
    }


    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int a[3];
  rep(i,3) cin>>a[i];
  sort(a,a+3);
  cout<<a[0]+a[1]<<endl;

  return 0;
}







Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
int N;
double x[10];
string u[10];
void solve(){
    double ans=0.0;
    for(int i=0;i<N;i++){
        if(u[i]=="BTC") x[i]=380000.0*x[i];
        ans+=x[i];
    }
    cout<<ans<<"\n";
    }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i=0;i<N;i++) cin>>x[i]>>u[i];
    solve();
}

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

vector<pair<ll,ll>> factorize(ll N){
    ll n = N;
    vector<pair<ll,ll>> v;
    for(ll i = 2; i*i<=n; i++){
        if(n % i != 0)continue;
        v.push_back(make_pair(i,0));
        while(n % i == 0){
            v.back().second++;
            n /= i;
        }
    }
    if(n != 1)v.push_back(make_pair(n,1));
    return v;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> memo(N+1,0);
    rep(i,N){
        auto v = factorize(i+1);
        rep(j,v.size()){
            memo[v[j].first] += v[j].second;
        }
    }

    ll tot = 1;
    for(auto& e:memo){
        tot *= (e+1);
        tot %= mo;
        //cout << e << " ";
            
    }
    //cout << endl;

    cout << tot << endl;

}
/*
 1  2 3 4
24 12 8 6

1    2  3  4  5  6  8 10
120 60 40 30 24 20 15 12

1   2   3   4   5   6   8  9  10 12 15 16 18 20 24
720 360 240 180 144 120 90 80 72 60 48 45 40 36 30
*/

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
static const int INF = 1000010000;
int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int /*from,*/to,cost;};

int h,w;
char field[114][514];
bool visited[114][514];

signed main(){
    cin >> h >> w;
    int s = 0;
    REP(i,h){
        scanf("%s",&field[i]);
        REP(j,w) if(field[i][j]=='.') s++; 
    }

    queue<pair<P,int> > que;
    que.push(MP(P(0,0),1));
    visited[0][0] = true;
    int m=-INF;
    while(!que.empty()){
        pair<P,int> c = que.front();que.pop();
        if(c.FI==P(h-1,w-1)) m = c.SE;
        REP(i,4){
            int nx,ny;
            nx = c.FI.FI + dx4[i];
            ny = c.FI.SE + dy4[i];
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&!visited[nx][ny]){
                if(field[nx][ny]=='.'){
                    que.push(MP(P(nx,ny),c.SE+1));
                    visited[nx][ny] = true;
                }
            }
        }
    }

    if(m==-INF) puts("-1");
    else printf("%d\n",s-m);
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
const int N = 2e5 + 87;
int n, c[N], lt[N], rt[N], tp, sz[N];
vector<int> g[N], g2[N];
vector<int> t[N];
void dfs(int u, int p)
{
    auto it = find(g[u].begin(), g[u].end(), p);
    if (it != end(g[u]))
        g[u].erase(it);
    lt[u] = tp++;
    sz[u] = 1;
    for (int v : g[u])  {
        dfs(v, u);
        sz[u] += sz[v];
    }
    rt[u] = tp;
}
bool in (int u, int v)
{
    return lt[v] <= lt[u] && rt[u] <= rt[v];
}
void build_g2(vector<int> & a)
{
    sort(a.begin(), a.end(), [&] (int i, int j) {return lt[i] < lt[j];});
    vector<int> st = {0};
    g2[0].clear();
    for (int u : a) {
        while (!in(u, st.back()))
            st.pop_back();
        g2[st.back()].push_back(u);
        st.push_back(u);
    }
}
ll gao(int u)
{
    ll ret = 0;
    int i = 0;
    ll s = g[u].size() ? sz[g[u][0]] : 0;
    for (int v : g2[u]) {
        while (i < g[u].size() && !in(v, g[u][i])) {
            ret += s * (s + 1) / 2;
            ++i;
            if (i < g[u].size())
                s = sz[g[u][i]];
        }
        s -= sz[v];
        ret += gao(v);
    }
    while (i < g[u].size()) {
        ret += s * (s + 1) / 2;
        ++i;
        if (i < g[u].size())
            s = sz[g[u][i]];
    }
    return ret;
}
ll solve(vector<int> & a)
{
    build_g2(a);
    return n * (n + 1ll) / 2 - gao(0);
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> c[i];
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    g[0].push_back(1);
    dfs(0, 0);
    for (int i = 1; i <= n; ++i)
        t[c[i]].push_back(i);
    for (int i = 1; i <= n; ++i)
        cout << solve(t[i]) << '\n';
}


Measured memory_bytes: 46560
N = int(input())
p = [int(x) for x in input().split()]
ans = 0
for i in range(N - 2):
    if p[i] < p[i + 1] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
        ans += 1
print("{}".format(ans))


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

using namespace std;

typedef pair<int, int> P;

int N;
P swimmer[50];
map<int, vector<P> > lane[2];

int main(){
	while(cin >> N, N){
		lane[0].clear();
		lane[1].clear();

		for(int i = 0; i < N; i++){
			cin >> swimmer[i].first >> swimmer[i].second;
			swimmer[i].second *= 2;
			lane[0][swimmer[i].first].push_back(swimmer[i]);	
		}

		int time = 0;
		while(lane[0].size() > 0 || lane[1].size() > 0){
			int i;
			if(lane[0].size() > 0 && (lane[1].size() == 0 || (*(lane[0].begin())).first < (*(lane[1].begin())).first)){
				i = 0;
			}else{
				i = 1;
			}
			auto h = *(lane[i].begin());
			time = h.first;
			lane[i].erase(h.first);
			sort(h.second.begin(), h.second.end());
			for(auto p : h.second){
				if(p.second > 1){
					p.second--;
					int nt = time + p.first;
					if(lane[(i+1)%2].size() > 0 && (*(lane[(i+1)%2].rbegin())).first >= nt){
						(*(lane[(i+1)%2].rbegin())).second.push_back(p);
					}else{
						lane[(i+1)%2][nt].push_back(p);
					}
				}
			}
		}
		cout << time << endl;
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  int ans = 0, tmp = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] >= H[i + 1]) {
      tmp++;
      ans = max(ans, tmp);
    } else {
      tmp = 0;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int N, M, xo[100009], ap[100009], t[100009];
vector < int > v[100009], ord;

void dfs (int nod, int tata)
{
    ap[nod] = 2;
    for (auto it : v[nod])
        if (ap[it] == 0)
            t[it] = nod, dfs (it, nod);
        else
        if (it != tata && ap[it] == 2)
        {
            printf ("%d %d\n", it, nod);
            xo[it] ^= 1;
        }
    ap[nod] = 1;
    ord.push_back (nod);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
if (M & 1) printf ("-1\n");
else
{
    for (int i=1; i<=M; i++)
    {
        int x, y;
        scanf ("%d %d", &x, &y);
        v[x].push_back (y);
        v[y].push_back (x);
    }
    dfs (1, -1);
    for (auto it : ord)
        if (it != 1)
        {
            if (xo[it]) printf ("%d %d\n", it, t[it]);
            else printf ("%d %d\n", t[it], it), xo[t[it]] ^= 1;
        }
}
return 0;
}


Measured memory_bytes: 14840
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s[0]=='S') cout<<"Cloudy"<<endl;
  else if(s[0]=='R') cout<<"Sunny"<<endl;
  else if(s[0]=='C') cout<<"Rainy"<<endl;
  else ;
  return 0;

}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

ll cnt = 1 ;

void DFS(vvll &g,vvll &ans,ll p){
	if(ans.at(p).at(0)!=-1) return ;
	ans.at(p).at(0) = cnt ;
	cnt++ ;
	for(int i=0;i<g.at(p).size();i++){
		DFS(g,ans,g.at(p).at(i)) ;
	}
	ans.at(p).at(1) = cnt ;
	cnt++ ;
}

int main(){
	ll n ; cin >> n ;
	vvll g(n,vll(0)) ;
	for(int i=0;i<n;i++){
		ll a,b ;
		cin >> a >> b ;
		vll c(b) ;
		for(int j=0;j<b;j++) cin >> c.at(j) ;
		sort(all(c)) ;
		for(int j=0;j<b;j++) g.at(i).emplace_back(c.at(j)-1) ;
	}
	vvll ans(n,vll(2,-1)) ;
	for(int i=0;i<n;i++){
		if(ans.at(i).at(0)==-1) DFS(g,ans,i) ;
	}
	for(int i=0;i<n;i++) cout << i+1 << " " << ans.at(i).at(0) << " " << ans.at(i).at(1) << "\n" ;
}



Measured memory_bytes: 3160
extractAandB :: [String] -> (Int, Int)
extractAandB xs = (read (xs!!0), read (xs!!1))

findSuitableValue :: (Int, Int) -> Int
findSuitableValue (a, b) = if null potentialSolutions then -1 else fromIntegral (head potentialSolutions)
  where
    potentialSolutions = (filter (\x -> floor ((fromIntegral x :: Float) * 0.08) == a && floor ((fromIntegral x :: Float) * 0.1) == b) . takeWhile (\x -> (fromInteger x :: Float) * 0.08 < (fromIntegral (a + 1)) && (fromInteger x:: Float) * 0.1 < (fromIntegral (b + 1)))) [10..]

main :: IO ()
main = do
  line <- getLine
  let out = (findSuitableValue . extractAandB . words) line
  putStrLn (show out)


Measured memory_bytes: 508
#include<cstdio>
#include<cstring>
#include<string>

char a[105];
char b[105];

int main()
{
	scanf("%s",a);
	scanf("%s",b);
	int lenx = strlen(a);
	int leny = strlen(b);
	if(lenx != leny){
		if(lenx < leny) {
			printf("LESS");
			return 0;
		}
		else {
			printf("GREATER");
			return 0;
		}
	}
	else {
		int x = strcmp(a,b);
		if(x > 0) printf("GREATER\n");
		else if(x < 0) printf("LESS\n");
		else printf("EQUAL\n");
		return 0;
	}
}

Measured memory_bytes: 128
/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

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

typedef long long                       ll;
typedef unsigned long long              ull;
typedef long double                     ld;

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

#define      cube(x)                    (x*x*x)
#define      sqr(x)                     (x*x)
#define      PI                         acos(-1)

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

int main()
{
    //string ;
    ll a,b,c,m=100,count=0;
    cin>>a;
    while(m<a)
    {
        m+=m/100;
        count++;
    }
    cout<<count<<endl;
    return 0;
}




Measured memory_bytes: 3608
K = int(input())

import fractions

A = {}
sum = 0

for i in range(K):
    for j in range(K):
        if fractions.gcd(i+1,j+1) in A:
            A[fractions.gcd(i+1,j+1)] += 1
        else:
            A[fractions.gcd(i+1,j+1)] = 1

for key in A:
    for i in range(K):
        sum += fractions.gcd(key,i+1)*A[key]

print(sum)


Measured memory_bytes: 10680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {
	
	int n, l;
	cin >> n >> l;
	vi apple(n);
	int sum = 0;
	rep(i, n) {
		apple[i] = l + i;
		sum += apple[i];
	}
	
	int ans;
	int taste = INF;
	rep(i, n) if (taste > abs(apple[i])) {
		taste = abs(apple[i]);
		ans = sum - apple[i];
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]){
    int h,m,s,S;
    scanf("%d", &S);
    h=S/3600;
    m=(S-h*3600)/60;
    s=S-(h*3600+m*60);
    printf("%d:%d:%d\n",h, m, s);
    return 0;
}

Measured memory_bytes: 592
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    /*cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);*/
    int h, w;
    cin >> h >> w;
    std::string s;
    for (int i = 0; i < h; i++) {
        cin >> s;
        cout << s << endl << s << endl;
    }

    return 0;
}


Measured memory_bytes: 504
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "z");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    auto x = aryread();
    if (m == 1 || n >= m)
    {
        writeln(0);
        return;
    }

    x.sort();
    // x.writeln();
    auto gap = new long[](m - 1);
    foreach (i; iota(m - 1))
    {
        gap[i] = x[i + 1] - x[i];
    }
    // gap.writeln();
    gap.sort();
    auto s = gap.sum();
    foreach (j; iota(n - 1))
        s -= gap[$ - 1 - j];
    s.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 4488
// Problem : B - I miss you...
// Contest : AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define pb emplace_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inf LLONG_MAX
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s;cin>>s;
for(int i=0;s[i];i++)
s[i]='x';
cout<<s;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
    solve();
}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	string A,B,C;

	cin >> A >> B >> C;

	cout << ((A[A.length()-1] == B[0] && B[B.length()-1] == C[0]) ? "YES" : "NO") << endl;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=300005;
int v[maxn],n,m;
inline void solve(int l,int r){
	for(int i=1,lastv=1e9,last;i<=r;i=last+1){
		if(i<=l)
			last=min(l/(l/i),r/(r/i));
		else
			last=r;
		if(l/i<lastv){
			v[l/i+1]++,v[min(lastv,r/i)+1]--;
			lastv=l/i;
		}
	}
}
int main(){
	read(n);read(m);
	rep(i,1,n){
		int l,r;read(l);read(r);
		solve(l-1,r);
	}
	rep(i,1,m)printf("%d\n",v[i]+=v[i-1]);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  int x = N * 800;
  int y = (N / 15) * 200;
  cout << x - y << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  string s;
  cin >>s;
  
  int c=-1;
  int f=-1;
  
  rep(i,s.size()) {
    if(s[i]=='C') c=i;
    if(s[i]=='F') f=i;
  }
  
  cout << (c>=0 && f>=0 && c<f?"Yes":"No") << endl;
  
  
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,a,n) for(ll i=a;i<(n);++i)
#define repr(i,n) for(ll i=n;i>=0; --i)
#define repr2(i,a,n) for(ll i=n;i>=a; --i)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define VEC(v) vector<v >

#define INT(...) int __VA_ARGS__;IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;IN(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;IN(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;IN(__VA_ARGS__)

int scan(){ return getchar(); }
void scan(int& a){ cin>>a; }
void scan(long long& a){ cin>>a; }
void scan(char &a){cin>>a;}
void scan(double &a){ cin>>a; }
void scan(long double& a){ cin>>a; }
void scan(char a[]){ scanf("%s", a); }
void scan(string& a){ cin >> a; }
template<class T> void scan(vector<T>&);
template<class T, size_t size> void scan(array<T, size>&);
template<class T, class L> void scan(pair<T, L>&);
template<class T, size_t size> void scan(T(&)[size]);
template<class T> void scan(vector<T>& a){ for(auto& i : a) scan(i); }
template<class T> void scan(deque<T>& a){ for(auto& i : a) scan(i); }
template<class T, size_t size> void scan(array<T, size>& a){ for(auto& i : a) scan(i); }
template<class T, class L> void scan(pair<T, L>& p){ scan(p.first); scan(p.second); }
template<class T, size_t size> void scan(T (&a)[size]){ for(auto& i : a) scan(i); }
template<class T> void scan(T& a){ cin >> a; }

void IN(){}
template <class Head, class... Tail> void IN(Head& head, Tail&... tail){ scan(head); IN(tail...); }

int in() {int x;cin>>x;return x;}
ll llin() {unsigned long long x;cin>>x;return x;}

#define ios cin.tie(NULL), ios_base::sync_with_stdio(false)
#define cfs(n) cout<<fixed<<setprecision((n))
#define endl '\n'
#define ret return 0

constexpr ll mod=998244353;
constexpr ll mod2=10e9+7;
const double PI = 3.1415926535897932384626433832795028841971; //acos(-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;}
// endmacro

int main(){
  ios; cfs(15);
  INT(n);
  VEC(string) v(n);
  rep(i, n) {
    string a;
    cin >> a;
    v[i]=a;
  }

  int a,b,c,d;
  a=b=c=d=0;

  for(string s : v) {
    if(s == "AC") ++a;
    else if(s == "WA") ++b;
    else if(s=="TLE") ++c;
    else if(s=="RE") ++d;
  }

  cout <<"AC x " << a << endl;
  cout <<"WA x " << b << endl;
  cout <<"TLE x " << c << endl;
  cout <<"RE x " << d << endl;
  ret;
}


Measured memory_bytes: 6344
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> b(n);
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		b[i] = a[i];
		mp[b[i]]++;
	}
	sort(all(b));
	for (int i = 0; i < n - 1; i++) {
		mp[b[i + 1]] += mp[b[i]];
	}
	for (int i = 0; i < n; i++) a[i] = mp[a[i]];
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == i % 2) cnt++;
	}
	cout << cnt / 2 << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main(void) {

    int n;
    cin>>n;
    vll v(n);
    rep(i,n)cin>>v[i];
    ll ans=INF;
    for(int x=0;x<110;x++){
        ll tmp=0;
        rep(i,n){
            tmp+=(x-v[i])*(x-v[i]);
        }
        chmin(ans,tmp);
    }
    fin(ans);
}

Measured memory_bytes: 256
/*
[agc024] A - Fairness
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

ll A, B, C, K;

ll solve() { return (K % 2 == 0 ? A - B : B - A); }

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int N=1000010;
int n,a[N],ans=1;
char s[N],t[N];
int main()
{
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	bool flag=0;
	ref(i,1,n)if(s[i]!=t[i])flag=1;
	if(!flag)
	{
		printf("0\n");
		return 0;
	}
	int R=n,L=R,atop=n+1,cnt=n,acnt=n,times=0;
	while(R>0)
	{
		L=R;
		while(L>1&&t[L-1]==t[R])L--;
		if(L<cnt)cnt=L;
		while(cnt>0&&s[cnt]!=t[L])cnt--;
		if(!cnt){
			printf("-1\n");
			return 0;
		}
		if(cnt==L){
			atop=n+1;acnt=n;R=L-1;
			times=0;
			continue;
		}
		if(atop>acnt){
			times++;
			a[--atop]=cnt+times;
			ans=max(ans,2);
			R=L-1;
			continue;
		}
		while(acnt>=atop&&a[acnt]-times>L)acnt--;
		ans=max(ans,acnt-atop+3);
		times++;
		a[--atop]=cnt+times;
		R=L-1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
inline int read(void){
	int num = 0, f = 1;
	char ch;
	while(!isdigit(ch=getchar())) if(ch == '-') f = -1;
	while(isdigit(ch)) num = num*10 + ch-'0', ch = getchar();
	return num * f;
}
int main()
{
	int x = read();
	if(x >= 30) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
int n,k,ans[300005];
int main(){
	scanf("%d%d",&k,&n);
	if(!(k&1)){
		printf("%d ",k/2);for(int i=2;i<=n;i++)printf("%d ",k);
		return 0*puts("");
	}
    int cnt=n,lim=n>>1;
    for(int i=1;i<=n;i++)ans[i]=(k+1)>>1;
    for(int i=1;i<=lim;i++)
        if(ans[cnt]==1)cnt--;
        else{ans[cnt++]--;for(;cnt<=n;cnt++)ans[cnt]=k;cnt--;}
    for(int i=1;i<=cnt;i++)printf("%d ",ans[i]);
	return 0*puts("");
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = INF;
    for(long long i=1; (i*i)<=N; i++){
        if(N%i==0 and ans>(i+(N/i))){
            ans = i + (N/i);
        }
    }
    cout << ans - 2<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

int prim(){
    int u,minv;
    int d[MAX],p[MAX],color[MAX];

    for(int i=0;i<n;i++){
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }

    d[0]=0;

    while(1){
        minv=INFTY;
        u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)
            break;
        color[u]=BLACK;
        for(int v=0;v<n;v++){
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if(d[v]>M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    int sum=0;
    for(int i=0;i<n;i++)
        if(p[i]!=-1)
            sum+=M[i][p[i]];
    return sum;
}

int main(){
    cin>>n;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int e;cin>>e;
            M[i][j]=(e==-1)?INFTY:e;
        }
    }

    cout<<prim()<<endl;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int C[105][105];
int n;
int main()
{
    n = 100;
    memset(C, 0, sizeof(C));
    for (int i = 0; i <= n; i++)
    {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++)
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
	int t, m;
	cin >> t >> m;
	cout << C[t][2] + C[m][2];
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }


int main()
{
    int N;
    lint D;
    cin >> N >> D;
    vector<lint> A(N);
    REP(i, N) cin >> A[i];
    lint res = accumulate(A.begin(), A.end(), 0LL);
    REP(i, N - 1) Min(A[i + 1], A[i] + D);
    IREP(i, N - 1) Min(A[i], A[i + 1] + D);
    cout << res + accumulate(A.begin(), A.end(), 0LL) - A[0] - A[N - 1] + (N - 1) * D << endl;
}


Measured memory_bytes: 1920
#include <stdio.h>
int main(){
  long int a,b=7,c,flag=0;
  scanf("%ld",&a);
  for(int i=1;i<1000000;i++){
    if(b%a==0){
     c=i;
      flag++;
      break;
    }
    b=b*10+7;
      if(b>=a){
        b%=a;
      }
    }
  if(flag==0)c=-1;
  printf("%ld",c);
  return 0;
}

Measured memory_bytes: 1732