akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;
 
void Main()
{
  int K;
  int N;
  
  cin >> K;
  cin >> N;
  
  int A[N];
  int S[N];
  
  for(int i=0 ; i < N; i++){
	 cin >> A[i];
  }
  
  
     for(int i = 0; i < N; i++){
       if(i == 0){
         if(A[0] + (K - A[N-1]) > A[1] - A[0]){
          S[i] = K - (A[0] + (K - A[N-1]));
         }
         else{
          S[i] = K - (A[1] - A[0]);
         }
       }
       else if(i == N - 1){
         if(A[0] + (K - A[N-1]) > A[N-1] - A[N-2]){
          S[i] = K - (A[0] + (K - A[N-1]));
         }
         else{
          S[i] = K - (A[N-1] - A[N-2]);
         }
       }
       else{
       	if(A[i + 1] - A[i] > A[i] - A[i - 1]){
          S[i] = K - (A[i + 1] - A[i]);
        }
        else{
          S[i] = K - (A[i] - A[i - 1]);
        }
       }
     }
  
  int Ans = S[0];
  
  for(int i = 1; i < N; i++){
    if(Ans > S[i]){
      Ans = S[i];
    }
  }
  
  printf("%d", Ans);
  
  
  
  
    
	
	
}
 
int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define e erase
#define PB push_back
#define elif else if
#define forn(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
using namespace std;
	
typedef long long int lli;
typedef long int li;
typedef vector <int> vi;
typedef vector <long long int> vii;
	
	
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a, b;
	string inp;
	char simp;

	cin>>a>>inp>>b;

	simp = inp[b-1];

	forn(i, inp.length()){
		if(inp[i] != simp){
			inp[i] = '*';
		}
	}

	cout<<inp<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int n,t,x,y;
	cin>>n;
	int f=0;

	for(int i=0; i<n; i++) {
		cin>>t>>x>>y;
		if(!(x+y<=t&&(t-x-y)%2==0)) f=1;
	}
	if (f==0) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
lst = []
for i in range(3):
  l = list(map(int, input().split()))
  lst.append(l)
for i in range(1, 3):
  diff = lst[i][0] - lst[0][0]
  for j in range(3):
    lst[i][j] -= diff
  if lst[i] != lst[0]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 9148
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 1e5 + 17;

int n, a, b;
llong h[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	scanf("%d %d", &a, &b);

	forn (i, n)
		scanf("%lld", h + i);

	return true;
}

bool check(llong x)
{
	forn (i, n)
		h[i] -= x * b;

	llong cnt = 0;

	forn (i, n)
		if (h[i] > 0)
			cnt += (h[i] + a - 1) / a;

	forn (i, n)
		h[i] += x * b;

	return cnt <= x;
}

void solve()
{
	a -= b;
	int l = 0, r = inf;

	for (; l < r; )
	{
		int m = (l + r) / 2;

		if (check(m))
			r = m;
		else
			l = m + 1;
	}
	
	printf("%d\n", l);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,i,ans=1,vis[26];
char s[100005];
const ll mod=1e9+7;
int main()
{
	scanf("%lld",&n);
	scanf("%s",s);
	for(i=0;i<n;i++)vis[s[i]-'a']++;
	for(i=0;i<26;i++)ans=ans*(vis[i]+1)%mod;
	ans=(ans+mod-1)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort()
if n%2==1:
    m = n//2
    print(b[m]-a[m]+1)
else:
    m = n//2 - 1
    print(b[m]+b[m+1]-a[m]-a[m+1]+1)


Measured memory_bytes: 91568
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  switch(n % 10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
    default:
      break;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    vector<char>a(n);
    char c=getchar();
    forn(i,n)
    {
        a[i]=getchar();
    }
    int cnt=0,res=0;
    forn(i,n)
    {
        if(a[i]=='A')cnt=1;
        else if(cnt==1&&a[i]=='B')cnt++;
        else if(cnt==2&&a[i]=='C')
        {
            res++;
            cnt=0;
        }
        else cnt=0;     
    }
    printf("%d\n",res); 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

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

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;

    int n = s.size();

    rep(i, n) {
        char c = s[i];
        int pos = c - 'a';
        if (c == 'a') continue;
        if (26 - pos <= k) {
            s[i] = 'a';
            k -= 26 - pos;
        }
    }

    char c = s[n-1];
    int pos = c - 'a';
    k -= 26 - pos;
    k = ((k % 26) + 26) % 26;
    s[n-1] = 'a' + k;

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;
    while(cin>>n){
        for(int i=0;n;i++){
            if(n&1)
                cout<<pow(2,i)<<(n>>1?' ':'\n');
            // cout<<i<<" "<<n<<endl;
            n>>=1;
            // cout<<i<<" "<<n<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3380
# D - Friends

class UnionFind():
    
    # インデックスは0-start
    # 初期化
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        self.group = n
    
    # private function
    def root(self, x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]
    
    # x,yが属するグループの結合
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x==y:
            return
        
        if self.parents[x]>self.parents[y]:
            x,y = y,x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        self.group -= 1
    
    # x,yが同グループか判定
    def same(self, x, y):
        return self.root(x)==self.root(y)

    # xと同じグループの要素数を取得
    def size(self, x):
        return -self.parents[self.root(x)]

N,M = map(int,input().split())
friend = UnionFind(N)
for _ in range(M):
    x,y = map(int,input().split())
    friend.union(x-1,y-1)
ans = 0
for i in range(N):
    ans = max(ans,friend.size(i))
print(ans)

Measured memory_bytes: 76692
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  ll sum = accumulate(all(A), 0LL);
  int cnt = 0;
  rep(i, n) {
    if(A[i] >= (sum+4*m-1)/(4*m)) cnt++;
  }
  cout << (cnt >= m ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define int long long
#define ll long long
using namespace std;
signed main() {
	char a, b;
	cin >> a >> b;
	if ((a == 'H'&&b == 'H') || (a == 'D'&&b == 'D'))cout << 'H'<< endl;
	else cout << 'D' << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
import copy

n = int(input())
x = [int(i) for i in input().split()]
sortedx = copy.copy(x)
sortedx.sort()

m = sortedx[int((n+1)/2)]

for i in x:
    if i < m:
        print(sortedx[int(n/2)])
    else:
        print(sortedx[int(n/2-1)])

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

#define int long long


signed main() {
    
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
int mox[2][2]={{1,-1},{0,-1}},moy[2][2]={{-1,1},{-1,0}};
char str[5]="URDL";
void serch(int x,int y,int then)
{
    if(then==-1)then=3;
    if(x==0&&y==0){
        cout<<endl;
        exit(0);
    }
    for(int i=0;i<4;i++){
        int now=(then+i)%4,ka=now/2;
        if(now%2==0){
            if(y+moy[0][ka]<5&&y+moy[0][ka]>-1&&side[y+moy[1][ka]][x]=='1'){
                cout<<str[now];
                serch(x,y+moy[0][ka],now-1);
            }
        }
        else{
            if(x+mox[0][ka]<5&&x+mox[0][now/2]>-1&&Longitudinal[y][x+mox[1][ka]]=='1'){
                cout<<str[now];
                serch(x+mox[0][ka],y,now-1);
            }
        }
    }
}
int main()
{
    for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
    cin>>Longitudinal[4];
    cout<<"R";
    serch(1,0,0);
}

Measured memory_bytes: 1184
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 1145141919810;


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };

bool zikan[31][100001] = {};
ll n, c;
signed main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n >> c;
	REP(i, n) {
		ll start, end, ch;
		cin >> start >> end >> ch;
		for (int i = start; i <= end; i++) {
			zikan[ch][i] = true;
		}
	}

	ll maxch = 0;

	REP(i, 100001) {
		ll num = 0;
		REP(j, 31) {
			if (zikan[j][i])num++;
		}
		maxch = max(maxch, num);
	}

	cout << maxch << endl;


	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>

int main() {
  int i, j, k, bottom, top, temp, count = 0;
  scanf("%d %d", &bottom, &top);
  for(i = 1; i < 10; i++) {
    for(j = 0; j < 10; j++) {
      for(k = 0; k < 10; k++) {
        temp = 10001 * i + 1010 * j + 100 * k;
        if(bottom <= temp && temp <= top) count++;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 305;



int n, m, d, a[N][N], q, x, y, l, r;
vector < pair < int, pair < int, int > > > g[N * N * 2];
vector < int > pref[N * N * 2];

main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m >> d;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    cin >> q;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            g[a[i][j] % d].push_back(make_pair(a[i][j], make_pair(i, j)));
        }
    }
    for(int i = 0; i < d; i++){
        if(g[i].empty()){
            continue;
        }
        sort(g[i].begin(), g[i].end());
        x = g[i][0].second.first, y = g[i][0].second.second;
        pref[i].resize(g[i].size());
        pref[i][0] = 0;
        for(int j = 1; j < g[i].size(); j++){
            int nx = g[i][j].second.first, ny = g[i][j].second.second;
            pref[i][j] = pref[i][j - 1] + abs(nx - x) + abs(ny - y);
            x = nx;
            y = ny;
        }
        pref[i].push_back(pref[i].back());
    }
    for(int i = 1; i <= q; i++){
        cin >> l >> r;
        int it1 = lower_bound(g[l % d].begin(), g[l % d].end(), make_pair(l, make_pair(0ll, 0ll))) - g[l % d].begin();
        int it2 = upper_bound(g[l % d].begin(), g[l % d].end(), make_pair(r, make_pair(0ll, 0ll))) - g[l % d].begin();
        cout << pref[l % d][it2] - pref[l % d][it1] << "\n";
    }
}


Measured memory_bytes: 15488
S = input()
T = input()

lenS = len(S)
lenT = len(T)

ans = lenT
for i in range(lenS - lenT + 1):
    mem = 0
    for j, t in enumerate(T):
        if S[i + j] != t:
            mem += 1
    ans = min(ans, mem)
print(ans)

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

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

int X,Y;

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>X>>Y;
	
	cout<<(X-1)+(X<=Y)<<endl;
}


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



Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#define ll long long int
using namespace std;
vector <int>v[100001];
bool vis[100001]={false};
ll d[100001]={0};
void dfs(int s){
	ll mx=0;
	vis[s]=true;
	for(int i=0;i<v[s].size();i++){
		if(!vis[v[s][i]]){
			dfs(v[s][i]);
		}
	}
	for(int i=0;i<v[s].size();i++){
		mx=max(d[v[s][i]],mx);
	}
	d[s]=mx+1;
}
int main(){
	ll n=0,m=0,a=0,b=0,dis=0;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		v[a].push_back(b);
	}
	memset(vis,false,sizeof(vis));
	memset(d,0,sizeof(d));
	for(int i=1;i<=n;i++){
		if(!vis[i])	
		dfs(i);
	}
	for(int i=1;i<=n;i++){
		dis=max(d[i],dis);
	}
	cout << dis-1;
}


Measured memory_bytes: 8704
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string S;
    cin>>S;
    string s[4]={"dream","dreamer","erase","eraser"};
    reverse(S.begin(),S.end());
    int flag=-1;
    string res;
    for(int i=0;i<4;i++)    reverse(s[i].begin(),s[i].end());
    for(int i=0;i<S.size();){
        flag=-1;
        for(int j=0;j<4;j++){
            if(S.substr(i,s[j].size())==s[j]){
                flag=1;
                i+=s[j].size();
            }
        }
        if(flag==-1){
            res="NO";
            cout << res << endl;
            return 0;
        }
    }
    
    //cout<<endl<<S<<endl;
    //if(S=="")   res="YES";
    //else        res="NO";
    res="YES";
    cout<<res<<endl;
    return 0;   
}

Measured memory_bytes: 512
Scanf.scanf "%d %d" (fun x n ->
    let module S = Set.Make (struct type t = int let compare = compare end) in
    let p = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let set = Array.fold_left (fun set v -> S.add v set) S.empty p in
    let rec loop i =
        if not (S.mem (x - i) set) then x - i else
        if not (S.mem (x + i) set) then x + i else
            loop (i + 1)
    in
    loop 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 3888
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int[][] C = new int[10][10];
    for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) C[i][j] = scanner.nextInt();
    for (int k = 0; k < 10; k++) {
      for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
          C[i][j] = Math.min(C[i][j], C[i][k] + C[k][j]);
        }
      }
    }

    long res = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        int a = scanner.nextInt();
        if (a >= 0) {
          res += C[a][1];
        }
      }
    }
    System.out.println(res);
  }
}


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

int64_t f(vector<int> &a, int s) {
  int64_t ans = 0;
  for (auto x : a) {
    ans += a.end() - lower_bound(a.begin(), a.end(), s - x);
  }
  return ans;
}

int main() {
  int64_t n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  int lower = 0, upper = 1 << 18;
  while (upper - lower > 1) {
    int half = (lower + upper) / 2;
    int64_t p = f(a, half);
    if (p >= m) {
      lower = half;
    } else {
      upper = half;
    }
  }
  vector<int64_t> asum(n + 1);
  for (int i = 0; i < n; i++) asum.at(i + 1) = asum.at(i) + a.at(i);
  int64_t count = 0, ans = 0;
  for (auto x : a) {
    ans += asum.at(n) - asum.at(lower_bound(a.begin(), a.end(), upper - x) - a.begin());
    count += a.end() - lower_bound(a.begin(), a.end(), upper - x);
  }
  ans *= 2;
  ans += (m - count) * lower;
  cout << ans << endl;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli dp[63][200100];
vector<lli> v[200100];

void func(long long N, long long K, std::vector<long long> A){

    REP(i,0,N){
        v[A[i]].push_back(i);
    }
    dp[0][N] = 0;

    for(lli i=N-1;i>=0;i--){
        auto itr = lower_bound( v[A[i]].begin(), v[A[i]].end(), i+1);
        if(itr == v[A[i]].end()) dp[0][i] = v[A[i]][0] + 1;
        else dp[0][i] = dp[0][(*itr)+1];

        LOG2(i,dp[0][i]);
    }

    REP(i,0,62){
        REP(j,0,N+1){
            dp[i+1][j] = dp[i][dp[i][j]];
        }
    }

    K--;
    lli now = 0;
    REP(i,0,62){
        if(K&(1LL<<i)) now = dp[i][now];
    }

    //cout<<now<<endl;

    //ラストはシミュレーション
    vector<lli> ans;
    REP(i,now,N){
        auto itr = lower_bound(v[A[i]].begin(),v[A[i]].end(),i+1);
        if(itr == v[A[i]].end())ans.push_back(A[i]);
        else i = (*itr);
    }
    REP(i,0,ans.size())cout<<ans[i]<<" ";
    cout<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&A[i]);
    }
    func(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 114164
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

a,b = I()
print((a+b+1)//2)

Measured memory_bytes: 27136
_, *a = map(str.split, open(0))
U, R, D, L = "URDL"
INF = float("inf")
d = {}
for *z, u in a:
  d.setdefault(u, []).append([*map(int, z)])
N = INF
for A, B, S in [(U, D, "x, y"), (R, L, "y, x"), 
                (R, U, "x+y, x-y"), (D, L, "x+y, x-y"), 
                (U, L, "x-y, x+y"), (R, D, "x-y, x+y")]:
  n = p = -INF
  L = eval(f"[({S}, Q) for P, Q in [(A, 1), (B, 0)] for x, y in d.get(P, [])]")
  for x, y, r in sorted(L):
    if x != n:
      if r:n = x;p = y
    elif r:p = y
    else:N = min(N, (y - p)*5)
print("SAFE" if N == INF else N)

Measured memory_bytes: 136632
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

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

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


//main関数
int main() {
	int X,Y;
	scanf("%d %d",&X,&Y);
	for(int i=0;i<=X;i++) {
		int sakoda = (2*(X-i) + 4*i);
		if ( sakoda == Y ){
			printf("Yes");
			return 0;
		}
	}	
	printf("No");
	return 0;
}

Measured memory_bytes: 1736
n, m = map(int, input().split())
dp = [float('inf')]*(1<<n)
dp[0] = 0
for i in range(m):
    c = 0
    a, b = map(int, input().split())
    for j in list(map(int, input().split())):
        c |= 1<<(j-1)
    for k in range(1<<n):
        dp[c|k] = min(dp[c|k], dp[k]+a)
if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 50396
H,W=map(int,input().split())
a = [input() for i in range(H)]
b = []
for i in range(H):
  if a[i].count('.')!=W:
    b.append(a[i])

flags=[False]*W

for i in range(H):
  for j in range(W):
    if a[i][j] != '.':
      flags[j]=True

for i in range(len(b)):
  tmp=[]
  for j in range(W):
    if flags[j]:
      tmp.append(b[i][j])
  print(''.join(tmp))
    

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int a, b;
  while(cin>>a>>b && a){
    ll ans = 1e12;
    for(int i = 1; i * i <= a; i++)if(a % i == 0){
      for(int j = 1; j * j <= b; j++) if(b % j == 0){
        ll sum = 0;
        ll v[4] = {i, j, a / i, b / j};
        sort(v, v + 4);
        REP(k, 3) sum += (v[k + 1] - v[k]) * (v[k + 1] - v[k]);
        ans = min(ans, sum);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

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

#define i5 100002

int main(){
	int n;
	cin >> n;

	vector<tuple<string, int, int>> a;
	repp(i, n){
		string s;
		int p;
		cin >> s >> p;
		p = -p;
		a.emplace_back(s, p, i);
	}

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

	rep(i, n){
		int id;
		tie(ignore, ignore, id) = a[i];
		cout << id << endl;
	}

	return 0;
}

// ================================
// 
// AtCoder Beginner Contest 128 解説放送
// https://www.youtube.com/watch?v=m-Nov1EvGoc
// より
// ＊一部変更
// 
// ================================


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  ll n,p;
  cin >> n >> p;

  ll odd = 0,even = 0;

  rep(i,n)
  {
    ll buf;
    cin >> buf;
    buf % 2 == 0 ? even : odd += 1;
  }

  ll ans = pow(2,n-1);

  if(odd == 0)
  {
    if(p == 1)
    {
      ans = 0;
    }
    else
    {
      ans = pow(2,n);
    }
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

vector<vector<int>> A(3, vector<int>(3));
vector<vector<bool>> Bingo(3, vector<bool>(3, false));

void find(int n) {
  rep(i, 3) {
    rep(j, 3) {
      if (A[i][j] == n) {
        Bingo[i][j] = true; 
      }
    }
  }
}

bool check() {
  rep(i, 3) {
    bool tate = true;
    bool yoko = true;
    rep(j, 3) {
      if (Bingo[i][j] == false) {
        tate = false;
      }
      if (Bingo[j][i] == false) {
        yoko = false;
      }
    }
    if (tate || yoko) {
      return true;
    }
  }

  if (Bingo[0][0] && Bingo[1][1] && Bingo[2][2]) {
    return true;
  }

  if (Bingo[0][2] && Bingo[1][1] && Bingo[2][0]) {
    return true;
  }

  return false;
}

int main() {
  int n;
  vector<int> B;

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

  cin >> n;
  B.resize(n);
  rep(i, n) {
    int b;
    cin >> b;
    find(b);
  }

  cout << (check() ? "Yes" : "No");
}


Measured memory_bytes: 256
N = int(input())
s = []
for i in range(N):
    s.append(list(input()))
for i in range(N):
    s[i] = [int(j) for j in s[i]]

from collections import deque
from collections import defaultdict

g = defaultdict(set)

for i in range(N):
    for j in range(N):
        if s[i][j] == 1:
            g[i+1].add(j+1)
            g[j+1].add(i+1)

ans = -1
for i in range(N):
    q = []
    q.append(i+1)
    visit = [-1]*(N+1)
    visit[i+1] = 1
    temp = 0
    while q:
        nextq = []
        for now in q:
            for next in g[now]:
                if visit[next] == -1:
                    visit[next] = visit[now] + 1
                    nextq.append(next)
                else:
                    if abs(visit[next] - visit[now]) == 1:
                        continue
                    else:
                        temp = -1
        if temp == -1:
            break
        q = nextq[:]
    if temp != -1:
        ans = max(max(visit), ans)
print(ans)


Measured memory_bytes: 46060
local ffi=require"ffi"
ffi.cdef[[
int scanf(const char*,...);
int printf(const char*,...);
]]
local C=ffi.C

local function max(a,b)return a<b and b or a end

N=io.read"*n"
W=io.read"*n"
w,v={},{}for i=1,N do
w[i]=io.read"*n"
v[i]=io.read"*n"end

dp=ffi.new("int64_t[101][100001]")
for i=0,W do dp[0][i]=0 end

for i=1,N do
dp[i]={}
for j=0,W do
if(j<w[i])then dp[i][j]=dp[i-1][j]
else dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j])end
end
end
C.printf("%ld\n",dp[N][W])

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

bool isPrime(int x) {
    // x > 0
    if (x == 1) return false;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

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

    int n;
    while (cin >> n, n) {
        int ans = 0;
        for (int i = n + 1; i <= 2 * n; i++) {
            ans += isPrime(i);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3216
n, m = map(int, input().split())
A = []
b = []
c = []
for i in range(n):
    A.append(list(map(int, input().split())))
for j in range(m):
    b.append(int(input()))
for k in range(n):
    s = 0
    for l in range(m):
        s += A[k][l] * b[l]
    c.append(s)
for k in range(n):
    print(c[k])



Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

bool strong(string s){

    int n = s.length()-1;
    for(int i = 0; i<n/2; i++){
        if(s[i] != s[n-i]) return false;
    }

    string s1 = "";
    string s2 = "";

    for(int i = 0; i< n/2; i++){
        s1 += s[i];
        s2 += s[n-i];
    }

    for(int i = 0; i<s1.length(); i++){
        if(s1[i] != s1[s1.length()-1-i]) return false;
        if(s2[i] != s2[s1.length()-1-i]) return false;
    }

    return true;
}

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s; cin >>s;

    cout <<(strong(s)? "Yes" : "No") <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
	t=(t<<3)+(t<<1)+v-48;
	v=getchar();}
	return t;
}
inline int ksm(re int x,re int y){
	int ans=1;
	while(y){
		if(y&1)ans*=x;
		x*=x;
		y>>=1;
	}
	return ans;
}
long long n,k,ans;
signed main(){
	n=read();k=read();
	while(n>=ksm(k,ans))++ans;
	printf("%lld",ans);
}



Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <sstream>
#include<algorithm>
#include <cstdlib>
using namespace std;

int main()
{
    string s;
    cin>>s;
    stringstream geek(s);
    long long int x = 0;
    geek >> x;
    int a[20];
    int b[20];
    int c[20];
    int d[20];
    int i,j,k,m,n;
    i=s.length();
    for(j=0;j<i;j++)
    {
        a[j]=x%10;
        x=x/10;
    }
    reverse(a,a+i);
    for(k=0;k<i-2;k++)
    {
        b[k]=(a[k]*100)+(a[k+1]*10)+a[k+2];
    }
    m=abs(753-b[0]);
    for(k=1;k<i-2;k++)
    {
        n=abs(753-b[k]);
        if(n<m)
        {
            m=n;
        }
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

//DFS用の探索フラッグ
bool visit[55];

//隣接行列
vector<vector<bool> > gra(51, vector<bool>(51));

void dfs(int now, int n){
  visit[now] = true;
  rep(i, n+1){
    int next = i+1;
    //nextが未探索，辺が繋がっている
    if(visit[next] == false && gra[now][next] == true)
      dfs(next, n);
  }
}


//visitが全部trueならtrueを返す
bool check(int v_num){
  rep(i, v_num+1 )
    if(visit[i] == false)
      return false;
  return true;
}


int main(){
  int N, M;
  cin >> N >> M;
  int a[M], b[M];
  rep(i, M){
    cin >> a[i] >> b[i];
    gra[a[i] ][b[i] ] = true;
    gra[b[i] ][a[i] ] = true;
  }
  visit[0] = true;
  //入力終わり

  //M個の辺を順に無くしていき，適当な点(1でいいや)から
  //DFSで全ての点を辿れるかを確かめる

  int ans = 0;
  rep(i, M){
    //探索フラッグの初期化
    rep(i, N)
      visit[i+1] = false;

    //辺を無くす
    gra[a[i] ][b[i] ] = false;
    gra[b[i] ][a[i] ] = false;

    //探索
    dfs(1, N);
    
    //全ての頂点が訪問済みでなければ無くした辺はbrideである
    if(check(N) == false)
      ans++;
	
    //辺を元に戻す
    gra[a[i] ][b[i] ] = true;
    gra[b[i] ][a[i] ] = true;
  }
  
  //解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
  ll h, w;
  ll ans = 1e18;
  ll tmp;

  cin >> h >> w;

  // pattern 1 (横線2本)
  if ( h > 2 ) {
    switch (h % 3) {
      case 0: ans = min(ans, 0LL); break;
      case 1: ans = min(ans, w); break;
      case 2: ans = min(ans, w); break;
    }
  }

  // pattern 2 (縦線2本)
  if ( w > 2) {
    switch (w % 3) {
      case 0: ans = min(ans, 0LL); break;
      case 1: ans = min(ans, h); break;
      case 2: ans = min(ans, h); break;
    }
  }

  // pattern 3 (縦に1本引いたあと, 横に一本,
  // このとき横の引き方はなるべく真ん中寄りが Best っぽい)
  tmp = 1e18;
  for (ll ww = 1; ww <= w-1; ww++) {
    ll area1 = ww * h;
    ll area2 = (w-ww) * (h-h/2);
    ll area3 = h*w - area1 - area2;

    ll max_v = max(area1, max(area2, area3));
    ll min_v = min(area1, min(area2, area3));

    tmp = min(tmp, max_v-min_v);
  }
  ans = min(ans, tmp);

  // pattern 4 (横に1本引いたあと, 縦に一本,
  // このとき縦の引き方はなるべく真ん中寄りが Best っぽい)
  tmp = 1e18;
  // hh: 縦幅を全探索
  for (ll hh = 1; hh <= h-1; hh++) {
    ll area1 = hh * w;
    ll area2 = (h-hh) * (w-w/2);
    ll area3 = h*w-area1-area2;

    ll max_v = max(area1, max(area2, area3));
    ll min_v = min(area1, min(area2, area3));

    tmp = min(tmp, max_v-min_v);
  }
  ans = min(ans, tmp);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    vector a(n,0);
    vector b(n,0);
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) cin >> b[i];
    sort(b.rbegin(), b.rend());
//    debug(a);
//    debug(b);

    bool ans = true;

    for (int i=0; i<100; i++) {
        int front = 0;
        int back = n-1;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == b[i]) {
                cnt++;
                if (b[front] != b[i]) {
                    swap(b[front], b[i]);
                    front++;
                } else if (b[back] != b[i]) {
                    swap(b[back], b[i]);
                    back--;
                }
            }
        }
    }

    for (int i=0; i<n; i++) {
        if (a[i] == b[i]) ans = false;
    }

    if (ans) {
        cout << "Yes" << endl;
        for (int i=0; i<n; i++) {
            cout << b[i] << (i==n-1? "\n" : " ");
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4456
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=2e5+100;
typedef long long LL;
int n;
LL a[maxn],p[5];

int main(int argc, char const *argv[])
{
    while (scanf("%d",&n)!=EOF)
    {
        memset(a,0,sizeof(a));
        for (int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            a[i]+=a[i-1];
        }

        LL ans=3e14;
        for (int i=2;i<=n-1;i++)
        {
            int x=lower_bound(a+1,a+i+1,a[i]/2)-a;
            int y=lower_bound(a+1,a+n+1,a[i]+(a[n]-a[i])/2)-a;
            if (x!=1) x--;
            if (y!=i+1) y--;

            p[0]=a[x];
            p[1]=a[i]-a[x];
            p[2]=a[y]-a[i];
            p[3]=a[n]-a[y];
            ans=min(ans,abs(max(p[0],max(p[1],max(p[2],p[3])))-min(p[0],min(p[1],min(p[2],p[3])))));

            int x1=x+1,y1=y;
            p[0]=a[x1];
            p[1]=a[i]-a[x1];
            p[2]=a[y1]-a[i];
            p[3]=a[n]-a[y1];
            ans=min(ans,abs(max(p[0],max(p[1],max(p[2],p[3])))-min(p[0],min(p[1],min(p[2],p[3])))));

            int x2=x,y2=y+1;
            p[0]=a[x2];
            p[1]=a[i]-a[x2];
            p[2]=a[y2]-a[i];
            p[3]=a[n]-a[y2];
            ans=min(ans,abs(max(p[0],max(p[1],max(p[2],p[3])))-min(p[0],min(p[1],min(p[2],p[3])))));

            int x3=x+1,y3=y+1;
            p[0]=a[x3];
            p[1]=a[i]-a[x3];
            p[2]=a[y3]-a[i];
            p[3]=a[n]-a[y3];
            ans=min(ans,abs(max(p[0],max(p[1],max(p[2],p[3])))-min(p[0],min(p[1],min(p[2],p[3])))));
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 1664
package main

import (
	"fmt"
)

var D, N int

func main() {
	fmt.Scan(&D, &N)
	num := 0
	switch {
	case D == 0:
		num = 1
	case D == 1:
		num = 100
	case D == 2:
		num = 10000
	}
	if N < 100 {
		fmt.Println(num * N)
	} else {
		fmt.Println(num * 101)
	}
}


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

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

    vector<string> S(A);
    vector<string> SS(A);
    vector<int> P(A);
    vector<int> PP(A);
    for(int i = 0; i < A; i++){
        cin >> S.at(i) >> P.at(i);
        SS.at(i) = S.at(i);
        PP.at(i) = P.at(i);
    }

    for(int i = 0; i < A; i++){
        int j = i+1;
        while( j < A){
            if(S.at(i) > S.at(j)){
                swap(S.at(i), S.at(j));
                swap(P.at(i), P.at(j));
            }
            else if(S.at(i) == S.at(j)){
                if(P.at(i)< P.at(j)){
                    swap(S.at(i), S.at(j));
                    swap(P.at(i), P.at(j));
                }
            }
            j++;
        }
    }
    int t = 0;
    for(int i = 0; i < A; i++){
        for(int j = 0; j < A; j++){
            if(SS.at(j) == S.at(i) && PP.at(j) == P.at(i)){
                cout << j+1 << endl;
                break;
            }
        }
    }

}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector< vector<int> > a;
  
  char tmp;
  rep(i,h){
    vector<int> v;
    rep(j,w){
      cin >> tmp;
      if(tmp=='#') v.push_back(1); 
      else v.push_back(0);
    }
    a.push_back(v);
  }
  
  vector<int> empty_h,empty_w;
  rep(i,h){
    bool empty=true;
    rep(j,w){
      if(a[i][j]==1) empty=false;
    }
    if(empty) empty_h.push_back(i);
  }
  rep(j,w){
    bool empty=true;
    rep(i,h){
      if(a[i][j]==1) empty=false;
    }
    if(empty) empty_w.push_back(j);
  }
  
  reverse(empty_h.begin(),empty_h.end());
  reverse(empty_w.begin(),empty_w.end());
  
  for(int x : empty_h){
    a.erase(a.begin() + x);
  }
  for(int y : empty_w){
    rep(i,a.size()){
      a[i].erase(a[i].begin()+y);
    }
  }
  
  for(vector<int> v : a){
    for(int i : v){
      if(i==1) cout << "#";
      else cout << ".";
    }
    cout << endl;
  }
  
  return 0;
}


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

int N, X;
vector<int> A;

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

int main(void) {
	cin >> N >> X;
	A.resize(N);
	for (int i = 0; i < N; ++i) {
		int d;
		cin >> d;
		d = abs(d - X);
		A[i] = d;
	}

	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	int sz = A.size();
	int g = A[0];
	for (int i = 1; i < sz; ++i) {
		g = gcd(g, A[i]);
		if (g == 1)
			break;
	}

	int ans = g;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int H, N;
  cin >> H >> N;
  int t, sum = 0;
  REP(i, N) {
    cin >> t;
    sum += t;
  }
  cout << (H <= sum ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
void solve(){
	long n;
	cin>>n;
	vector<long> a;
	map<long,long> map;
	long v;
	for(int i=0;i<n;i++){
		cin>>v;
		a.push_back(v);
		if(map.count(v)){
			map[v]++;
		}
		else map[v] = 1;
	}
	long sum = 0;
	for(auto itr =map.begin();itr!=map.end();++itr){
		sum+= (itr->second * (itr->second -1))/2;
	}
	for(long i=0;i<n;i++){
		cout<<sum - map[a[i]] + 1<<"\n";
	}
	return;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output1.txt", "w", stdout);
//	#endif
	solve(); 
	return  0;
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int main()
{
  int H, W;
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    int ret = INF;
    for(int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if(c == 'c') {
        ret = 0;
      } else {
        ret += 1;
      }
      if(j > 0) cout << " ";
      if(ret < INF) cout << ret;
      else cout << -1;
    }
    cout << endl;
  }
  return(0);
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;

int H, W;
const int mod = 1e9 + 7;
char a[1005][1005];
long long dp[1005][1005];

// dp[i][j] = number of paths from (0,0) to (i,j)

long long rec(int i, int j)
{
    if (dp[i][j] != -1)
        return dp[i][j];

    if (i == 0 && j == 0)
        return dp[i][j] = 1;

    if (i == 0)
    {
        if (a[i][j] == '.')
            return dp[i][j] = rec(i, j - 1);
        else
            return dp[i][j] = 0;
    }

    if (j == 0)
    {
        if (a[i][j] == '.')
            return dp[i][j] = rec(i - 1, j);
        else
            return dp[i][j] = 0;
    }

    if (a[i][j] == '.')
        dp[i][j] = (rec(i - 1, j) + rec(i, j - 1)) % mod;
    else
        dp[i][j] = 0;
    return dp[i][j];
}

int main()
{
    cin >> H >> W;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cin >> a[i][j];

    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            dp[i][j] = -1;

    long long ans = rec(H - 1, W - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9216
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <cassert>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 17;
const int Maxm = 301;
const int Inf = 1000000000;

int GN, GM;
int A, B;
int D[Maxn][Maxn];
int mn[Maxm][Maxm];
int N;
vector <ii> neigh[Maxm];
int dist[Maxm];

int getFirst(int r, int c)
{
	return r * GM + c + 1;
}

bool Check(int val1)
{
	GN = val1; GM = 299 / GN;
	for (int i = 0; i < GN; i++)
		for (int j = 0; j < GM; j++)
			mn[i][j] = 0;
	for (int i = 0; i < A; i++)
		for (int j = 0; j < B; j++)
			for (int koefi = 0; koefi < GN; koefi++)
				for (int koefj = 0; koefj < GM; koefj++)
					mn[koefi][koefj] = max(mn[koefi][koefj], D[i][j] - koefi * (i + 1) - koefj * (j + 1));
	for (int i = 0; i < A; i++)
		for (int j = 0; j < B; j++) {
			bool ok = false;
			for (int koefi = 0; koefi < GN && !ok; koefi++)
				for (int koefj = 0; koefj < GM && !ok; koefj++)
					ok = koefi * (i + 1) + koefj * (j + 1) + mn[koefi][koefj] == D[i][j];
			if (!ok) return false;
		}
	return true;
}

int Get(int v, int t, int X, int Y)
{
	//printf("(%d, %d, %d, %d)\n", v, t, X, Y);
	fill(dist, dist + Maxm, Inf); dist[v] = 0;
	priority_queue <ii> Q; Q.push(ii(-dist[v], v));
	while (!Q.empty()) {
		int v = Q.top().second, d = -Q.top().first; Q.pop();
		if (dist[v] != d) continue;
	//	printf("v = %d, d = %d\n", v, d);
		if (t == v) return d;
		for (int i = 0; i < neigh[v].size(); i++) {
			ii u = neigh[v][i];
			if (u.second == -1) u.second = X;
			if (u.second == -2) u.second = Y;
			//printf("u = (%d, %d)  d = %d\n", u.first, u.second, dist[u.first]);
			if (d + u.second < dist[u.first]) {
				dist[u.first] = d + u.second;
				Q.push(ii(-dist[u.first], u.first));
			}
		}
	}
	return Inf;
}

int main()
{
	scanf("%d %d", &A, &B);
	for (int i = 0; i < A; i++)
		for (int j = 0; j < B; j++)
			scanf("%d", &D[i][j]);
	int siz;
	for (siz = 1; siz <= 299; siz++)
		if (Check(siz)) break;
	if (siz > 299) { printf("Impossible\n"); return 0; }
	N = GN * GM + 1;
	for (int i = 0; i < GN; i++)
		for (int j = 0; j < GM; j++) {
			neigh[getFirst(i, j)].push_back(ii(N, mn[i][j]));
			if (j + 1 < GM)
				neigh[getFirst(i, j)].push_back(ii(getFirst(i, j + 1), -2));
			if (i + 1 < GN)
				neigh[getFirst(i, j)].push_back(ii(getFirst(i + 1, j), -1));
		}
	int M = 0;
	for (int i = 1; i <= N; i++)
		M += neigh[i].size();
	for (int i = 0; i < A; i++)
		for (int j = 0; j < B; j++) {
			int g = Get(getFirst(0, 0), N, i + 1, j + 1);
			if (D[i][j] != g) assert(false);
		}
	printf("Possible\n");
	printf("%d %d\n", N, M);
	for (int i = 1; i <= N; i++)
		for (int j = 0; j < neigh[i].size(); j++) {
			printf("%d %d ", i, neigh[i][j].first);
			if (neigh[i][j].second == -1) printf("X\n");
			else if (neigh[i][j].second == -2) printf("Y\n");
			else printf("%d\n", neigh[i][j].second);
		}
	printf("%d %d\n", getFirst(0, 0), N);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define rep2(i, a, b) for(int i=a; i<=(int)(b); ++i)
#define all(v) v.begin(),v.end()
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int h, w;
  cin >> h >> w;
  char s[h][w];
  int d[h][w];
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  int b = 0;
  rep(i, h) rep(j, w) {
    cin >> s[i][j];
    d[i][j] = 0;
    if (s[i][j] == '.') ++b;
  }
  queue<pair<int, int>> q;
  q.emplace(0, 0);
  d[0][0] = 1;
  while (!q.empty()) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    rep(i, 4) {
      int new_y = y + dy[i];
      int new_x = x + dx[i];
      if (new_x < 0 || new_x >= w || new_y < 0 || new_y >= h || s[new_y][new_x] == '#' || d[new_y][new_x] != 0) continue;
      d[new_y][new_x] = d[y][x] + 1;
      q.emplace(new_y, new_x);
    }
  }
  if (d[h-1][w-1] == 0) cout << "-1\n";
  else cout << (b-d[h-1][w-1]) << endl;
}

Measured memory_bytes: 256