akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

ll t3[1 << 17];
void init() {
	t3[0] = 1;
	rep1(i, (1 << 17) - 1) {
		t3[i] = t3[i - 1] * 3 % mod;
	}
}
void solve() {
	init();
	string s; cin >> s;
	int len = s.length();
	ll ans = 0;
	ll u = 1;
	rep(i, len) {
		if (s[i] == '1') {
			ans += t3[len - 1 - i]*u%mod;
			ans %= mod;
			u = u * 2 % mod;
		}
	}
	ans = (ans + u) % mod;
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	//while (cin >> n>>m>>l,n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define sum accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define sp " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
/*vbool isprime(N,true);
vll spf(N,0);
vll prime;
void sieve()
{
    isprime[0] = isprime[1] = false;
    for(ll i = 2 ; i<N ; i++)
    {
        if(isprime[i])
        {
            for(ll j=2*i ; j<N ; j+=i)
            {
                isprime[j] = false;
                if(spf[j]==0)
                {
                    spf[j] = i;
                }
            }
            prime.pb(i);
        }
    }
}*//*
ll nck(ll n , ll k ,ll m=1e18+7)
{
    ll i , j,b=1,c=1 ;
    if(n-k<k)
    {
        k = n-k ;
    }
    while(k)
    {
        b*=n ;
        c*=k ;
        ll g = __gcd(b,c) ;
        b/=g ;
        c/=g ;
        n--;
        k-- ;
    }
    return(b) ;
}*/
long long power(long long k , long long n , long long m=mod)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}
ll n,m,k;
int main()
{
    FastIO ;
    PRECISION(10) ;
    ll a,b,c,d,i,j,t,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    cin>>x>>y>>a>>b>>c;
    vll red,green,col;
    READ(red,a);
    READ(green,b);
    READ(col,c);
    sort(rall(red));
    sort(rall(green));
    sort(rall(col));
    vll v;
    for(i=0 ; i<x ; i++)
    {
        col.pb(red[i]);
    }
    for(i=0 ; i<y ; i++)
    {
        col.pb(green[i]);
    }
    sort(rall(col));
    c = 0;
    for(i=0 ; i<x+y ; i++)
    {
        c+=col[i];
    }
    cout<<c;
}

Measured memory_bytes: 7792
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, m) = (v[0], v[1]);
    let a = read_vec::<i64>();
    let ans = n - a.iter().sum::<i64>();
    if ans < 0 {
        println!("-1");
        return;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2236
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[100000];
    int n,x;
    cin>>n>>x;
    for(int i=0;i<n;++i) cin>>a[i];
    int dem=0;
    for(int i=0;i<n;++i){
        x-=a[i];
        if(x>=0){
            dem++;
        }
        else break;
    }
    if(x>0){
        sort(a,a+n);
        cout<<dem+x/a[0];
    }
    else cout<<dem;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main(void) {
	int n, m;
	int ans = 1;

	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)ans *= 2;
	ans *= (100 * (n - m) + 1900 * m);
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.buffer.readline

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)








Measured memory_bytes: 53780
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int n,m,i,j,k,p,l=0,q;
	string st1[100],st2[100];
	cin >> n >> m;
	for(i=0; i<n; i++)
		cin >> st1[i];
	for(i=0; i<m; i++)
		cin >> st2[i];
	for(i=0; i<=n-m; i++)
	{
		for(j=0; j<=n-m; j++)
		{
			q=0;
			for(k=0; k<m; k++)
			{
				for(p=0; p<m; p++)
					if(st1[i+k][j+p]!=st2[k][p]) q=1;
			}
			if(q==0) l=1;
		}
	}
	if(l==1) cout <<"Yes";
	else cout << "No";
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
sum = p.slice(0, k).inject(:+)
sum_max = sum
for i in k...n do
  sum = sum - p[i - k] + p[i]
  sum_max = sum if sum_max < sum
end
puts (sum_max + k).to_f / 2.0


Measured memory_bytes: 14980
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  int l = 1, r = N;
  for (int i=0;i<M;i++) {
    int L, R;
    cin >> L >> R;
    if (L > l) l = L;
    if (R < r) r = R;
  }
  if (l <= r) {
    cout << r-l+1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long  ll;

bool BinarySearch(const vector<int> &s, int x)
{
    int l = 0, r = s.size();

    while (l < r) {
        int mid = (l + r) * 0.5;

        if (x == s[mid])
            return true;

        if (x < s[mid])
            r = mid;
        else
            l = mid + 1;
    }

    return false;
}

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

    int n, q, t, ans = 0;

    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; ++i)
        cin >> s[i];

    sort(s.begin(), s.end());

    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        if (BinarySearch(s, t))
            ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1524
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;

#define MaxN 200005
#define MaxM MaxN*2
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
int N, M;
typedef pair<int,int> pii; 
struct Edge
{
    int u,v,w,next;
}edge[MaxM];
int cont;
int head[MaxN];
void add(int u, int v)
{
    edge[cont].u = u;
    edge[cont].v = v;
    edge[cont].w = 1;
    edge[cont].next = head[u];
    head[u] = cont++;
}
struct cmp
{                        //将优先队列改为小根堆
    bool operator()(pii a,pii b)
    {
        return a.first>b.first;
    }
};
int vis[MaxN];
int dis[MaxN];   //存储起点到每一个点的最短路

int Dijkstra(int s, int t)
{
    CLR(vis);
    for(int i=0;i<=N;i++) dis[i] = INF;
    dis[s] = 0;
    priority_queue<pii,vector<pii>,cmp> q;
    q.push(make_pair(0,s));
    while(!q.empty())
    {
        pii u = q.top();
        q.pop();
        if(vis[u.second]) continue;
        vis[u.second] = 1;
        for(int i=head[u.second];i!=-1;i=edge[i].next)
        {
            int to = edge[i].v;
            if(dis[to] > u.first + edge[i].w)
            {
                dis[to] = u.first + edge[i].w;
                q.push(make_pair(dis[to], to));
            }
        }
    }
    return dis[t];
}
void init()
{
    cont = 0;
    MST(head,-1);
}

int main()
{
    //std::ios::sync_with_stdio(false);
    while(~scanf("%d%d", &N, &M))
    {
        init();
        for(int i=0;i<M;i++)
        {
            int a, b;
            scanf("%d%d", &a, &b);
            add(a,b);add(b,a);
        }
        int ans = Dijkstra(1,N);
        if(ans==2) puts("POSSIBLE");
        else puts("IMPOSSIBLE");
    }
    //printf("%lld\n", ((x)%mod+mod)%mod );
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
}


Measured memory_bytes: 9976
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

char a[110][110];
int cnt[30];


int main()
{
  int i,j,k,m,n,tmp;
  int c4,c2,c1;
  vector<int> aa;
  scanf("%d%d",&m,&n);
  for (i=0;i<m;i++)
    scanf("%s",a[i]);
  memset(cnt,0,sizeof(cnt));
  for (i=0;i<m;i++)
    for (j=0;j<n;j++)
      cnt[a[i][j]-'a']++;
  aa.clear();
  for (i=0;i+i<m;i++)
    for (j=0;j+j<n;j++)
    {
      tmp=4;
      if (m-1-i==i) tmp/=2;
      if (n-1-j==j) tmp/=2;
      aa.push_back(tmp);
    }
  sort(aa.begin(),aa.end());
  reverse(aa.begin(),aa.end());
  for (i=0;i<aa.size();i++)
  {
    for (j=0;j<26;j++)
      if (cnt[j]>=aa[i])
      {
        cnt[j]-=aa[i];
        break;
      }
    if (j==26)
    {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep (i, n) cin >> a[i];

  int ans = 0;
  int i = 0;
  while (i < n - 1) {
    i += (k - 1);
    ++ans;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3756
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int S, W; cin >> S >> W;
    cout << (W >= S ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
const int P=1e9+7,N=1e5+7;
typedef long long i64;
struct mat{
	int a[3][3];
	mat operator*(const mat&w)const{
		mat r;
		for(int i=0;i<3;++i)
		for(int j=0;j<3;++j)
			r.a[i][j]=((i64)a[i][0]*w.a[0][j]+(i64)a[i][1]*w.a[1][j]+(i64)a[i][2]*w.a[2][j])%P;
		return r;
	}
};
mat  I=((mat){1,0,0, 0,1,0, 0,0,1});
mat m0=((mat){1,0,0, 1,1,0, 1,2,1});
mat m1=((mat){1,0,1, 0,1,0, 0,0,1})*m0;
mat pw1[33333],pw2[33333],ans=I;
int n,m,xs[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)scanf("%d",xs+i);
	xs[m+1]=n;
	pw1[0]=pw2[0]=I;
	for(int i=1;i<=32768;++i)pw1[i]=m1*pw1[i-1];
	for(int i=1;i<=32768;++i)pw2[i]=pw2[i-1]*pw1[32768];
	for(int i=1;i<=m+1;++i){
		int d=xs[i]-xs[i-1]-1;
		ans=pw1[d&32767]*ans;
		if(d>>15)ans=pw2[d>>15]*ans;
		ans=m0*ans;
	}
	printf("%d\n",ans.a[2][0]);
	return 0;
}

Measured memory_bytes: 2944
#!/usr/bin/env python3
#AGC3 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [I() for _ in range(n)]
b = sorted(a)
lst = []
for i in range(n):
    if a[i] != b[i]:
        r = bl(b,a[i])
        if i % 2 ^ r % 2 == 0:
            continue
        lst.append(a[i])
m = len(lst)
ans = m//2
print(ans)


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

int main() {
    int A[3], K; cin >> A[0] >> A[1] >> A[2] >> K;
    for (int i = 0; i < K; ++i) {
        if (A[0] >= A[1]) {
            A[1] *= 2;
            continue;
        }
        if (A[1] >= A[2]) {
            A[2] *= 2;
            continue;
        }
    }
    if (A[0] < A[1] && A[1] < A[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
import Control.Applicative

func m f r | (m==(-1)) || (f==(-1)) = "F"
		   | m+f>=80			= "A"
		   | m+f>=65			= "B"
		   | m+f>=50			= "C"
		   | m+f>=30			= if r>=50 then "C" else "D"
		   | otherwise			= "F"

main = do
	l <- init . map(map(read::String->Int)) . map words . lines <$> getContents
	let l2 = [ func (t!!0) (t!!1) (t!!2) | t<-l ]
	mapM_ putStrLn $ l2

Measured memory_bytes: 4084
K = int(input())
S = input()

mod = 10**9 + 7

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(n+1)]
        self.invs = [1 for i in range(n+1)]
        
        for i in range(1, n+1):
            self.facts[i] = self.facts[i-1] * i % mod
            self.invs[i] = pow(self.facts[i], mod-2, mod)

    def ncr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

    def nhr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.ncr(n+r-1, n-1)

N = K+len(S)
pow25 = [1] * (N+1)
pow26 = [1] * (N+1)
for i in range(1, N+1):
    pow25[i] = (pow25[i-1] * 25) % mod
    pow26[i] = (pow26[i-1] * 26) % mod

comb = Combination(K+len(S))

ans = 0
for i in range(K+1):
    ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow25[N-i-len(S)] * pow26[i]) % mod

print(ans)

Measured memory_bytes: 217252
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int L = sc.nextInt();
		String S[] = new String[N];
		
		for(int i=0; i<N; i++){
			S[i] = sc.next();
		}
		
		Arrays.sort(S);
//		System.out.println(Arrays.toString(S));
		
		StringBuffer x = new StringBuffer();
		for(int i=0; i<N; i++){
			x.append(S[i]);
		}
		
		
		
		
		System.out.println(x);


	}
}


Measured memory_bytes: 9940
import itertools
N = int(input().strip())

ns = '753'

def dfs(s):
  cnt = 0
  if int(s) > N:
    return cnt
  cnt += all(c in s for c in ns) 
  cnt += sum(dfs(s + c) for c in ns)
  return cnt


ans = 0
for s in itertools.product('753', repeat=3):
  ans += dfs("".join(s))
print(ans)


Measured memory_bytes: 3060
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] s = new int[n];
			Queue<Integer> queue = new PriorityQueue<>();
			int sum = IntStream.range(0, n).map(i -> {
				s[i] = scanner.nextInt();
				if (0 != (s[i] % 10)) {
					queue.add(s[i]);
				}
				return s[i];
			}).sum();
			if (0 == (sum % 10)) {
				if (0 == queue.size()) {
					System.out.println(0);
				} else {
					System.out.println(sum - queue.poll());
				}
			} else {
				System.out.println(sum);
			}
		}
	}
}


Measured memory_bytes: 26836
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

int N, X[1009], Y[1009], H[1009]; vector<tuple<int,int,int> >vec;

int main() {
  cin >> N; tuple<int,int,int>G = make_tuple(-1, -1, -1);
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> H[i];
		if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			int V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j);  bool flag = true;
			for (int k = 1; k <= N; k++) {
			  int VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV,0);
				if (H[k] != VV) flag = false;
			}
			if (flag == true) vec.push_back(make_tuple(i, j, V));
		}
	}
	if (vec.size() == 1) {
		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define zero_pad(num) setfill('0') << std::right << setw(num)
const int MOD=1e9+7;
const int INF=1e18;



signed main(){
    int N,K;cin>>N>>K;
    if(K>(N-1)*(N-2)/2)cout<<-1<<endl;
    else{
        vector<pair<int,int>>A;
        REP(i,N-1)A.pb({1,i+2});
        bool isused[N-1][N-1];
        REP(i,N-1)REP(j,N-1)isused[i][j]=false;
        REP(k,(N-1)*(N-2)/2-K){
            for(int i=2;i<N;i++){
                bool ok=false;
                for(int j=i+1;j<=N;j++){
                    if(!isused[i-2][j-2]){
                        A.pb({i,j});
                        isused[i-2][j-2]=true;
                        ok=true;
                        break;
                    }
                }
                if(ok)break;
            }
        }
        cout<<A.size()<<endl;
        REP(i,A.size()){
            cout<<A[i].first<<" "<<A[i].second<<endl;
        }
    }
}

Measured memory_bytes: 512
n = gets.chomp.to_i
d, x = gets.chomp.split(" ").map(&:to_i)
a = []
for i in 0...n
    a[i] = gets.chomp.to_i
end
x += n
for i in 0...n
    x += d / a[i]
    if d % a[i] == 0
        x -= 1
    end
end
print(x)

Measured memory_bytes: 1788
import numpy as np
N = int(input())
L = np.array(input().split(),dtype = int)

m = min(N,max(L))

r = np.array(np.linspace(1,m,m),int)


dp = [0 for i in range(N+1)]

for i in range(0,N):
    if dp[i]+1 ==L[i]:
        dp[i+1] = dp[i]+1
    else:
        dp[i+1] = dp[i]

a = max(dp)
if a == 0:
    print(-1)
else:
    print(N-a)

Measured memory_bytes: 33844
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let ab: Vec<_> = (0..n)
        .map(|_| (sc.read::<u64>(), sc.read::<u64>()))
        .collect();
    match ab.iter().filter(|&&(a, b)| a > b).map(|&(a, b)| b).min() {
        Some(b) => {
            let sum: u64 = ab.into_iter().map(|(a, _)| a).sum();
            println!("{}", sum - b);
        }
        None => {
            println!("0");
        }
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

const int ms[] = {0, 2, 5, 5, 4, 5, 6, 3 ,7 ,6};

signed main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for(auto &a : A) cin >> a;
	// dp[i]: i個マッチ棒を使って最大の数
	vector<string> dp(N+1, "");
	dp[0] = "";
	for(int i=0;i<=N;i++) {
		if(i != 0 and dp[i] == "") continue;
		for(int j=0;j<M;j++) {
			string nxst = dp[i] + char('0' + A[j]);
			if(i + ms[A[j]] <= N) {
				if(dp[i+ms[A[j]]].size() < nxst.size()) {
					dp[i+ms[A[j]]] = nxst;
				} else if(dp[i+ms[A[j]]].size() == nxst.size()) {
					if(dp[i+ms[A[j]]] < nxst) {
						dp[i+ms[A[j]]] = nxst;
					}
				}
			}
		}
	}
	cout << dp[N] << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  if (S < T) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
//~ int const MOD = 1e9 + 7;
int const MOD = 998244353;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
    a[i] %= k;
  }
  //~ error(a);
  for (int i = 1; i <= n; ++i) {
    a[i] -= i % k;
    if (a[i] < 0) a[i] += k;
  }
  //~ error(a);
  map<int,int> m;
  m[0] = 1;
  i64 ans = 0LL;
  for (int i = 1; i <= n; ++i) {
    if (i - k >= 0) {
      m[a[i - k]]--;
      //~ if (m[a[i - k]] == 0) {
        //~ m.erase(a[i - k]);
      //~ }
    }
    ans += m[a[i]];
    m[a[i]]++;
  }
  kek(ans);
  
  return 0;
}

//~ a[j] - a[i] == j - i
// 1 0 2 3 5


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

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

int main() {
    ll n;
    string s;
    cin >> n >> s;

    vector<string> l(s.size() + 5000, "Z");
    for (int i = 1; i <= n; i++) {
        l[i] = s[i - 1];
    }

    // rep(i, n + 2) cout << l[i] << endl;
    // sort(l.begin(), l.end());

    // 三色全てそろってない時ない時
    ll r = 0, g = 0, b = 0;
    for (int i = 1; i <= n; i++) {
        if (l[i] == "R") r++;
        if (l[i] == "G") g++;
        if (l[i] == "B") b++;
    }

    ll ans = r * g * b;
    // if (!ans) {
    //     cout << 0 << endl;
    //     return 0;
    // }

    ll i, k;
    for (ll j = 2; j < n; j++) {
        i = 1;
        k = 2 * j - i;
        for (int tmp = 1; tmp < j; tmp++) {
            // std::cout << i << " " << j << " " << k << " " << n << endl;
            // std::cout << l[i] << " " << l[j] << " " << l[k] << endl;
            // if (k <= 1 || k > n) continue;
            // if (i >= n) continue;
            if (l[i] != l[j] && l[i] != l[k] && l[j] != l[k] && 0 < i && i <= n && 0 < k && k <= n && l[i] != "Z" && l[j] != "Z" && l[k] != "Z") {
                ans--;
            }
            i++;
            k--;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vl a(n);
    ll sum = 0, ans = 1e18;
    rep(i, n) {
        std::cin >> a[i];
        sum += a[i];
    }

    ll l = 0;
    rep(i, n-1) {
        l += a[i];
        sum -= a[i];
        chmin(ans, abs(l-sum));
    }
    std::cout << ans << "\n";
}


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

int main() {
  long long int sum = 0, a, b, temp;
  cin >> a >> b;
  temp = b-a;
  for (long long int i=1; i<temp; i++) {
    sum+=i;
  }
  cout << sum-a;
  return 0;
}

Measured memory_bytes: 256
// ※※※ 解答不能 ※※※
// 以下の回答を参照.
// https://atcoder.jp/contests/abc179/submissions/16844205
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#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--)
#define pb push_back
#define a first
#define b second
const LL MOD = 998244353;
LL dp[202020];

int main(){
    
    // 1. 入力情報取得.
    int N, K;
    scanf("%d %d", &N, &K);
    vector<P> v;
    rep(i, K){
        int l, r;
        scanf("%d %d", &l, &r);
        v.pb({l, r});
    }
    
    // 2. マスN に 移動する方法の個数は？
    dp[0] = 1, dp[1] = MOD - 1;
    rep(i, N){
        if(i) dp[i] += dp[i - 1], dp[i] %= MOD;
        rep(j, K){
            int l = v[j].a;
            int r = v[j].b + 1;
            if(i + l < N) dp[i + l] += dp[i], dp[i + l] %= MOD;
            if(i + r < N) dp[i + r] += (MOD - dp[i]), dp[i + r] %= MOD;
        }
    }
    
    // 3. 出力.
    printf("%lld\n", dp[N - 1]);
    return 0;
    
}

Measured memory_bytes: 5312
from collections import Counter

x=int(input())
n=str(input())


#print(countN)
#abc
aaa=set([])
result=0
for i in range(x-2):
    a=n[i]
    if a not in aaa:
        aaa.add(a)
        bbb=set([])
        for j in range(i+1,x-1):
            b=n[j]
            if b not in bbb:
                bbb.add(b)
                ccc=set([])
                for k in range(j+1,x):
                    c=n[k]
                    if c not in ccc:
                        ccc.add(c)
                        result+=1
    if len(aaa)==10:
        break
print(result)



        

        
        




Measured memory_bytes: 42176
#include<stdio.h>
int main(){
int a,b,c,x,y,n[10000],i=0,p=0,m,k;
scanf("%d %d %d",&a,&b,&c);
for(x=1;x<=c;x++)
{
   for(y=x;y<=c;y++)
   {
   if(c==x*y)
   {
    if(x==y)
	{
	n[i]=x;
	i++;
	}
	else
	{
   n[i]=x;
   i++;
   n[i]=y;
   i++;
   }
   }
   }
}
k=a;
for(a=k;k<=b;k++)
{
 for(m=0;m<=i-1;m++)
 {
  if(n[m]==k)
  {
  p++;
  }
 }
}
printf("%d\n",p);
return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(B, A * N) << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	int h, w;
	string str[50];
	int answer[50][50] = {};
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> str[i];
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			answer[i][j] = 0;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (str[i][j] == '#') {
				for (int ii = -1; ii <= 1; ii++) {
					for (int jj = -1; jj <= 1; jj++) {
						if (0 <= i + ii&&i + ii <= h - 1 && 0 <= j + jj && j + jj <= w - 1) {
							answer[i + ii][j + jj] += 1;
						}
					}
				}
			}
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (str[i][j] == '#') {
				answer[i][j] = '#';
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
		if (str[i][j] == '#') {
			cout <<'#';
		}
		else {
			cout<<answer[i][j];
		}
		
	}
		if (i != h - 1)
			cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Map<Integer,PriorityQueue<Long>> List = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<n;i++){
            PriorityQueue<Long> L = new PriorityQueue<>(Collections.reverseOrder());
            List.put(i,L);
        }
        for(int i=0;i<q;i++){
            int cmd = sc.nextInt();
            int t = sc.nextInt();
            if(cmd==0){
                long x = sc.nextLong();
                List.get(t).add(x);
            }
            else if(cmd==1&&List.get(t).size()!=0)sb.append(List.get(t).peek()+"\n");
            else if(cmd==2&&List.get(t).size()!=0)   List.get(t).poll();
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 169736
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;
    if ( b/k*k>=a ) {
        cout << "OK" << '\n';
    }
    else {
        cout << "NG" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <bitset>
#include <math.h>
#include <vector>
#include <set>

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; }
const long long INF = 1LL<<60;

using namespace std;

int main(){
    int N, M;
    long long cost = 0;
    cin >> N >> M;

    vector<pair<long long, long long> > pairs(N);

    for(int i = 0; i < N; i++){
        cin >> pairs[i].first >> pairs[i].second;
    }

    sort(pairs.begin(), pairs.end());

    for(int i = 0; M != 0; i++){
        if(M - pairs[i].second >= 0){
            cost += pairs[i].first * pairs[i].second;
            M -= pairs[i].second;
        }
        else{
            cost += pairs[i].first * M;
            M = 0;
        }
        //cout << "M = " << M << endl;
        //cout << "cost = " << cost << endl;
    }

    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, W, w[101], v[101];
ll dp[100001], ans;
int main()
{
    IOS
    cin >> n >> W;
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int rem = W; rem>=w[i]; --rem) {
           dp[rem] = max(dp[rem], v[i]+dp[rem-w[i]]);

        }
    }
    cout << dp[W] << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] elm = br.readLine().split(" ");
		int n = Integer.parseInt(elm[0]);
		int m = Integer.parseInt(elm[1]);
		int[][] mat = new int[n][m];
		int[] vct = new int[m]; 
		int[] ans = new int[n];
		for(int i = 0; i < n ; i++){
			String[] line = br.readLine().split(" ");
			for(int j = 0; j < m ; j++){
				mat[i][j] = Integer.parseInt(line[j]);
			}
		}
		for(int i = 0; i < m ; i++){
			vct[i] = Integer.parseInt(br.readLine());
		}
		for(int i = 0; i < n ; i++){
			for(int j = 0; j < m ; j++){
				ans[i] += mat[i][j] * vct[j];
			}
		System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 27456
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


ll mod_pow(ll x,ll n, ll mod){
    if(n==0) return 1;
    ll res=mod_pow(x * x % mod, n/2, mod);
    if(n & 1) res=res * x % mod;
    return res;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll m,n;
    cin>>m>>n;
    cout<<mod_pow(m,n,MOD)<<endl;
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

using P = pair<int,int>;

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> stu;
    vector<tuple<int,int,int>> che;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        stu.push_back(make_pair(a,b));
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        che.push_back(make_tuple(a,b,i));
    }
    vector<int> ind(n);
    rep(i,n){
        int tm=INF;
        rep(j,m){
            int x,y,z;
            tie(x,y,z) = che[j];
            int t;
            t = abs(stu[i].first - x) + abs(stu[i].second - y);
            if(t<tm){
                tm = t;
                ind[i] = z;
            }
        }
    }
    rep(i,n){
        cout << ind[i]+1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;
vector<long long> a(100000,-1);
void waru(int,int);
void kaeru(int,int);
int n;
int main(void){
	long long tyo=-1;
	
	cin>>n;
	for(int lop=0;lop<n;lop++){
		cin>>a[lop];
	}
	a.resize(n+1);
	sort(a.begin(),a.end(),greater<long long>());
	
	//waru(0,n-1);
	
	/*for(int lop=0;lop<n;lop++){
		cout<<a[lop]<<' ';
	}*/
	
	for(int lop=0;lop<n;lop++){
		if(tyo>a[lop] && a[lop]==a[lop+1]){
			tyo=a[lop]*tyo;
			cout<<tyo<<endl;
			return 0;
		}
		if(a[lop]==a[lop+1] && a[lop]==a[lop+2] && a[lop]==a[lop+3]){
			tyo=a[lop]*a[lop];
			cout<<tyo<<endl;
			return 0;
		}else if(a[lop]==a[lop+1]){
			tyo=a[lop];
		}
	}
	cout<<0<<endl;
	return 0;
}

void waru(int hidari,int migi){
	int lop=0,lop2=0;
	
	for(lop=2;lop<n;lop*=2){
		for(lop2=0;lop2<n;lop2+=lop){
			kaeru(lop2,lop2+lop);
		}
	}
	return;
}

void kaeru(int hidari,int migi){
	int lop=0,lop2=0,num=0;
	
	for(lop=0;lop<migi;lop++){
		num=a[lop];
		for(lop2=lop-1;lop2>=0 && a[lop2]<num;lop2--){
			a[lop2+1]=a[lop2];
		}
		a[lop2+1]=num;
	}
	return;
}

Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    def root(x):
        if par[x] == x:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

    n,m = LI()
    p = LI()
    for i in range(n):
        p[i] -= 1
    par = [i for i in range(n)]
    rank = [0]*n
    for i in range(m):
        x,y = LI()
        x -= 1
        y -= 1
        if root(x) != root(y):
            unite(x,y)
    ans = 0
    for i in range(n):
        if root(p[i]) == root(i):
            ans += 1
    print(ans)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 96344
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;

#define ll                          long long

#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	int n,m;
	cin >> n >> m;
	int s= 0 ;
	forn(i,m){
		int a;
		cin>>a;
		s+=a;
	}
	if(s > n){
		cout <<-1;
		return 0;
	}
	cout << n-s;
}

Measured memory_bytes: 3616
#include<stdio.h>

int main(void){
    int a,n,i,min=1000000,max=-1000000;
    long int sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        sum+=a;
        if(min>a)
            min=a;
        if(max<a)
            max=a;
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}



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

typedef long long ll;
typedef pair<int, int> Pair;

const int N = 100005;
const ll INF = INT_MAX - 1;

ll n, h[N], dp[N];

ll get(int in){
  if(in == n) return 0;
  if(dp[in] != -1) return dp[in];
  ll ans = abs( h[in] - h[in + 1]) + get(in + 1);
  if(in != n - 1) ans = min(ans, abs( h[in] - h[in + 2]) + get(in + 2));
  return dp[in] = ans;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  cin >> n;
  for(int i = 1; i <= n; i++) cin >> h[i];
  memset(dp, -1, sizeof dp);
  cout << get(1) << endl;
}


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


int main() {
    int N,ans,tmp;
    cin >> N;
    ans = 0;
    tmp = 0;
    for(int i = 1; i <= N ;i++){
        tmp = 0;
        for(int j = 1; j <= i ;j++){
            if(i%j==0) tmp++;
        }
        if(tmp == 8 && i%2 == 1) ans++;
    }
    
    cout << ans << endl;

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define has_str(s, c)	((s).find(c) != string::npos)
typedef long long ll;
int main() {
#ifdef online_judge
    freopen("input.txt", "rt", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int red, green, blue;
    cin >> red >> green >> blue;
    int by_two;
    cin >> by_two;
    while (by_two > 0 && red >= green) {
        green *= 2;
        by_two--;
    }
    while (by_two > 0 && green >= blue) {
        blue *= 2;
        by_two--;
    }
    if(blue > green && green > red) {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	char prev = '?';
	for (auto c : s) {
		if (prev != c)
			ans++;
		prev = c;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=3e5+9;
int n,k;
string s;
int main(){
    cin>>n>>k>>s;
    k--;
    s[k]=tolower(s[k]);
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int W;
  int H;
  cin >> W >> H;
  while(W!=0&&H!=0){
      for(int i=0;i<H;i++){
          putchar('#');
      }putchar('\n');
      for(int i=0;i<W-2;i++){
          putchar('#');
          for(int j=0;j<H-2;j++){
              putchar('.');
          }
          putchar('#');
          putchar('\n');
      }
      if(H>1){
          for(int i=0;i<H;i++){
              putchar('#');
          }putchar('\n');
      }
      cin >> W >> H;
      putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    uint A, B;
    cin >> A >> B;
    if (A%3==0 || B%3 == 0 || (A+B)%3==0) cout << "Possible";else cout << "Impossible";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n,w;
    cin >> n >> w;
    int val[n],wt[n];
    for(int i=0;i<n;i++)
        cin >> wt[i] >> val[i];
    int kp[n+1][w+1];
    memset(kp,0,sizeof(kp));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j<wt[i-1])
                kp[i][j]=kp[i-1][j];
            else{
                kp[i][j]=max(kp[i-1][j],kp[i-1][j-wt[i-1]]+val[i-1]);
            }
        }
    }
    cout << kp[n][w];
}

Measured memory_bytes: 79104