akhauriyash/Code-Regression huggingface dataset:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis1=LI()
m=I()
lis2=LI()
c1=Counter(lis1)
c2=Counter(lis2)
for x in c2.keys():
    if c1[x]<c2[x]:
        print("NO")
        sys.exit()
print("YES")

Measured memory_bytes: 57396
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int main(){
  while(true){
    const int a = getInt();
    const int b = getInt();
    const int c = getInt();
    const int d = getInt();
    const int e = getInt();

    if(a + b + c + d + e == 0) break;

    const int na = getInt();
    const int nb = getInt();
    const int nc = getInt();

    int ans = na * a + nb * b + nc * c;

    REP(i,na + nb + 1){
      const int nnb = min(i, nb);
      const int nna = i - nnb;
      const int r = (na - nna) * a + (nb - nnb) * b;

      if(nna + nnb + nc >= d){
        const int s = (nna + nnb + nc) * e;
        if(nna * a + nnb * b + nc * c >= (nna + nnb + nc) * e)
          ans = min(ans, s + r);
      }else{
        const int s = e * d;
        if(nna * a + nnb * b + nc * c >= d * e)
          ans = min(ans, s + r);
      }
    }

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

  return 0;
}

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


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


import heapq
def main():
    N, D, A = read_values()
    M = [read_list() for _ in range(N)]
    M.sort(key=lambda l: l[0])
    Q = []

    F = 0
    res = 0
    for x, h in M:
        while Q:
            if Q[0][0] >= x:
                break
            else:
                _, f = heapq.heappop(Q)
                F -= f
        R = max((h - F - 1) // A + 1, 0)
        res += R
        F += R * A
        heapq.heappush(Q, (x + 2 * D, R * A))

    print(res)
       

if __name__ == "__main__":
    main()


Measured memory_bytes: 77600
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    // 入力を受け取る
    int n = sc.nextInt();
    int[] monsters = new int[n];
    for (int i = 0; i < n; i++) {
      monsters[i] = sc.nextInt();
    }
    // gcd(a, a2, ..., an)
    int ans = monsters[0];
    for (int i = 1; i < n; i++) {
      ans = gcd(ans, monsters[i]);
    }
    System.out.println(ans);
  }

  public static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
}


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

typedef long long ll;

map<int,int> prime_factor(int n){ //素因数分解
    map<int,int> table;
    for(int j=2;j<=n;j++){
        int tmp=j;
        for(int i=2;i<=tmp;i++){
            while(tmp%i==0){
                table[i]++;
                tmp/=i;
            }
        }
        //if(tmp!=1) table[tmp]=1;
    }
    return table;// key->素因数, value->べき乗
}

int main(){
    int N; cin >> N;
    map<int,int> prime=prime_factor(N);
    int ans=0;
    for(int i=2;i<=N;i++){
        for(int j=2;j<=N;j++){
            for(int k=2;k<=N;k++){
                if(i==j||j==k||i==k) continue;
                if(prime[i]>=4&&prime[j]>=4&&prime[k]>=2){
                    ans++;
                }
            }
        }
    }
    ans/=2;
    for(int i=2;i<=N;i++){
        for(int j=2;j<=N;j++){
            if(i==j) continue;
            if(prime[i]>=24&&prime[j]>=2){
                ans++;
            }
            if(prime[i]>=14&&prime[j]>=4){
                ans++;
            }
        }
    }
    for(int i=2;i<=N;i++){
        if(prime[i]>=74) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

const int N = 1e6 + 6;

int a[N];
char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s) + 1;
  for (int i = 0; i + 1 < n; ++i) {
    if (s[i] == '<')
      a[i+1] = a[i] + 1;
  }
  for (int i = n-2; i >= 0; --i) {
    if (s[i] == '>')
      a[i] = max(a[i+1] + 1, a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3840
N=int(input())
SUM,S=0,[10**9+7]
for _ in range(N):
    s=int(input())
    SUM+=s
    if s%10!=0:S.append(s)
S.sort()
if SUM%10!=0:print(SUM)
else:print(max(0,SUM-S[0]))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100;

int main(){
	for(;;){
		int N;
		bool is[2 * MAX_N];
		vector<int> va, vb;
		cin >> N;
		if(N == 0) break;
		fill(is, is + 2 * N, true);
		for(int i = 0; i < N; i++){
			int a;
			cin >> a;
			a--;
			is[a] = false;
		}
		for(int i = 0; i < 2 * N; i++){
			if(!is[i]) va.push_back(i);
			else vb.push_back(i);
		}
		sort(va.begin(), va.end());
		sort(vb.begin(), vb.end());
		int s = 0, t = 0;
		int num = 0;
		bool is_T = true; 
		while(!va.empty() && !vb.empty()){
			if(is_T){
				while(s < va.size() && va[s] < num) s++;
				if(s == va.size()){
					num = 0;
					s = 0, t = 0;
				}else if(va[s] >= num){
					num = va[s];
					va.erase(va.begin() + s);
				}
			}else{
				while(t < vb.size() && vb[t] < num)  t++;
				if(t == vb.size()){
					num = 0;
					s = 0, t = 0;
				}else if(vb[t] >= num){
					num = vb[t];
					vb.erase(vb.begin() + t);
				}
			}
			is_T = !is_T;
		}
		cout << vb.size() << endl;
		cout << va.size() << endl;
	}
	return 0;
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
P dp[101][50001];

void Max(P &a,P b){a=max(a,b);}

int main(){
  int n,p[101];
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>p[i];
  
    memset(dp,-1,sizeof(dp));
    dp[0][0]=P(0,0);
  
    for(int i=0;i<n;i++)
      for(int j=0;j<50000;j++){
	if(dp[i][j]==P(-1,-1))continue;
	int coin=dp[i][j].first;
	int ncost=dp[i][j].second-p[i];
	Max(dp[i+1][j],dp[i][j]);
	if(p[i]%1000<=500&&p[i]%1000)Max(dp[i+1][j+(1000-p[i]%1000)%500],P(coin+1,ncost));
	if(p[i]%1000==0&&j>=500) Max(dp[i+1][j-500],P(coin+1,ncost));
	
	if(p[i]%1000>500) {
	  if(j>=p[i]%500)Max(dp[i+1][j-p[i]%500],P(coin+1,ncost));
	  else Max(dp[i+1][j+(500-p[i]%500)],P(coin,ncost));
	}
      }
  
  
    P ans=P(0,0);
    for(int i=0;i<50000;i++)Max(ans,dp[n][i]);
    cout <<ans.first<<" "<<-ans.second<<endl;
    
  }	
  return 0;
}

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

const int r = 1e9 + 7;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;cin >> n;
	long long int sum = 0, ans = 0;
	vector <int> a(n);
	for (int i = 0; i < n; ++i){
		cin >> a[i]; sum += a[i];
		sum %= r;
	}
	for (int i = 0; i < n; ++i){
		sum -= a[i];
		sum = (sum + r)% r;
		ans += sum*a[i];
		ans%=r;
	}
	cout << ans << "\n";
	return 0;
}


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

int main() {
  string S;
  cin >> S;

  rep(i, 3) {
    if (S[i] == '9') cout << 1;
    else cout << 9;
  }
  cout << endl;
}


Measured memory_bytes: 256
queue=[]

count=0
queue.append([int(i) for i in list(input())])

while not queue[count]==[0]:
    queue.append([int(i) for i in list(input())])
    count+=1

for i in range(count):
    wa=0
    for w in range(len(queue[i])):
        wa+=queue[i][w]
    print(wa)
        


Measured memory_bytes: 5628
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> a = new ArrayList<>();
		List<Integer> b = new ArrayList<>();
		if (n % 2 == 0) {
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					if (i != j && j != n - i + 1) {
						a.add(i);
						b.add(j);
					}
				}
			}
		} else {
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					if (i != j && j != n - i) {
						a.add(i);
						b.add(j);
					}
				}
			}
		}
		System.out.println(a.size());
		for (int i = 0; i < a.size(); i++) {
			System.out.println(a.get(i) + " " + b.get(i));
		}
	}
}

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

int main() {
  int a, b, c, m = 0;
  cin >> a >> b >> c;
  if(a + b < c - 1) cout << 2 * b + a + 1 << endl;
  else cout << b + c << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]

dp=[[0 for _ in range(n+1)] for _ in range(n+1)]

for w in range(n):
    for l in range(n-w):
        r=w+l+1
        dp[l][r] = max(-dp[l+1][r]+A[l],-dp[l][r-1]+A[r-1])
print(dp[0][-1])

Measured memory_bytes: 120284
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var k = Read().Int();
            var r = ReadSplit();
            var a = r[0].Int();
            var b = r[1].Int();
            for (int i = a; i <= b; i++)
            {
                if (i % k == 0)
                {
                    WriteRead("OK");
                    return;
                }
            }
            WriteRead("NG");
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 17872
from collections import *
from math import *
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
S = 0

for k,v in C.items():
  S+=comb(v,2)

for a in A:
  print(S-(comb(C[a],2)-comb(C[a]-1,2)))

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

const int mod = 1000000007;
// const int mod = 998244353;

int main(){
    int a,b;
    cin >> a >> b;
    if(b%a==0)
        cout<<a+b<<endl;
    else
    	cout<<b-a<<endl;
 
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <climits>
using namespace  std;

void fnInput(int &rnMaxSiz, vector<int> &rvnSort)
{
  cin >> rnMaxSiz;

  rvnSort.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
    cin >> rvnSort[i];
}

void fnMerge(vector<int> &rvnSort, int &rnSortCnt, int nLeft, int nMid, int nRight)
{
  vector<int> vLeft, vRight;
  int nLeftSiz = nMid - nLeft;
  int nRightSiz = nRight - nMid;

  vLeft.resize(nLeftSiz + 1);
  vRight.resize(nRightSiz + 1);

  for (int i = 0; i < nLeftSiz; i++)
    vLeft[i] = rvnSort[nLeft + i];
  for (int i = 0; i < nRightSiz; i++)
    vRight[i] = rvnSort[nMid + i];

  vLeft[nLeftSiz]   = INT_MAX;
  vRight[nRightSiz] = INT_MAX;
  int i = 0, j = 0;

  for (int n = nLeft; n < nRight; n++)
    if (vLeft[i] <= vRight[j])
    {
      rvnSort[n] = vLeft[i++];
      rnSortCnt++;
    }
    else
    {
      rvnSort[n] = vRight[j++];
      rnSortCnt++;
    }
}

void fnMergeSort(vector<int> &rvnSort, int &rnSortCnt, int nLeft, int nRight)
{
  if (nLeft + 1 < nRight)
  {
    int nMid = (nLeft + nRight) / 2;
    fnMergeSort(rvnSort, rnSortCnt, nLeft, nMid);
    fnMergeSort(rvnSort, rnSortCnt, nMid, nRight);
    fnMerge(rvnSort, rnSortCnt, nLeft, nMid, nRight);
  }
}

void fnResult(const vector<int> &cnrvnSort, int nSortCnt)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i != 0)  cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
  cout << nSortCnt << endl;
}

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

  int nMaxSiz;
  vector<int> vnSort;

  fnInput(nMaxSiz, vnSort);

  int nLeft = 0;
  int nRight = nMaxSiz;
  int nSortCnt = 0;
  fnMergeSort(vnSort, nSortCnt, nLeft, nRight);

  fnResult(vnSort, nSortCnt);

  return 0;
}

Measured memory_bytes: 5068
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005
#define MAX 52

struct Edge{
	Edge(int arg_to,int arg_index){
		to = arg_to;
		index = arg_index;
	}
	int to,index;
};

int num_edge;
int in_num[MAX],out_num[MAX];
int min_dist[MAX],count_table[MAX];
int COUNT,GOAL;
bool check[MAX][MAX],used[MAX*MAX];
char buf[NUM];
vector<Edge> G[MAX];


int getNUM(char ch){

	if(ch >= 'a' && ch <= 'z'){

		return ch-'a';

	}else{

		return ch-'A'+26;
	}
}

void dfs(int node_id,int depth){

	if(COUNT >= 2)return;

	if(depth == num_edge){

		COUNT++;
		return;
	}

	for(int i = 0; i < G[node_id].size(); i++){

		if(used[G[node_id][i].index])continue;
		used[G[node_id][i].index] = true;

		dfs(G[node_id][i].to,depth+1);
		used[G[node_id][i].index] = false;
	}
}

void func(){

	int length = 0;
	for(length = 0; buf[length] != '\0'; length++);

	if(length <= 2){
		printf("No Results\n");
		return;
	}

	for(int i = 0; i < MAX; i++){

		G[i].clear();
	}

	for(int i = 0; i < MAX; i++){

		in_num[i] = 0;
		out_num[i] = 0;
	}

	for(int i = 0; i < MAX; i++){
		for(int k = 0; k < MAX; k++){
			check[i][k] = false;
		}
	}

	int from,to;
	num_edge = 0;

	for(int i = 0; i+1 < length; i++){

		from = getNUM(buf[i]);
		to = getNUM(buf[i+1]);

		if(check[from][to])continue;

		check[from][to] = true;

		out_num[from]++;
		in_num[to]++;

		G[from].push_back(Edge(to,num_edge++));
	}

	int out_1_bigger = 0,in_1_bigger = 0;
	bool FLG_1 = true,FLG_2 = true;


	for(int i = 0; i < MAX; i++){

		if(out_num[i] != in_num[i]){

			FLG_1 = false;
		}
		if(abs(out_num[i]-in_num[i]) >= 2){

			FLG_2 = false;
		}
		if(out_num[i] == in_num[i]+1){
			out_1_bigger++;
		}
		if(out_num[i]+1 == in_num[i]){

			in_1_bigger++;
		}
	}

	if(FLG_2 == true){
		if(out_1_bigger == 1 && in_1_bigger == 1){

			//Do nothing
		}else{

			FLG_2 = false;
		}
	}

	if(FLG_1){

		printf("%d\n",num_edge+1);

	}else if(FLG_2){

		if(num_edge+1 < length){

			printf("%d\n",num_edge+1);

		}else{

			COUNT = 0;

			for(int i = 0; i < MAX*MAX; i++){
				used[i] = false;
			}

			dfs(getNUM(buf[0]),0);

			if(COUNT >= 2){

				printf("%d\n",num_edge+1);
			}else{

				printf("%d\n",num_edge+2);
			}
		}

	}else{
		int ans = num_edge;

		for(int i = 0; i < MAX; i++){

			ans += max(out_num[i]-in_num[i],0);
		}

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

int main(){

	while(true){

		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3288
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		int cnt=0;
		while(true){
			String s="";
			while(String.IsNullOrEmpty(s))s=Console.ReadLine();
			cnt++;
			int N=int.Parse(s);
			if(N==0)break;
			Sol mySol =new Sol(N);
			Console.WriteLine("{0} {1:F1}",cnt,mySol.Solve());
		}
	}
}

class Sol{
	public double Solve(){
		 return area(L);
	}
	int N;
	List<Pair> L;
	public Sol(int n){
		N=n;
		L=new List<Pair>();
		for(int i=0;i<N;i++)L.Add(new Pair(ria()));
	}

	static double area(List<Pair> L) {
		// trapezium method
		double s = 0;
		int n=L.Count;
		for (int i = 0; i < L.Count; i++)
			s += (L[(i + 1) % n].Y + L[i].Y) * (L[(i + 1) % n].X - L[i].X) / 2.0;
		return Math.Abs(s);
	}


	struct Pair{
		public int X;
		public int Y;
		public Pair(int x,int y){
			X=x;Y=y;
		}
		public Pair(int[] xy){
			X=xy[0];Y=xy[1];
		}
		public static Pair operator-(Pair p,Pair q){
			return new Pair(p.X-q.X,p.Y-q.Y);
		}
		public static int det(Pair p,Pair q){
			return (p.X*q.Y-p.Y*q.X);
		}
		public static int dot(Pair p,Pair q){
			return (p.X*q.X+p.Y*q.Y);
		}
		public override String ToString(){
			return "(\t"+X.ToString()+"\t"+Y.ToString()+")";
		}
		public int L2(){
			return X*X+Y*Y;
		}
		public double L(){
			return Math.Sqrt(X*X+Y*Y);
		}
		public static bool eqCo(Pair p,Pair q){
			return p.X==q.X&&p.Y==q.Y;
		}
	}


	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 5740
#include<stdio.h>

int max(int a, int b){
  if(a > b) return a;
  else return b;
}

int main(){

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

  int point = 0;
  for(int i = 0; i < n; ++i){
    int tmp = 0;
    scanf("%d",&tmp);
    point += tmp - 1;
  }

  printf("%d",point);

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N=0;
  int i=1;
  int j;
  cin >> N;
  vector<int> P(N);
  vector<int> Q(N);
  vector<int> num(N);
  for (int i =0;i<N;i++){
    cin >>P.at(i);
  }
  for ( i =0;i<N;i++){
    cin >>Q.at(i);
  } 
  for(i=0;i<N;i++){
    num.at(i)=i+1;
  }
  map<vector<int>,int> mp;
  do{
    mp[num]=mp.size();
  }while(next_permutation(num.begin(),num.end()));
  int ans=abs(mp[P]-mp[Q]);
  cout<<ans << endl;
}

Measured memory_bytes: 5248
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const ll llinf = 114514191945454545;

struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};

struct graph{
  ll nodenum;
  ll min;
  ll minid;
  ll min2;
  graph(){

  }
  graph(ll inmin,ll inminid){
    nodenum = 1;
    min = inmin;
    minid = inminid;
    min2 = llinf;
  }
};


int main(){
  ll N,M;
  vector<ll> cost;
  cin>> N >> M;
  UnionFind un(N);
  cost.resize(N);
  for(ll i=0;i<N;++i){
    cin >> cost[i];
  }
  for(ll i=0;i<M;++i){
    ll s,t;
    cin >> s >> t;
    un.unionSet(s,t);
  }

  // データを走査する
  map<ll, graph> mp;
  for(ll i=0;i<N;++i){
    ll id = un.root(i);
    cerr<<i<<","<<id<<endl;
    if( mp.find(id) != mp.end() ) {
      mp[id].nodenum += 1;
      if(cost[i] <= mp[id].min){
	mp[id].min2 = mp[id].min;
	mp[id].min = cost[i];
	mp[id].minid = i;
      }else if(cost[i]<mp[id].min2){
	mp[id].min2 = cost[i];
      }
    } else {
      mp[id] = graph(cost[i],i);
    }
  }
  cerr<<"node prop"<<endl;
  vector<ll> min2s;
  vector<ll> all2s;
  ll out = 0;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
    cerr<<itr->second.nodenum<<","<<itr->second.min<<","<<itr->second.min2<<","<<itr->second.minid<<endl;
    out += itr->second.min;
    cost[itr->second.minid] = llinf;
    min2s.push_back(itr->second.min2);
  }
  if(min2s.size()==1){
    cout<<0<<endl;
    return 0;
  }

  // 豚のような実装
  sort(min2s.begin(),min2s.end());
  sort(cost.begin(),cost.end());
  
  for(ll i=0;i<min2s.size()-2;++i){
    out += cost[i];
    if(out > llinf){
      cout<<"Impossible"<<endl;
      return 0;
    }
  }
  for(ll i=0;i<cost.size();++i){
    cerr<<cost[i]<<",";
  }
  cerr<<endl;
  cout<<out<<endl;
  return 0;
}

Measured memory_bytes: 10748
import sys

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


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 get(self, init=None):
        if self.v is None:
            return init
        else:
            return self.v


def main():
    N, MA, MB = read_values()
    dp = [
        [[10 ** 20 for b in range(N * 10 + 1)] for a in range(N * 10 + 1)]
        for n in range(N + 1)
    ]

    dp[0][0][0] = 0

    for n in range(1, N + 1):
        a, b, c = read_values()
        for aa in range(N * 10):
            for bb in range(N * 10 - b):
                if aa - a < 0 or bb - b < 0:
                    dp[n][aa][bb] = dp[n - 1][aa][bb]
                else:
                    dp[n][aa][bb] = min(
                        dp[n - 1][aa - a][bb - b] + c, dp[n - 1][aa][bb]
                    )

    res = V(min)
    max_k = (10 * N) // max(MA, MB)
    for k in range(1, max_k + 1):
        res.ud(dp[N][MA * k][MB * k])

    print(res if res.get() < 10 ** 20 else -1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 100956
#include <bits/stdc++.h>
using namespace std;
#define N 1000010
int i,n,y,L,cnt;
struct edge {
    int u, v, w;
}e[110];
inline void add(int u,int v,int w) {
    e[++cnt] = (edge) {u, v, w};
}
int main() {
    cin >> L;
    for (i = L; i; ++n, i >>= 1);
    for (i = 1; i < n; ++i)add(i, i + 1, 1 << i - 1), add(i, i + 1, 0);
    for (y = 1 << n - 1, i = 1; L != 1; ++i, L >>= 1)if (L & 1)add(i, n, y), y |= 1 << i - 1;
    printf("%d %d\n", n, cnt);
    for (i = 1; i <= cnt; ++i)printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///


void _case()
{
    ll i,ans=0;
    string a,b;
    cin>>a>>b;
    for(i=0;i<3;i++) ans+=(a[i]==b[i]);
    cout<<ans el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int tc; cin>>tc; while(tc--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, x, i, t, s=0;
    cin>> n>> x;


    for( i=0; i<n; i++)
    {
        cin>> t;
        s+= t;

        if( x<s)
        {
            cout << i+1;
            nl;
            return 0;
        }
    }

    cout << n+1;
    nl;

    return 0;
}


Measured memory_bytes: 3640
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
ab = [input().split() for i in range(m)]
tmp=[]
for i in ab:
    tmp.append([int(i[0]),int(i[1])])
ab=tmp

ans = [0 for i in h]

for j in ab:
    if h[j[0]-1]<=h[j[1]-1]:
        ans[j[0]-1]=-1
    if h[j[0]-1]>=h[j[1]-1]:
        ans[j[1]-1]=-1

ans1=0
for i in ans:
    if i>-1:
        ans1+=1
print(ans1)

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

typedef long long ll;
int top, S[1000];

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top=0;
  char S[1000];
  while(scanf("%s",S)!=EOF){ 
    if(S[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(S[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(S[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }else{
      push(atoi(S));
    }
  }
  cout<<pop()<<endl;
  return 0;
}



Measured memory_bytes: 3228
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <time.h>
using namespace std;
long double esp=1e-11;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define cle(a) while(!a.empty())a.pop()
#define mem(p,c) memset(p,c,sizeof(p))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
typedef long long int LL;
const long double PI = acos((long double)-1);
const LL INF=0x3f3f3f3fll;
const int MOD =1000000007ll;
const int maxn=2005;
LL dp[maxn][2];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("in1.txt", "w", stdout);
    //::iterator iter;                  %I64d
    //for(int x=1;x<=n;x++)
    //for(int y=1;y<=n;y++)
    //scanf("%d",&a);
    //printf("%d\n",ans);
    int n,p;
    scanf("%d%d",&n,&p);
    dp[0][0]=1;
    for(int x=1;x<=n;x++)
    {
        int t;
        scanf("%d",&t);
        if(t%2==1)
            dp[x][0]=dp[x-1][1]+dp[x-1][0],dp[x][1]=dp[x-1][0]+dp[x-1][1];
        else
            dp[x][0]=2*dp[x-1][0],dp[x][1]=2*dp[x-1][1];
    }
    printf("%lld\n",dp[n][p]);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	cin >> n;
	ll ans = 1;
	ll MOD = 1e9 + 7;
	for (int i = 1;i <= n;++i) {
		ans *= i;
		ans = ans % MOD;
	}
	cout << ans << endl;
	return 0;
}


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

#define ll long long

int main(){
	int n,W;
	scanf("%d%d", &n,&W);

	vector<int> wt(n);
	vector<ll> val(n);

	for(int i = 0;i < n;i++) scanf("%d%lld",&wt[i],&val[i]);

	vector<ll> dp(W+1, 0);

	for(int i = 0;i < n;i++){
		for(int j = W-wt[i]; j >= 0;j--){
			dp[j+wt[i]] = max(dp[j] + val[i], dp[j+wt[i]]);
		}

	}

	printf("%lld", dp[W]);
}

Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , K , a[N];
ll sum[N] , psum[N];

int main(){
  cin >> n >> K;
  rep(i,1,n+1) cin >> a[i];
  rep(i,1,n+1) sum[i] = sum[i-1] + a[i];
  rep(i,1,n+1) psum[i] = psum[i-1] + max(0 , a[i]);
  ll ans = 0;
  rep(i,K,n+1) {
    ll other = psum[n] - psum[i] + psum[i-K];
    ll in = sum[i] - sum[i-K];
    ans = max(ans , max(0ll , in) + other);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N,K,C;
  string S;
  cin >> N >> K >> C >> S;
  vector<int> L(K);
  vector<int> B(K);
  
  int cnt = 0;
  for(int i=0;i < N;i++){
    if(S.at(i) == 'o'){
      L.at(cnt) = i;
      cnt++;
      i += C;
    }
    if(cnt >= K){
      break;
    }
  }
  cnt = K - 1;
  for(int i=0;i < N;i++){
    if(S.at(N - i - 1) == 'o'){
       B.at(cnt) = N - i - 1;
       cnt--;
       i +=C;
    }
    if(cnt < 0){
      break;
    }
  }
  for(int i=0;i < K;i++){
    if(L.at(i) == B.at(i)){
      cout << L.at(i) + 1 << endl;
    }
  }
}

Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long c;
    c = a+b;
    long long ans;
    ans = a*(n/c);
    ans += min(n%c,a);
    cout << ans << endl;
}




Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353
#define MAX 100000

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

map<ll, ll> yaku_factor(ll N) {
	map<ll, ll> ret;
	ret[1] = 1;

	for (ll i = 2; i * i <= N; i++) {
		if (N % i == 0) {
			ret[i] = 1;
			if (i != N / i) {
				ret[N / i] = 1;
			}
		}
	}
	if (N != 1)ret[N] = 1;
	return ret;

}

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

	ll N;
	cin >> N;

	vl A(N);
	vl B(N, 0);
	vl OUT(N, 0);

	rep(i, N) {
		cin >> A[i];
	}

	rrep(i, N) {
		if (i >= (N / 2)) {
			if (A[i] == 1) {
				OUT[i] = 1;
				map<ll, ll> yaku = yaku_factor(i + 1);
				for (pair<ll, ll> y : yaku) {
					B[y.first - 1] = (B[y.first - 1] + 1);
				}
			}
		}
			if (A[i] != B[i]%2) {
				OUT[i] = 1;
				map<ll, ll> yaku = yaku_factor(i + 1);
				for (pair<ll, ll> y : yaku) {
					B[y.first - 1] = (B[y.first - 1] + 1);
				}
			}
	}

	ll count = 0;
	rep(i, N) {
		if (OUT[i] == 1)count++;
	}

	cout << count << endl;
	rep(i, N) {
		if (OUT[i] == 1) cout << i + 1 << " ";
	}

	return 0;
}



Measured memory_bytes: 5632
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int n, x, t;
	cin >> n >> x >> t;
	if (n % x == 0) {
		cout << n / x * t <<endl;
	}
	else {
		cout << (n / x + 1)*t << endl;
	}
	return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)2e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int t;
    cin>>t;
    if(t >= 30) cout<<"Yes\n";
    else cout<<"No\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

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

int main() {
	int X, Y;
	cin >> X >> Y;
	int n=0;

	switch (X) {
	case 1:
		n = n + 300000;
		break;
	case 2:
		n = n + 200000;
		break;
	case 3:
		n = n + 100000;
		break;
	default:
		break;
	}
	switch (Y) {
	case 1:
		n = n + 300000;
		break;
	case 2:
		n = n + 200000;
		break;
	case 3:
		n = n + 100000;
		break;
	default:
		break;
	}
	if (n == 600000) {
		n = 1000000;
	}
	cout << n << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input
ll N,A,B,C,D,E;


//processing
ll hoge;


//dpTable
//int dp[100050];

int main(){
    cin >> N >> A >> B >> C >> D >> E;
    hoge = min(A,min(B,min(C,min(D,E))));
    ll ans = (N + hoge - 1) / hoge;
    cout << ans + 4 << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn],rk[maxn];
int n;
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),rk[i]=i;
	std::sort(rk+1,rk+n+1,cmp);
	int ans=0;
	for(int i=1;i<=n;i++)
		ans+=std::abs(i-rk[i])&1;
	writeln(ans/2);
	return 0;
}

Measured memory_bytes: 896
// C

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
map<ll,ll> prime_factor(ll n){
  map<ll,ll> res;
  for (ll i(2);i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n/=i;
    }
  }
  if (n!=1) res[n]=1;
  return res;
}

int main(){
  ll X;
  cin>>X;
	while(true){
    map <ll,ll> a = prime_factor(X);
    if (a.size() == 1 && a[X] == 1){
      cout << X << endl;
      return 0; 
    } 
    X++;
	}
  return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	char a[1000], b[1000];
	int ans = -1;
	scanf("%s%s", a, b);
	if (strlen(a) > strlen(b))ans = 1;
	else if (strlen(a) < strlen(b))ans = 2;
	else {
		rep(i, strlen(a)) {
			if (a[i] > b[i])ans = 1;
			else if (a[i] < b[i])ans = 2;
			if (ans != -1)break;
		}
		if (ans == -1)ans = 0;
	}
	if (ans == 0)printf("EQUAL\n");
	else if (ans == 1)printf("GREATER\n");
	else printf("LESS\n");
	return 0;
}


Measured memory_bytes: 128
N = int (input ())
S = str (input ())
S = '.' + S
N += 1
cnt = 0
inf = int(1e9)

A = list(range(N))
for i in range(N):
    A[i] =[inf,inf]
A[0][0] = A[0][1] = 0
for i in range (1,N):
    for j in range (2):
        if j == 1:
            if S[i] == '.':
                A[i][j] = min(A[i][j], A[i-1][0] + 1)
                A[i][j] = min(A[i][j], A[i-1][1] + 1)
            else:
                A[i][j] = min(A[i][j], A[i-1][0] )
                A[i][j] = min(A[i][j], A[i-1][1] )
        else:
            if S[i] == '#':
                A[i][j] = min(A[i][j], A[i-1][0] + 1)
            else:
                A[i][j] = min(A[i][j], A[i-1][0])                

ans = min(A[N-1][0],A[N-1][1])

print (ans)


Measured memory_bytes: 30052
#include <iostream>
#include <vector>
#include <stdlib.h> //for exit
#include <algorithm> //for sort...etc
#include <numeric> //for accumulate
using namespace std;

int main()
{
    while(1)
    {
        int n,score=10000000;
        vector<int> a;
        cin >> n;
        if(n == 0) exit(0);
        for(int i = 0 ; i < n; i++)
        {
            int tpn;
            cin >> tpn;
            a.push_back(tpn);
        }

        for(int i = 0; i < n; i++)
        {
            for(int k = 0; k < n; k++)
            {
                int tpscore = abs(a[i] - a[k]);
                if((tpscore < score) && (i!=k))
                {
                    score = tpscore;
                }
            }
        }

        cout << score << endl;
    }
}


Measured memory_bytes: 3112
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<string, int> I;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
char rest(char a, char b){
  char rgb[5] = "rgb";
  REP(i,3){
    if(rgb[i] != a && rgb[i] != b){
      return rgb[i];
    }
  }
  return ',';
}
  
int bfs(I insect){
  set<string> memo;
  queue<I> que;
  que.push(insect);
  while(!que.empty()){
    I inc = que.front(); que.pop();
    string s = inc.first;
    int t = inc.second;

    if(memo.find(s) != memo.end()) continue;
    memo.insert(s);

    bool goal = true; 
    REP(i,s.size()-1){
      if(s[i] != s[i+1]){
        goal = false;
        string nxt = s;
        char rschar = rest(s[i],s[i+1]);
        if(rschar == '.') abort();
        nxt[i] = rschar;
        nxt[i+1] = rschar;
        que.push(I(nxt, t+1));
      }
    }
    if(goal) return t;
  }
  return -1;
}

int main(void){
  string insect;
  while(cin>>insect){
    if(insect == "0") break;
    int ans = bfs(I(insect, 0));
    if(ans == -1) cout<< "NA" << endl;
    else  cout<< ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2112
a = input()
b = input().split()

c = dict()
for i in b:
    if i in c:
        c[i] += 1
    else:
        c[i] = 1

done = True
for i in c:
    if c[i] > 1:
        print("NO")
        done  = False
        break

if done:
    print("YES")

Measured memory_bytes: 99928
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<180*(n-2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e6;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

// ARC077
int fact[MAX_N];
int ifact[MAX_N];
 
int power(int x, int n) {
	int res = 1LL;
	while (n > 0) {
		if (n & 1) (res *= x) %= MOD;
		(x *= x) %= MOD;
		n >>= 1;
	}
	return res % MOD;
}
 
int inv(int x) {
	return power(x, MOD - 2);
}
 
int nCr(int n, int r) {
	if (n < 0 || r < 0 || r > n) return 0;
	if (r > n / 2) r = n - r;
	return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

signed main() {
  INIT;

	fact[0] = ifact[0] = 1;
	FOR(i, 1, MAX_N) {
		(fact[i] = fact[i - 1] * i) %= MOD;
		ifact[i] = inv(fact[i]);
	}
	
	VAR(int, n);
	VEC(int, a, n + 1);

	vector< int >  memo(MAX_N, -1);
	int lb = 0, ub = 0;
	REP(i, n + 1) {
		if (memo[a[i]] > -1) {
			lb = memo[a[i]];
			ub = i;
			break;
		}
		memo[a[i]] = i;
	}

	int ans = 0;
	REP(i, n + 1) {
		(ans = nCr(n + 1, i + 1)) %= MOD;
		(ans = ans - nCr(n - ub + lb, i) + MOD) %= MOD;
		while (ans < 0) (ans += MOD) %= MOD;
		OUT(ans)BR;
	}
	
	
  
  return 0;
}


Measured memory_bytes: 25472
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int k;
    cin >> k;

    vector<int> a(k);
    for (int i = 0; i < k; i++) {
        cin >> a[i];
    }

    int64_t m0 = 2, m1 = 2;
    for (int i = k - 1; i >= 0; i--) {
        m0 = (m0 + a[i] - 1) / a[i] * a[i];
        m1 = m1 / a[i] * a[i] + (a[i] - 1);
        if (m0 > m1) {
            cout << -1 << endl;
            quick_exit(0);
        }
    }

    cout << m0 << ' ' << m1 << endl;

    return 0;
}

Measured memory_bytes: 640