akhauriyash/Code-Regression huggingface dataset:
// If you want something you've never had, you must be willing to do s
// something you've never done

//  When the going gets tough,  the tough get going
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}

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

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = 2e9;

signed main() {
    int k;
    cin >> k;
    int g[k+5][k+5];
    memset(g, 0, sizeof g);
    for(int i=1; i<=k; i++) {
        for(int j=1; j<=k; j++) {
            g[i][j] = __gcd(i, j);
        }
    }
    int sum = 0;
    for(int i=1; i<=k; i++) {
        for(int j=1; j<=k; j++) {
            for(int m=1; m<=k; m++){
                sum += g[m][g[i][j]];
            }
        }
    }
    cout << sum << '\n';
    return 0;
}

// A telephone line whose bandwidth is 1638 Hz is connected from point A to point B. What will be the channel capacity if signal-to-noise ratio is 22 db?


Measured memory_bytes: 3784
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {
    public static void main(String[] args) {
        FastScanner scr = new FastScanner();

//        int t = scr.nextInt();
//        while (t-- > 0)
        solve(scr);
    }


    static void solve(FastScanner scr) {
        long x = scr.nextLong();
        long points = 0;

        long h = x / 500;
        x -= h * 500;
        long z = x / 5;
        h *= 1000;
        z *= 5;
        System.out.println(h+z);
    }


    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            init();
        }

        public FastScanner(String name) {
            init(name);
        }

        public FastScanner(boolean isOnlineJudge) {
            if (!isOnlineJudge || System.getProperty("ONLINE_JUDGE") != null) {
                init();
            } else {
                init("input.txt");
            }
        }

        private void init() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        private void init(String name) {
            try {
                br = new BufferedReader(new FileReader(name));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }

    }
}

Measured memory_bytes: 21460
from collections import deque

h,w=map(int,input().split())
w+=2

a=[list('@'*w)]
for i in range(h):
    a+=[list('@'+input()+'@')]
a+=[list('@'*w)]
h+=2

xy=[(-1,0),(0,-1),(0,1),(1,0)]
que=deque()

def bfs():
    res=0
    while que:
        x,y=que.popleft()
        for dx,dy in xy:
            nx,ny=dx+x,dy+y
            tmp=A[x][y]+1
            if a[nx][ny]!='@':
                if A[nx][ny]<=tmp:continue
                A[nx][ny]=tmp
                que.append((nx,ny))
                res=max(res,tmp)
    return res


A=[[float('inf')]*w for i in range(h)]

res=0
for i in range(1,h-1):
    for j in range(1,w-1):
        if a[i][j]=='#':
            A[i][j]=0
            que.append((i,j))

res=bfs()
print(res)



Measured memory_bytes: 130396
#include<iostream>
#include<cmath>
using namespace std;
const double PI= atan(1.0)*4;
int main() 
{
    long long ans=0,N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
    	int a;
    	cin>>a;
    	ans=ans+a;
	}
	N=N-ans;
	if(N<0)cout<<-1<<endl;
	else cout<<N<<endl;
	return 0;
}

Measured memory_bytes: 3632
/************************************************************
	> File Name: a.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Mon 13 Jan 2020 11:03:01 AM CST
************************************************************/

#pragma GCC optimize(2)
#include <iostream>
using namespace std;
int main(void){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	char ch;
	cin >> ch;
	cout << (char)(ch+1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,m,dp[3030][3030];
string s,t;
int main()
{
	cin>>s>>t;
	n=s.size();
	m=t.size();
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s[i]==t[j])
			{
				dp[i+1][j+1]=dp[i][j]+1;
			}
			else
			{
				dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
			}
		}
	}
//	cout<<dp[n][m]<<endl;
	string ans="";
	int i=n,j=m;
	while(i>0 && j>0)
	{
		if(dp[i][j]==dp[i-1][j])
		{
			i--;
		}
		else if(dp[i][j]==dp[i][j-1])
		{
			j--;
		}
		else if(dp[i][j]==dp[i-1][j-1]+1)
		{
			i--;
			j--;
			ans=s[i]+ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a, b;
	scanf("%d%d", &a, &b);
	if(a + b == 15)printf("+\n");
	else if( a * b == 15)printf("*\n");
	else printf("x\n");
	
	Please AC;
}


Measured memory_bytes: 760
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInt s = (read :: String -> Int) s

main = do
    n <- readLn :: IO Int
    an <- map read . words <$> getLine
    let bn = map judge an
    
    putStrLn $ solve bn

judge :: Int -> Int
judge n = if (n `mod` 4) == 0
          then 2
          else if (n `mod` 2) == 0
               then 1
               else 0
               
solve :: [Int] -> String
solve xn = if ( (c-a) >= 0 ) && ((c /= 0) || ( (c==0) && (b `mod` 2) == 0) ) || ((a-c) == 1 && (b `mod` 2) == 0)
           then "Yes"
           else "No"
             where a = length $ (filter (==0) xn)
                   b = length $ (filter (==1) xn)
                   c = length $ (filter (==2) xn)

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

using namespace std;

using int64 = long long;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

vector<vector<Edge>> ReadUndirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge(v1, v2));
    graph[v2].push_back(Edge(v2, v1));
  }
  return graph;
}

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

  int n;
  cin >> n;
  auto graph = ReadUndirectedGraph(n, n - 1, true);

  function<tuple<int, int>(int, int)> dfs =
      [&](int v, int p) -> tuple<int, int> {
    auto r = make_tuple(v, 0);
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      int arg, value;
      tie(arg, value) = dfs(e.to, v);
      value += 1;
      if (get<1>(r) < value) {
        r = make_tuple(arg, value);
      }
    }
    return r;
  };
  int v;
  tie(v, ignore) = dfs(0, -1);
  int d;
  tie(ignore, d) = dfs(v, -1);
  if (d % 3 == 1) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }
}

Measured memory_bytes: 29952
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);

        System.out.println( solve() );
    }

    private static long solve() {
        long ans = 0;
        for (int i = 0; i < N-1; i++) {
            ans += A[i] / 2;
            if( A[i] % 2 == 1 && A[i+1] > 0) {
                A[i+1] --;
                ans++;
            }
        }
        ans += A[N-1] / 2;
        return ans;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 36940
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char s[n + 1], t[n + 1];
  cin >> s >> t;
  ostringstream oss;
  for(int i = 0; i < n; ++i) {
    oss << s[i] << t[i];
  }
  cout << oss.str() << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	var N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)

	as := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &as[i])
	}
	sort.Sort(sort.IntSlice(as))
	fmt.Println(as[len(as)-1] - as[0])
}


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

int main(){
    int N,M;
    string s[100],t[100];

    cin >> N;
    for(int i=0;i<N;i++) cin >> s[i];
    cin >> M;
    for(int i=0;i<M;i++) cin >> t[i];

    int max =0;

    for(int i=0;i<N;i++){
      int sum =0;
        for(int j=0;j<N;j++){
            if(s[i]==s[j]) sum++;
        }
      	for(int j=0;j<M;j++){
          if(s[i] == t[j]) sum--;
        }
         if(sum>max) max = sum;
        
    }
    cout <<max << endl;

    
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{   
	while(1){
		int H,W;
		cin>>H>>W;
		if(H==0 && W==0)break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
n,m = map(int, input().split())
h_list = list(map(int,input().split()))
ans = [1]*n
for i in range(m):
    a,b = map(int, input().split())
    if h_list[a-1] == h_list[b-1]:
        ans[a-1] = 0
        ans[b-1] = 0
    else:
        if h_list[a-1] > h_list[b-1]:
            ans[b-1] = 0
        else:
            ans[a-1] = 0
print(sum(ans))

Measured memory_bytes: 20044
# encoding: utf-8
import sys
# input = sys.stdin.readline
P = 10 ** 9 + 7

N, K = map(int, input().split())

# molec = 1
# for i in range(K - 1):
#     molec = (molec * (i + 1)) % P

power = 10 ** 9 + 5
digits = []
for i in range(64):
    digits.append(power % 2)
    power >>= 1

def modinv(b):
    binv = 1
    val = b % P
    for i, digit in enumerate(digits):
        if digit == 1:
            binv = (binv * val) % P
        val = (val * val) % P
    # print("##", b, binv)
    return binv

molec = 1
tab_nck = [1]
for i in range(1, K - 1):
    molec = (molec * (K - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck.append(molec)
tab_nck.append(1)

molec = 1
tab_nck2 = [1]
for i in range(1, N - K + 1):
    molec = (molec * (N - K + 2 - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck2.append(molec)
tab_nck2.append(1)

# print("#", tab_nck)
# print("#", tab_nck2)

def nck(a, b):
    # a = K - 1
    if b < 0: return 0
    elif b > K - 1: return 0
    else: return tab_nck[b]

def nck2(a, b):
    # a = N - K + 1
    if b < 0: return 0
    elif b > N - K + 1: return 0
    else: return tab_nck2[b]

for i in range(1, K + 1):
    ans = 1
    #
    ans = (ans * nck(K - 1, i - 1)) % P
    ans = (ans * nck2(N - K + i - 1, i)) % P
    #
    print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i+=2){
        int tmp = 0;
        for(int j=1;j<=i;j++){
            if(i%j==0)tmp++;
        }
        if(tmp == 8)ans++;
    }
    cout << ans << endl;
}

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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(void){
    int n, ans;

    cin >> n;

    for(int i = n; ;i++){
        if(IsPrime(i)){
            ans = i;
            break;
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN=4e5+7;
int head[MAXN],vis[MAXN],size[MAXN],dep[MAXN],nod[MAXN];
struct po
{
	int nxt,to,from;
}edge[MAXN];
int n,m,num,cnt,ans=1,s,t,flag=1;
inline void add_edge(int from,int to)
{
	edge[++num].nxt=head[from];
	edge[num].from=from;
	edge[num].to=to;
	head[from]=num;
}
inline int bfs(int S)
{
	memset(vis,0,sizeof(vis));
	queue<int> q;
	q.push(S);
	vis[S]=1;
	int u;
	while(!q.empty()){
		u=q.front(); q.pop();
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(!vis[v]){
				vis[v]=1;
				q.push(v);
			}
		}
	}
	return u;
}
void dfs(int u)
{
	if(!flag) return;
	int tp=0;
	vis[u]=1;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(!vis[v]){
			dfs(v);
			dep[u]=max(dep[u],dep[v]);
			if(dep[v]>1) tp++;
			if(v!=t&&dep[v]==1) size[u]++;
		}
	}
	dep[u]++;
	if(tp>=2){
		flag=0;
		return;
	}
	if(u!=s&&u!=t&&dep[u]>=2)
		nod[cnt++]=size[u];
}
void out(int u)
{
	int tt=ans;
	vis[u]=1;
	if(size[u]>0) for(int i=1;i<=size[u];i++) cout<<++ans<<" ";
	printf("%d%c", tt,u==t?'\n':' ');
	ans++;
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(v==t||v==s||dep[v]>1){
			if(!vis[v]) out(v);
		}
	}
}
int main()
{
	cin>>n;
	m=n-1;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		add_edge(u,v);
		add_edge(v,u);
	}
	t=bfs(1);s=bfs(t);
	memset(vis,0,sizeof(vis));
	dfs(s);
	
	reverse(nod,nod+cnt);
	for(int i=0;i<cnt;i++){
		if(nod[i]<nod[cnt-i-1]) break;
		else if(nod[i]>nod[cnt-i-1]){
			swap(s,t);
			break;
		}
	}
	memset(vis,0,sizeof(vis));
	if(!flag) cout<<"-1";
	else out(s);
}

Measured memory_bytes: 19328
public class Main{
  static int top = 0;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int[] stack;
    String prec;
    char c;

    stack = new int[200];
    top = 0;

    for(;;){
      if(!sc.hasNext())break;
      prec = sc.next();
      c = prec.charAt(0);
      if('0' <= c && c <= '9'){
        push(stack, Integer.parseInt(prec));
      }else if(c == '+'){
        push(stack, pop(stack) + pop(stack));
      }else if(c == '-'){
        push(stack,  -pop(stack) + pop(stack));
      }else if(c == '*'){
        push(stack, pop(stack) * pop(stack));
      }else{
        break;
      }
    }

    System.out.println(pop(stack));

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static int pop(int[] stack){
    return stack[--top];
  }

  private static void push(int[] stack, int a){
    stack[top++] = a;
    return;
  }
}

Measured memory_bytes: 18688
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[100050];

int r[100050];
int root(int x) {
	return (x == r[x]) ? x : (r[x] = root(r[x]));
}
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) {
		scanf("%d", &in[i]);
		r[i] = i;
	}
	
	while (M--) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		r[root(t1)] = root(t2);
	}

	int ans = 0;
	for (i = 1; i <= N; i++) if (root(i) == root(in[i])) ans++;
	return !printf("%d\n", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  int s = 0;
  int sp = 0;
  int ans = 1;

  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) s = 1;
    if (a[i] > a[i + 1]) s = -1;

    if (s == 1 && sp == -1 || s == -1 && sp == 1) {
      ans++;
      s = 0;
      sp = 0;
      continue;
    }
    sp = s;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4016
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MAX = 2020;
int board[MAX][MAX], bCUM[MAX][MAX], rCUM[MAX][MAX], cCUM[MAX][MAX];

int main(){
    
    // 1. 入力情報.
    int N, M, Q;
    scanf("%d %d %d", &N, &M, &Q);
    rep(i, N){
        char S[2020];
        scanf("%s", S);
        rep(j, M) board[i][j] = S[j] - '0';
    }
    
    // 2. 二次元累積和(黒マス).
    repx(i, 1, N + 1){
        repx(j, 1, M + 1){
            bCUM[i][j] = board[i - 1][j - 1] + bCUM[i - 1][j] + bCUM[i][j - 1] - bCUM[i - 1][j - 1];
        }
    }
    // repx(i, 0, N + 1){
    //     repx(j, 0, M + 1) printf("%d ", bCUM[i][j]);
    //     printf("\n");
    // }
    
    // 3. 二次元累積和(黒マスが縦方向に連続する箇所の数).
    repx(i, 1, N + 1){
        repx(j, 1, M + 1){
            cCUM[i][j] = cCUM[i - 1][j] + cCUM[i][j - 1] - cCUM[i - 1][j - 1];
            if(i > 1 && board[i - 2][j - 1] && board[i - 1][j - 1]) cCUM[i][j]++;
        }
    }
    // repx(i, 0, N + 1){
    //     repx(j, 0, M + 1) printf("%d ", cCUM[i][j]);
    //     printf("\n");
    // }
    
    // 4. 二次元累積和(黒マスが横方向に連続する箇所の数).
    repx(i, 1, N + 1){
        repx(j, 1, M + 1){
            rCUM[i][j] = rCUM[i - 1][j] + rCUM[i][j - 1] - rCUM[i - 1][j - 1];
            if(j > 1 && board[i - 1][j - 2] && board[i - 1][j - 1]) rCUM[i][j]++;
        }
    }
    // repx(i, 0, N + 1){
    //     repx(j, 0, M + 1) printf("%d ", rCUM[i][j]);
    //     printf("\n");
    // }
    
    // 5. クエリ回答.
    rep(i, Q){
        // 5-1. 矩形領域.
        int x1, y1, x2, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        
        // 5-2. 黒マスの数.
        int vCount = bCUM[x2][y2] - bCUM[x1 - 1][y2] - bCUM[x2][y1 - 1] + bCUM[x1 - 1][y1 - 1];
        
        // 5-3. 辺数.
        int eCount = 0;
        eCount += cCUM[x2][y2] - cCUM[x1][y2] - cCUM[x2][y1 - 1] + cCUM[x1][y1 - 1];
        eCount += rCUM[x2][y2] - rCUM[x1 - 1][y2] - rCUM[x2][y1] + rCUM[x1 - 1][y1];
        
        // 5-4. 出力.
        int ans = vCount - eCount;
        printf("%d\n", ans);
    }
    return 0;
    
}

Measured memory_bytes: 67020
#include<stdio.h>

int main()
{
    int N;
    int i;
    int a, b, c;

    scanf("%d\n", &N);

    for(i = 0; i < N; i++)
    {
        scanf("%d %d %d", &a, &b, &c);
        if (a > b && a > c)
            if (a*a == b*b + c*c)
                printf("YES\n");
            else
                printf("NO\n");
        else if(b > a && b > c)
            if(b*b == a*a + c*c)
                printf("YES\n");
            else
                printf("NO\n");
        else if(c*c == a*a + b*b)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 580
N=int(input())
L=list(map(int,input().split()))
ans=0

for i in range(N):
    for j in range(N):
        for k in range(N):
            a,b,c=L[i],L[j],L[k]
            if i<j<k and a!=b and b!=c and c!=a:
                if a+b>c and b+c>a and c+a>b:
                    ans+=1
                    #print(a,b,c)

print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
    int64 n;
	cin >> n;
	int64 ans = n - 1;
	for (int64 i = 1; i * i <= n; ++i) {
	    if (n % i == 0) {
		    ans = min(ans, i + n / i - 2);
		}
	}
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("rawtypes")
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());

		/**
		 * 1)A+B<=2Cの場合
		 *  →A*X+B*Yが最低金額
		 * 2)A+B>2Cの場合
		 *  →まず、XとYの小さい方をZとして2C*Z必要
		 *    XとYとの差については、差*A or B or 2C 条件はコード参照
		 *    なお、X=Yなら2C*Xのみ
		 */
		
		int cost = 0;
		// (ai/2)に最も近い数を探索する
		if(a + b <= c * 2) {
			cost += (a * x) + (b * y);
		}else {
			cost += 2 * c * Math.min(x, y);
			if(x > y) {
				if(a <= c * 2) {
					cost += a * (x - y);
				}else {
					cost += 2 * c * (x - y);
				}
			}else if(x < y) {
				if(b <= c * 2) {
					cost += b * (y - x);
				}else {
					cost += 2 * c * (y - x);
				}
			}
		}
		System.out.println(cost);

	}

}


Measured memory_bytes: 23764
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
max_T = max(T)
max_A = max(A)
if max_A != max_T:
    print(0)
    exit()
mt,ma = 0,0
ans = 1
for i in range(N):
    if T[i] == max_T:

        break
    else:
        if T[i] > mt:
            mt = T[i]
        else:
            ans *= mt
            ans %= mod
for j in range(N)[::-1]:
    if A[j] == max_A:
        break
    else:
        if A[j] > ma:
            ma = A[j]
        else:
            ans *= ma
            ans %= mod
if i == j:
    print(ans)
    exit()
elif j < i:
    print(0)
    exit()
else:
    ans *= pow(max_A,j-i-1,mod)
    ans %= mod
    print(ans)


Measured memory_bytes: 86620
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    
         if(a == b && b != c) cout << "Yes" << endl;
    else if(a == c && b != c) cout << "Yes" << endl;
    else if(b == c && a != c) cout << "Yes" << endl;
    else                      cout << "No" << endl;
    return 0;
}

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

void solve() {
    int N , M;
    cin >> N >> M;
    cout << (N * (N - 1) / 2) + (M * (M - 1) / 2) << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

#define ran 101111

int n;
int a[ran], b[ran], c[ran];
long long sb[ran];

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	for(int i=0;i<n;i++) scanf("%d", &b[i]);
	for(int i=0;i<n;i++) scanf("%d", &c[i]);
	
	sort(a, a+n);
	sort(b, b+n);
	sort(c, c+n);
	
	int it = 0;
	for(int i=0;i<n;i++) {
		while(it<n && a[it]<b[i]) it++;
		sb[i] = it;
		if (i) sb[i] += sb[i-1];
	}
	
	it = 0;
	long long ans = 0LL;
	for(int i=0;i<n;i++) {
		while(it<n && b[it]<c[i]) it++;
		if(it>0) ans+=sb[it-1];
	}
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(void){
    int a,b,c,d,p;
    int costx, costy;
    
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &p);
    costx = a*p;
    costy = b + (p>c?(p-c)*d:0);
    
    printf("%d\n", costx>costy?costy:costx);
      
    return 0;
}

Measured memory_bytes: 1024
// Vacation

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main {
	public static int vacation(int[][] arr, int n) {
		int[][] dp = new int[n][3];
		// System.out.println();
		for(int i = 0; i < 3; i++) {
			dp[0][i] = arr[0][i];
			// System.out.print(arr[0][i] + " ");
		}
		// System.out.println();

		for(int i = 1; i < n; i++) {
			for(int j = 0; j < 3; j++) {
				if(j == 0)
					dp[i][j] = max(arr[i][j]+dp[i-1][1], arr[i][j]+dp[i-1][2]);
				else if(j == 1)
					dp[i][j] = max(arr[i][j]+dp[i-1][0], arr[i][j]+dp[i-1][2]);
				else if(j == 2)
					dp[i][j] = max(arr[i][j]+dp[i-1][0], arr[i][j]+dp[i-1][1]);
				// System.out.print(dp[i][j] + " ");
			}
			// System.out.println();
		}
		// System.out.println();

		return max(dp[n-1][0], dp[n-1][1], dp[n-1][2]);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[][] arr = new int[n][3];

		for(int i = 0; i < n; i++) {
			String[] s = br.readLine().split(" ");
			for(int j = 0; j < 3; j++) {
				arr[i][j] = Integer.parseInt(s[j]);
			}
		}
		System.out.println(vacation(arr, n));
	}
	public static int min(int...arr) {
		int min = Integer.MAX_VALUE;
		for(int i: arr) {
			if(i < min)
				min = i;
		}
		return min;
	}

	public static int max(int...arr) {
		int max = Integer.MIN_VALUE;
		for(int i: arr) {
			if(i > max)
				max = i;
		}
		return max;	
	}
}

Measured memory_bytes: 53648
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int st = n<k ? n : k;
    int nd = n<k ? 0: n-k;
    cout << st*x + nd*y << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int vis[105][105];
int cnt[5];
int f[256];
int main() {
  IOS;
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      f[c]++;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vis[i][j])
        continue;
      int tmp = 0;
      tmp = !vis[i][j], vis[i][j] = 1;
      tmp += !vis[h - i - 1][j], vis[h - i - 1][j] = 1;
      tmp += !vis[i][w - j - 1], vis[i][w - j - 1] = 1;
      tmp += !vis[h - i - 1][w - j - 1], vis[h - i - 1][w - j - 1] = 1;
      cnt[tmp]++;
    }
  }
  for (int k = 4; k >= 1; k--) {
    for (int i = 0; i < cnt[k]; i++) {
      int ok = 0;
      for (int j = 'a'; j <= 'z'; j++) {
        if (f[j] >= k) {
          f[j] -= k, ok = 1;
          break;
        }
      }
      if (!ok) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3696
// Problem : K - Stones
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_k
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(long long int i=0;i<n;i++)
#define FORR(i,n) for(long long int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<long long int>
#define slli set<long long int>
#define mlli map<long long int,long long int>
#define lli long long int 
#define test lli tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define MOD 1000000007
using namespace std;
// using int=long long;
void solve(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	// FOR(i,n)cin>>arr[i];
	for(auto &x:a){
		scanf("%int",&x);
	}
	vector<bool>dp(k+1);
	for(int stones=0;stones<=k;stones++){
		for(int x:a){
			if(stones-x>=0 && !dp[stones-x]) dp[stones]=true;
		}
	}
	cout<<(dp[k]==true?"First":"Second");
			
}


int32_t main() {
    	solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define lli  long long int
using namespace std;
#define S second
#define F first
#define pb push_back
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      auto pl:mp       pl.S && pl.F
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)
{   int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {   if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int main()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t, i, j, n = 0, y = 0, x = 0, h, w, k;
    cin >> n;
    lli a[n];
    lli b[n];
    for (i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    b[0] = 0;
    for (i = 2; i <= n; i++) {
        y = (i + 1) / 2;
        x = x + a[n - y];
    }
    cout << x;
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    double L; cin >> L;
    double d = L/3;
    double eps = 1e-6;
    double ans = 0;
    for(double x = d - 0.0001; x <= d + 0.0001; x += 0.0001){
        if(abs(3*x-L)<eps) chmax(ans,x*x*x);
    }
    printf("%.10f",ans);

    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 rep2(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
int main() {
    ll N, m = LONG_LONG_MAX;
    cin >> N;
    rep(i, 5) {
        ll x;
        cin >> x;
        m = min(m, x);
    }
    ll ans = 4 + (ll)ceil(N * 1.0 / m);
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int a,b,c,tot,kk;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b>>c;
	//b>a,c>b
	while(b<=a){
		tot++;
		b*=2;
	}
	while(c<=b){
		tot++;
		c*=2;
	}
	cin>>kk;
	if(tot>kk) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


int n,m, a, b, c;
vector<int> edge[50];
int dist[50];

int step(int u,int num) {
	vector<int> nxt, cur;
	cur.push_back(u);
	rep(_,num) {
		nxt.clear();
		rep(i,cur.size()) {
			rep(j,edge[cur[i]].size()) {
				nxt.push_back(edge[cur[i]][j]);
			}
		}
		sort(all(nxt));
		uniq(nxt);
		swap(cur,nxt);
	}
	int res = INF;
	rep(i,cur.size()) {
		res = min(res,dist[cur[i]]);
	}
	return res;
}



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> a >> b >> c;
	rep(i,m) {
		int x,y;
		cin >> x >> y;
		x -- ; y--;
		edge[x].push_back(y);
	}
	fill_n(dist, n, INF);
	dist[n - 1] = 0;
	bool update = true;
	while (update) {
		update = false;
		rep(u,n) {
			int ma = 0;
			ma = max(ma, step(u, a));
			ma = max(ma, step(u, b));
			ma = max(ma, step(u, c));
			if (ma+1 < dist[u]) {
				dist[u] = ma + 1;
				update = true;
			}
		}
	}

	int ans=dist[0];
	if (ans == INF)cout << "IMPOSSIBLE" << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3208
#include<stdio.h>
int main()
{
    long long a,b,gcd,temp,lcm;
    while(scanf("%lli %lli",&a,&b)!=EOF)
    {
    lcm=a*b;
    while(b!=0)
    {
        temp=b;
        b=a%b;
        a=temp;
    }
    gcd=a;
    lcm=lcm/gcd;
    printf("%lli %lli\n",gcd,lcm);
    }
    return 0;
}



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

int main(void)
{
    int N;
    cin >> N;

    vector<int> A(N);
    for (int i = 0; i<N; i++) {
        cin >> A[i];
    }
    sort(A.begin(),A.end());


    int num = 1;
    for (int i = 1; i < N; i++) {
        if (A[i] > A[i-1])
            num++;
    }

    cout << num << endl;

    return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 40;
const int AL = 26;

int n;
string s;

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	static char buf[N];
	scanf("%s", buf);
	s = buf;
	return true;
}

string t1, t2;
map<pair<string, string>, int> used;

void solve() {
	t1 = s.substr(0, n);
	t2 = s.substr(n, n);
	
	reverse(all(t2));
	
	used.clear();
	forn(mask, 1 << n){
		string r1 = "", r2 = "";
		forn(i, n)
			if ((mask >> i) & 1)
				r1 += t1[i];
			else
				r2 += t1[i];
		++used[mp(r1, r2)];
	}
	
	li ans = 0;
	forn(mask, 1 << n){
		string r1 = "", r2 = "";
		forn(i, n)
			if ((mask >> i) & 1)
				r1 += t2[i];
			else
				r2 += t2[i];
		ans += used[mp(r1, r2)];
	}
	
	printf("%lld\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 91904
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	// N
	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	// S
	scanner.Scan()
	S := scanner.Text()

	counter := 0

	for i := 0; i < N-2; i++ {
		if S[i:i+3] == "ABC" {
			counter++
		}
	}

	fmt.Println(counter)
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

	int n; cin >> n;

	cout << (1000-n%1000)%1000 << '\n';

	return 0;
}


Measured memory_bytes: 3656
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cmath>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long lld;
typedef long double Lf;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main() {
	int n, k, t, all[6] = { 0 }, d[10] = { 0 };
	scanf("%d%d", &n, &k);
	rep(i, k) { scanf("%d", &t); d[t]++; }
	if (n == 1 && d[1] != 1) { printf("1"); return 0; }
	t++;
	Rep(i, 2 < n ? n : 2, 1e5) {
		rep(j, log10(i) + 1) {
			all[j] = (i % (int)pow(10, j + 1)) / (int)pow(10, j);
			rep(x, 10)if (d[all[j]])t = 0;
		}
		if (t) { printf("%d", i); return 0; }
		t++;
	}
}

Measured memory_bytes: 128
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    s25 = [[0]*19 for i in range(19)] #2^i*5^j*kの個数：s25[i][j]
    nms = [] #(i,j)の組
    n = int(ipt())
    for _ in range(n):
        a = float(ipt())*(10**9)+0.1
        ia = int(a)
        for i in range(19):
            if ia%2 != 0:
                t2 = i
                break
            elif i == 18:
                t2 = 18
            else:
                ia //= 2
        for i in range(19):
            if ia%5 != 0:
                t5 = i
                break
            elif i == 18:
                t5 = 18
            else:
                ia //= 5
        s25[18-t2][18-t5] += 1
        nms.append((t2,t5))

    ss = s25
    for i in range(1,19):
        ss[0][i] += ss[0][i-1]
        ss[i][0] += ss[i-1][0]
    for i in range(1,19):
        for j in range(1,19):
            ss[i][j] += ss[i-1][j]+ss[i][j-1]-ss[i-1][j-1]
#    print(ss)

    ans = 0
    for t2,t5 in nms:
        ans += ss[t2][t5]
        if t2 >= 9 and t5 >= 9:
            ans -= 1

    print(ans//2)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 90384
'use strict'

function solve(N, K, A) {
  let dp = new Array(K+1).fill(false)
  for (var i = 1; i <= K; i++) {
    for (var j = 0; j < A.length; j++) {
      if (i < A[j]) {
        break
      }
      dp[i] = dp[i] || !dp[i-A[j]]
    }
  }
  return dp[K]
}

function main(input) {
  var lines = input.split("\n")
  var NK = lines[0].split(' ').map(l => parseInt(l))
  var N = NK[0]
  var K = NK[1]
  var A = lines[1].split(' ').map(l => parseInt(l))
  var ans = solve(N, K, A) ? 'First' : 'Second'
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 12364