akhauriyash/Code-Regression huggingface dataset:
n = input().split()
N = int(n[0])
K = int(n[1])

listb = [1]
listc = [0]*N
C = 1
A = list(map(int, input().split()))
                 
for i in range(N):
    C = A[C-1]
    if listc[C-1] == 0:
        listb.append(C)
        listc[C-1] = 1
    else:
        D = listb.index(C)
        listb.append(C)
        break

L = len(listb) -1

if K <= N:
    print(listb[K])
else:
    if L-D == 1 or L-D == 0:
        print(C)
    else:
        M = (K-D) % (L-D)
        print(listb[(D+M)%L])

Measured memory_bytes: 33888
def get_answer(ki):
    n = ki[0][0]
    q = ki[0][1]
    #n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    #q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    n_data = ki[1:-q]
    #q_data = ki[-q:]
    q_index = [0] * n
    for qq in ki[-q:]:
        q_index[qq[0] - 1] += qq[1]

    score = [0] * n

    """
        assert get_answer(["4 3",
                       "1 3", "1 4", "2 3",
                       "2 10", "1 100", "3 1"]) == "100 111 101 100"
    """
    t_index = []
    for i in range(0, n + 1):
        t_index.append([])
    for nn in n_data:
        t_index[nn[0]].append(nn[1])
        t_index[nn[1]].append(nn[0])

    t_stack = [1]
    s_stack = [0]
    r_flag = [0] * n
    while len(t_stack) > 0:
        i = t_stack.pop()
        s = s_stack.pop()
        if r_flag[i - 1]:
            continue
        r_flag[i - 1] = 1
        s += q_index[i - 1]
        score[i - 1] += s
        t_stack += t_index[i]
        s_stack += [s] * len(t_index[i])

    """
    s_value = str(score[0])
    for i in range(1, n):
        s_value += " " + str(score[i])
    """
    ss = [str(s) for s in score]
    return " ".join(ss)

# b05 1998 ms
if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break
            if len(input1) == 0:
                break
            s = input1.split(" ")
            input_ki.append([int(s[0]), int(s[1])])
        except EOFError:
            break
    print(get_answer(input_ki))


Measured memory_bytes: 132760
#include <cstdio>
#include <vector>
using namespace std;

using i64 = long long;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

signed main() {
	i64 n;
	scanf("%lld", &n);
	vector<i64> A(n + 1);
	REP(i, n + 1) {
		scanf("%lld", &A[i]);
	}
	i64 s = 0;
	REP(i, n) {
		i64 b;
		scanf("%lld", &b);
		i64 m = A[i] < b ? A[i] : b;
		s += m;
		b -= m;
		m = A[i + 1] < b ? A[i + 1] : b;
		s += m;
		A[i + 1] -= m;
	}
	printf("%lld", s);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using ll=long long;
using ld=long double;
#define inf INT_MAX  
const ll infll=1ll*inf*inf;
#define mode 998244353
#define mod 1000000007
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ub upper_bound 
#define lb lower_bound 
#define far(i,a,b) for (ll i = a; i <= b; i++)
#define rev(i,a,b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define sz(a) int((a).size())
#define ftr(c,i) for(auto i = begin(c); i != end(c); i++)
#define rtr(c,i) for(auto i = rbegin(c); i != rend(c); i++)
#define pre(c,x) ((c).find(x) != (c).end())
#define cpre(c,x) (find(all(c),x) != (c).end())
#define mll map<ll,ll>
#define vs vector<string>
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vii vector<pii >
#define vll vector<pll >
#define vvl vector<vector<ll> >
#define vvi vector< vector<int > >
#define W(t) while(t --)
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout <<(ll)(it-arr.begin()) << ')' <<  *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->ff<<' '<<it->ss << endl; cout << endl;
#define MID(i,j) ((i)+(j))/2
#define nl '\n' 
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
ll max(ll a,ll b) {return (a>b? a:b);}
ll min(ll a,ll b) {return (a>b? b:a);}
ll gcd(ll a,ll b) {return (b==0)? a:gcd(b,a%b); }
ll gcd(ll a,ll b,ll & x,ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll modinv(ll a,ll b){
	ll x,y;
	gcd(a, b, x, y);
	return (x%b + b)%b;
}
ll ceiling(ll a,ll b){ 
        if(a%b==0) return a/b;
        else return a/b+1;
}
ll powm(ll a,ll b,ll m){
	a%=m;
	ll res=1;
	while(b>0){
		if(b&1) res=(res*a)%m;
		b>>=1;
		a=a*a%m;
	}
	return res;
}
const int N=1e6+5;
ll n,m,q,t,k,x,y,z;
ll a,d;
vl p10(20);
ll dig(ll a){
	int ans=0;
	while(a>0) ans++,a/=10;
	return ans;
}
vvl mat_mul(vvl mat1,vvl mat2){
	vvl res(3,vl(sz(mat2[0]),0));
	far(i,0,2){
		far(j,0,sz(mat2[0])-1){
			far(k,0,2){
				res[i][j]=(res[i][j]+(mat1[i][k]*mat2[k][j])%m)%m;	
			}
		}
	}
	return res;
}
vvl mat_exp(vvl mat,ll p){
	vvl res(3,vl(3,0));
	res[0][0]=1;
	res[1][1]=1;
	res[2][2]=1;
	while(p>0){
		if(p&1) res=mat_mul(res,mat);	
		mat=mat_mul(mat,mat);
		p>>=1;
	}
	return res;
}
int main()
{
	fio;
	cin >> n >> a >> d >> m;
	p10[1]=10;
	far(i,2,18) p10[i]=p10[i-1]*10;
	vvl ans(3,vl(1));
	ans[0][0]=0;
	ans[1][0]=a%m;
	ans[2][0]=1;
	vvl mat(3,vl(3,0));
	mat[0][0]=p10[dig(a)]%m;
	mat[0][1]=1;
	mat[1][1]=1;
	mat[1][2]=d%m;
	mat[2][2]=1;
	while(x<n){
		mat[0][0]=p10[dig(a+x*d)]%m;
		y=(p10[dig(a+x*d)]-1-(a+x*d))/d;
		vvl mat1=mat_exp(mat,min(y+1,n-x));
		x+=min(y+1,n-x);
		ans=mat_mul(mat1,ans);	
	}
	cout << ans[0][0] << nl;


}


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

using namespace std;

int main(){
	string s;
	cin >> s;
	
	if(s.size()>=4){
		if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	
	return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    int c(0);
    for (int i=0; i<3; i++)
    {
        if (s[i] == t[i]) c++;
    }

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
int main(void){
  int q;
  double x;
  
    while(1){
        scanf("%d", &q);
        if(q == -1) break;
        x = q / 2.0;
        while(fabs(x * x * x - q) >= 0.00001 * q){
           x = x - (x * x * x - q) / (3 * x * x);
       }
       printf("%f\n", x);
   }
 return 0;
}



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

int main(){
  int n;
  cin >> n;
  int a[10];
  int all = 1, bad = 1;
  rep(i,n){
    scanf("%d", a+i);
    all *= 3;
    if(a[i]%2==0) bad*=2;
  }
  cout << all - bad << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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 Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  lint n;
  cin>>n;
  vector<bitset<33>> l;
  bitset<33> al(0);
  rep(i,n){
    lint j;cin>>j;
    bitset<33> t(j);
    al=al^t;
    l.pb(t);
  }

  rep(i,n){
    bitset<33> t=l[i];
    bitset<33> a;
    a=al^t;
    lint e=a.to_ulong();
    cout<<e<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 5332
#include <stdio.h>
 
int main() {
  int a[101][101] = {0};
  int b[101] = {0};
  int d[101] = {0};
  int i,j,r,c;
  int x;
  int e = 0;
 
  scanf("%d %d" , &r,&c);
 
  for(j=0; j<r; j++) {
    for(i=0; i<c; i++) {
      scanf("%d",&x);
      a[j][i] = x;
    }
  }
 
  for(j=0; j<r; j++){
    for(i=0; i<c; i++) {
      b[i] += a[j][i];
    }
  }
 
  for(j=0; j<r; j++){
    for(i=0; i<c; i++){
      d[j] += a[j][i];
    }
  }
 
  for(j=0; j<r; j++) {
    for(i=0; i<c; i++) {
      printf("%d ",a[j][i]);
    }
    printf("%d\n", d[j]);
  }
  for(i =0; i<c; i++) {
    printf("%d " ,b[i]);
    e += b[i];
  }
  printf("%d\n", e);
 
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// union-find tree

const int max_n = 100005;

int par[max_n];
int rnk[max_n];

void init(int n){
	rep(i,n){
		par[i] = i;
		rnk[i] = 0;
	}
}

// find root of tree with x
int find(int x){
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rnk[x] < rnk[y]) par[x] = y;
	else{
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

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

	int n, m;
	cin >> n >> m;

	vector<int> spk[m];
	rep(i, n){
		int k;
		cin >> k;
		rep(j, k){
			int l;
			cin >> l;
			l--;
			spk[l].push_back(i);
			// cout << k << "," << l << endl;
		}
	}

	init(n);

	rep(i, m){
		int sz = spk[i].size();
		if(sz >= 2){
			rep(j, sz-1){
				unite(spk[i][0], spk[i][j+1]);
			}
		}
	}

	bool ans = true;
	rep(i, n-1){
		if(!same(0, i+1)) {
			ans = false;
			break;
		}
	}

	cout << (ans ? "YES" : "NO") << endl;
}

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

#define PI 3.14159265358979323846264338327950L
#define ll long long
#define lli long long int

using namespace std;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
        ll h, w;
        cin >> h >> w;
        if (h == 1 || w == 1) {
            cout << 1 << "\n";
        } else {
            if (h * w % 2 == 0) {
                cout << h * w / 2 << "\n";
            } else {
                cout << h * w / 2 + 1 << "\n";
            }
        }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
bool flag = false;
string N;

void solve(){
    rep(i, 3){
        if(N[i] == '7') flag = true;
    }

    if(flag)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}

int main(){
    cin >> N;

    solve();
}
		


Measured memory_bytes: 3048
h,w,k = map(int, input().split())
sx,sy,gx,gy = map(lambda x: int(x)-1, input().split())
board = [list(map(lambda x: int(x=="."), input())) for i in range(h)]
inf = 1<<30
DP = [[inf for j in range(w)] for i in range(h)]
DP[sx][sy] = 0

que = [(sx,sy)]
dxdy = [(0,1),(1,0),(0,-1),(-1,0)]
for x,y in que:
    for dx,dy in dxdy:
        nx,ny = x,y
        for i in range(k):
            nx += dx
            ny += dy
            if not(0<=nx<h and 0<=ny<w and board[nx][ny] and DP[nx][ny] >= DP[x][y]+1):
                break
            if DP[nx][ny] == DP[x][y]+1:
                continue
            DP[nx][ny] = DP[x][y]+1
            que.append((nx,ny))
ans = DP[gx][gy]
if ans == inf:
    ans = -1
print(ans)


Measured memory_bytes: 217252
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if (s.size() >= 4 && s.substr(0, 4) == "YAKI")cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 768
def line_mainte(A,h):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append((h,i+1,h,i+2))
    return (len(output),output)

def row_mainte(A,w):
    output = []
    for i in range(len(A)-1):
        if A[i] % 2 != 0:
            A[i] -= 1
            A[i+1] += 1
            output.append((i+1,w,i+2,w))
    return (len(output),output)

H,W = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(H)]

count,procedure = 0,[]
for i in range(H):
    tmp = line_mainte(a[i],i+1)
    count += tmp[0]
    procedure += tmp[1]
row_W = [a[i][W-1] for i in range(H)]
tmp = row_mainte(row_W,W)
count += tmp[0]
procedure += tmp[1]

print(count)
for i in range(len(procedure)):
    for j in range(4):
        if j != 3:
            print(procedure[i][j],end=" ")
        else:
            print(procedure[i][j])


Measured memory_bytes: 22820
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int a[10],s,k,i,m;
    for(i=0;i<5;i++)
        cin>>a[i];
    k=a[0]%10;m=0;
    for(i=1;i<5;i++)
    {
        if(a[i]%10<k&&a[i]%10!=0)
        {
            k=a[i]%10;
            m=i;
        }
    }
    s=0;
    for(i=0;i<5;i++)
    {
        if(i!=m&&a[i]%10!=0)
            s+=(a[i]/10+1)*10;
        else if(i!=m)
        s+=a[i];
    }
    s+=a[m];
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = input()
flag = True
for i in range(n - m + 2):
    if s[i:i + m] == "1" * m:
        flag = False
        break
if flag == False:
    print(-1)
else:
    dice = []
    step = 0
    while step < n:
        if step + m > n:
            dice.append(n - step)
            break
        else:
            dice2 = m
            while s[-step - 1 - dice2] == "1":
                dice2 -= 1
            else:
                step += dice2
                dice.append(dice2)
    dice.reverse()
    dice = [str(dice[i]) for i in range(len(dice))]
    print(" ".join(dice))

Measured memory_bytes: 10364
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int x;
      cin>>x;

       long long int fac1=x/500;
      int rem = x % 500;

      long long int total = fac1*1000;

        rem = rem/5;

       total+=rem*5;

       cout<<total;   
}


Measured memory_bytes: 256
from itertools import combinations
n = int(input())
k, *b_arr = map(int, input().split())


def calc_int(arr):
    ret = 0
    for i in arr:
        ret += 1 << i
    return ret


subsets = []
for i in range(len(b_arr)+1):
    i_subsets = []
    for sub in combinations(b_arr, i):
        i_subsets.append((calc_int(sub), sub))
    subsets.extend(i_subsets)

subsets.sort()
for sub in subsets:
    print('{}: {}'.format(sub[0], ' '.join(map(str, sub[1])))) if len(sub[1]) != 0 else print(f'{sub[0]}:')


Measured memory_bytes: 65392
// 2020-08-17 06:04:17
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  map<int, int> mp;
  {
    vector<int> b(n);
    rep(i, n) {
      int a; cin >> a; a--;
      b[a]++;
    }
    rep(i, n) mp[b[i]]++;
  }
  vector<ll> sum1(n+2, 0), sum2(n+2, 0), ans(n+1, 0);
  repc(i, n) {
    sum1[i+1] = sum1[i] + i * mp[i];
    sum2[i+1] = sum2[i] + mp[i];
  }
  REPC(i, 1, n) {
    ll res = 0;
    res = sum1[i+1] + (sum2[n+1] - sum2[i+1]) * i;
    res /= ll(i);
    chmax(ans[res], ll(i));
  }
  REPCM(i, n-1, 1) chmax(ans[i], ans[i+1]);
  REPC(i, 1, n) cout << ans[i] << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 24156
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename x>
using ordered_set = tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>;
#define sorta(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n,greater<__typeof(a[0])>())
#define all(x) (x).begin(),(x).end()
#define ms0(x) memset((x),0,sizeof((x)))
#define ms1(x) memset((x),-1,sizeof((x)))
typedef pair<int,int> pi;
#define inarr(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define prinarr(arr) {for(int x:arr)cout<<x<<" ";} cout<<"\n";
#define cout1(a) cout<<a<<"\n";
#define cout2(a,b) cout<<a<<" "<<b<<"\n";
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define setpre(n) cout<<fixed<<setprecision(8)<<n<<"\n";
#define filldp(arr,n,m,k) for(int i=0;i<n;i++){for(int j=0;j<m;j++) arr[i][j]=k;}

#define mod 1000000007
#define mod1 998244353


vector<vector<int>> adj;
vector<int> dis;
vector<int> parent;
vector<bool> visited;

void newgr(int n){
    n+=10;
    adj=vector<vector<int>>(n);
    dis=vector<int>(n,0);
    //parent=vector<int>(n,-1);
    visited=vector<bool>(n,false);
}

void dfs(int s){
    visited[s]=true;
    for(auto u:adj[s]){
        if(!visited[u]){
            //parent[u]=s;
            dis[u]=dis[s]+1;
            dfs(u);
        }
    }
}

void bfs(int s){
    queue<int> q;
    q.push(s);
    visited[s]=true;
    dis[s]=0;
    while(!q.empty()){
        auto u=q.front();
        q.pop();
        for(auto x:adj[u]){
            if(!visited[x]){
                //parent[x]=u;
                visited[x]=true;
                dis[x]=dis[u]+1;
                q.push(x);
            }
        }
    }
}

long long power(long long x,long long y){  
    long long ans=1;
    x%=mod;
    while(y>0){
        if(y&1) ans=(ans*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return ans;
}

long long modinv(long long b){ 
    return power(b,mod-2);
}



int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int ans=0;
    int l,r,d;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++){
        if((i%d)==0)ans++;
    }
    cout1(ans);

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;
long long n;
int main()
{cin>>n;
long long n1=n%10,n3=n/100,n2=(n/10)%10;
if(n1==n2&&n2==n3)cout<<n;
else {
    while((n1!=n2||n2!=n3||n1!=n3))
    {n++;
        n1=n%10,n3=n/100,n2=(n/10)%10;
    }
cout<<n<<endl;
}
    return 0;
}


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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    int N, Q;
    cin >> N >> Q;
    V<> A(N);
    fenwick_tree<int> fw(N);
    REP(i, N) {
        cin >> A[i];
        fw.add(i, A[i]);
    }
    REP(i, Q) {
        int q, a, b;
        cin >> q >> a >> b;
        if(q == 0) {
            fw.add(a, b);
        }
        else {
            print(fw.sum(a, b));
        }
    }

    return 0;
}


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

#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define endl "\n"

#define for0(i, n) for (int i = 0; i < n; i++)
#define loop(i, a, b) for(int i = a;i <= b; i++)
#define forrev(i, n) for(int i = n; i >= 0; i--)
#define test_case(t) int t; cin >> t; while (t--)
#define debug(x) cout<< #x << "=" << x <<"\n";

typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

#define prec(n) fixed<<setprecision(n)
#define inf (int)(1e18)
#define MAX 1000002
#define MOD 1e9 + 7

long long int max(long long int a,long long int b){if(a>b) return a; else return b;}
long long int min(long long int a,long long int b){if(a<b) return a; else return b;}
bool isPrime(int N){
for(int i=2;i*i<=N;++i){
    if(N%i==0) return false;
    }
    return true;
}        

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

    int n;
    cin>>n;

    int a = 0, w = 0, t = 0, r = 0;

    while(n--)
    {
        string s;
        cin>>s;

        if(s == "AC")
         a++;

        else if(s == "WA")
         w++;

        else if(s == "TLE")
         t++;

        else if(s == "RE")
         r++;   
    }

    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;

      
    return 0;
}
//g++ -std=c++17 -Wshadow -Wall -O2 -Wno-unused-result



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

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> arr[2];
  vector<int> all(N);
  for(int i=0;i<N;++i) {
    cin>>all[i];
    arr[i&1].push_back(all[i]);
  }
  for(int t=0;t<2;++t)
    sort(arr[t].begin(), arr[t].end());
  sort(all.begin(),all.end());
  int res=0;
  for(int i=0;i<N;i+=2){
    if(!binary_search(arr[i&1].begin(),arr[i&1].end(), all[i])){
      ++res;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1276
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)
	min := 1 << 62
	for i := 0; i < len(S)-2; i++ {
		x := int(S[i]-'0')*100 + int(S[i+1]-'0')*10 + int(S[i+2]) - '0'
		if min > Abs(753-x) {
			min = Abs(753 - x)
		}
	}
	fmt.Println(min)
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 1768
N,W = list(map(int, input().split()))
m = []
v = []
for i in range(N):
    a,b = map(int, input().split())
    m.append(a)
    v.append(b)

sum_v = sum(v)
dp = [[10**15 for i in range(sum_v+1001)]for j in range(N+1)]
for i in range(N):
    dp[i][0] = 0
    for j in range(sum_v+1):
        if j != 10**15:
            dp[i+1][j+v[i]] = min(dp[i][j+v[i]],dp[i][j] + m[i])
            dp[i+1][j] = min(dp[i+1][j],dp[i][j])

for i in range(sum(v)+1):
    if  dp[-1][sum(v)-i] <= W:
        print(sum(v)-i)
        break

Measured memory_bytes: 171656
import java.util.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
      	BigInteger sum = BigInteger.valueOf(0);
		for(int i=1;i<=a;i++){
			if(i%3!=0&&i%5!=0) {
				sum=sum.add(BigInteger.valueOf(i));
			}
        }
      System.out.println(sum);
	}
}

Measured memory_bytes: 54420
def warshall_floyd(cost):
    ret = [[1]*N for _ in [0]*N]
    for k in range(N):
        for i, c_left in enumerate(cost[i][k] for i in range(N)):
            for j, (c_now, c_right) in enumerate(zip(cost[i], cost[k])):
                if c_left + c_right < c_now:
                    print(-1)
                    exit()
                if i == j or j == k or k == i:
                    continue
                if c_left + c_right == c_now:
                    ret[i][j] = ret[j][i] = 0
    return ret


INF = 10**10
N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*N)


E = []
for i in range(N):
    for j in range(i+1, N):
        E.append((A[i][j], i, j))
E.sort()

road = warshall_floyd(A)
ans = 0
for cost, i, j in E:
    if not road[i][j]:
        continue
    ans += cost

print(ans)


Measured memory_bytes: 66828
from itertools import accumulate

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

current_arr = A
if K > 41:
    print(*([N]*N))
    exit()
for _ in range(K):
    imos = [0] * N
    ruiseki = [0] * (N+1)
    for i, ai in enumerate(current_arr):
        imos[max([0, i-ai])] += 1
        if i+ai+1 < N:
            imos[i+ai+1] -= 1
    for j, im in enumerate(imos):
        ruiseki[j+1] = ruiseki[j] + im
    current_arr = ruiseki[1:]
#print(imos)
#print(ruiseki)
#print(*accumulate(imos))
print(*current_arr)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

    string ans;
    if(s.size() <= k) {
        ans = s;
    } else {
        rep(i, k) ans += s[i];
        ans += "...";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#ABC146 A
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
s = si()
if s=='SAT':
    print(1)
elif s=='SUN':
    print(7)
elif s=='MON':
    print(6)
elif s=='TUE':
    print(5)
elif s=='WED':
    print(4)
elif s=='THU':
    print(3)
elif s=='FRI':
    print(2)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef unsigned long long ull;
ull const Base = 1000;
int n,par[N],in[N];

ull bfs(){
  queue<int> Q;
  ull ans=0;
  map<ull,int> M[N];
  ull H[N]={},dep[N]={};
  for(int i=0;i<N;i++) H[i] = 1;
  for(int i=0;i<n;i++)if(!in[i]) Q.push(i),ans+=M[0][1]++,H[i]=1;
  
  
  while(!Q.empty()){
    int pos = Q.front();Q.pop();
    int nx = par[pos];
    ull &A = H[pos],&B = H[nx];
    dep[nx] = max(dep[nx],dep[pos]+1);
    B+=A*Base;
    if(--in[nx]==0)ans+=M[dep[nx]][B]++,Q.push(nx);
  }
  return ans;
}

int main(){
  cin>>n;
  for(int i=0,a,b;i<n-1;i++){
    cin>>a>>b;
    in[a-1]++,par[b-1] = a-1;
  }
  cout<<bfs()<<endl;
  return 0;
}

Measured memory_bytes: 16372
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  vector<vector<int>> a(3,vector<int>(3));
  for(int i = 0;i < 3;i++) {
    for(int j = 0;j < 3;j++) cin >> a.at(i).at(j); 
  }

  int n;
  cin >> n;
  vector<vector<bool>> c(3,vector<bool>(3,false));
  for(int i = 0;i < n;i++) {
    int b;
    cin >> b;
    for(int j = 0;j < 3;j++) {
      for(int k = 0;k < 3;k++) {
        if(a.at(j).at(k) == b) c.at(j).at(k) = true;
      }
    }
  }

  string ans = "No";
  for(int i = 0;i < 3;i++) {
    bool can = true;
    for(int j = 0;j < 3;j++) {
      can = can && c.at(i).at(j);
    }
    if(can) ans = "Yes";
  }
  for(int i = 0;i < 3;i++) {
    bool can = true;
    for(int j = 0;j < 3;j++) {
      can = can && c.at(j).at(i);
    }
    if(can) ans = "Yes";
  }

  if(c.at(0).at(0) && c.at(1).at(1) && c.at(2).at(2)) ans = "Yes";
  if(c.at(0).at(2) && c.at(1).at(1) && c.at(2).at(0)) ans = "Yes";

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll gcd(ll a, ll b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int INF = 1<<30;
int n;

vector<int> g[1005];

vector<int> bfs(int sv){
  vector<int> dist(n,INF),pre(n,-1);
  queue<int> q;
  dist[sv] = 0;
  q.push(sv);
  while(!q.empty()){
    int v = q.front(); q.pop();
    for (int u: g[v]){
      if(dist[u] != INF) continue;
      pre[u] = v;
      dist[u] = dist[v]+1;
      q.push(u);
    }
  }
  pair<int,int> best(INF,-1);
  rep(v,n){
    if(v == sv) continue;
    for (int u:g[v]){
      if(u == sv){
        best = min(best, make_pair(dist[v],v));
      }
    }
  }
  if(best.first == INF) return vector<int> (n+1);
  int v = best.second;
  vector<int> res;
  while(v != -1){
    res.push_back(v);
    v = pre[v];
  }
  return res;
}

int main(){
  int m; cin >> n >> m;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
  }
  vector<int> ans(n+1);
  rep(s,n){
    auto now = bfs(s);
    if(now.size() < ans.size()) ans = now;
  }
  if(ans.size() == n+1){
    cout << -1 << endl;
    return 0;
  }
  cout << ans.size() << endl;
  for(auto v:ans){
    cout << v+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 384
# coding: utf-8
from itertools import *
import sys
import time


#################### library ####################


#################### naive ####################


#################### process ####################


#################### main ####################

#t0 = time.clock()
a = int(raw_input())
s = raw_input()
if a < 3200:
	print 'red'
else:
	print s
#print >>sys.stderr, "%.6fsec" % (time.clock() - t0,)


Measured memory_bytes: 2688
N = gets.to_i

edges = Array.new(N + 1) { Array.new(N + 1, true) }

if N.even?
  1.upto(N) do |i|
    edges[i][N - i + 1] = false
    edges[N - i + 1][i] = false
  end
else
  1.upto(N - 1) do |i|
    edges[i][N - i] = false
    edges[N - i][i] = false
  end
end

ans = []

1.upto(N) do |a|
  1.upto(N) do |b|
    next if a == b
    next if !edges[a][b]

    ans << [a, b]
    edges[b][a] = false
  end
end

puts ans.size
puts ans.map { |a, b| [a, b].join(' ') }


Measured memory_bytes: 3452
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    rep(i,4){
        cout<<s[i];
    }
    cout<<" ";
    rep(i,8){
        cout<<s[4+i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
import math
import itertools
n=int(input())

a=list(map(str,input().split()))
b=list(map(str,input().split()))

a_str = [''.join(v) for v in itertools.permutations(a)]
a_int = [int(i) for i in a_str]
a_int.sort()

x="".join(a)
y="".join(b)

p=a_int.index(int(x))+1
q=a_int.index(int(y))+1

print(abs(p-q))


Measured memory_bytes: 7792
#include<cstdio>

int DP[10005]={0};

void set()
{
	DP[0]=1;
	for(int i=0;i<10000;i++)
	{
		DP[i+1]=DP[i]+i+1;
	}
}

int n;
int main()
{
	set();
	while(scanf("%d",&n)!=EOF)
	{
		printf("%d\n",DP[n]);
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
	public Main() {
		FastScanner scanner = new FastScanner();
		String S = scanner.next();
		
		String L = S.toLowerCase();
		
		if (S.equals(L)){
			System.out.println("a");
		} else {
			System.out.println("A");
		}
	}
	
	public static void main(String[] args) {
		new Main();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}
	
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 32440
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int w, h;
  while (cin >> w >> h, w) {
    vs v(h);
    int si, sj;
    rep(i, h) {
      cin >> v[i];
      rep(j, v[i].size()) if (v[i][j] == '@') {
        si = i;
        sj = j;
      }
    }
    queue<pii> q;
    q.emplace(si, sj);
    int c = 0;
    while (q.size()) {
      int i, j;
      tie(i, j) = q.front();
      q.pop();
      if (i < 0 || j < 0 || i >= h || j >= w || v[i][j] == '#') continue;
      c++;
      v[i][j] = '#';
      vi di = {0, 1, 0, -1}, dj = {1, 0, -1, 0};
      rep(k, 4) q.emplace(i + di[k], j + dj[k]);
    }
    cout << c << endl;
  }
}

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

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

    long ans = 1;

    for (int i = 1; i <= n; i++) {
        ans = (ans * i) % 1000000007;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#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 INF 1e9;
using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> data;

  UnionFind(int sz) { data.assign(sz, -1); }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) { return (-data[find(k)]); }
};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> p(n);
  REP(i, n) {
    cin >> p[i];
    --p[i];
  }

  UnionFind uf(n);
  REP(i, m) {
    ll x, y;
    cin >> x >> y;
    --x, --y;
    uf.unite(x, y);
  }
  ll ans = 0;
  REP(i, n) {
    if (uf.find(i) == uf.find(p[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}

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


int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	vector<int> v(n), ans(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	for(int i = 0; i < n; i++) {
		ans[v[i]-1] = i+1;
	}
	for(int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}

}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll k, a;
  string s;
  in2(k, s);
  if(s.size() <= k)
    out(s);
  else{
    rep(i, k)
      out(s[i]);
    rep(i, 3)
      out('.');
  }
  memi;
}

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

int main() {
    int n,m,votes=0;
    cin>>n>>m;
    int arr[n];
    for( int i=0;i<n;i++){
        cin>>arr[i];
        votes+=arr[i];
    }
    sort(arr,arr+n,greater<int>());
    double less=1/double(4*m);
    less*=votes;
    for (int i=0;i<n and m>0;i++){
        if (arr[i]>=less)
            m--;
    }
    if (m==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
        
}

Measured memory_bytes: 3644
import java.io.*;

//class Main{
class Main{
	public static void main(String[] arg){
		String buf;
		int num;
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			buf = br.readLine();
			num = Integer.parseInt(buf);
			System.out.println(num * num *num);
		} catch (Exception e){}
	}
}


Measured memory_bytes: 24108
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		long min=0, max=0, sum=0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a= new int[n];
		for (int i=0; i < n; i++) {
			a[i] = sc.nextInt();
			if (i == 0) {
				min = a[i];
				max = a[i];
				sum = a[i];
			} else {
				if (min > a[i]) {
					min = a[i];
				}
				if (max < a[i]) {
					max = a[i];
				}
				sum = sum + a[i];
			}
		}
		System.out.println(min + " " + max + " " + sum);
	}

}

Measured memory_bytes: 41684
n = int(input())
w = [input() for _ in range(n)]
result = 'Yes'

for i in range(0, n-1):
    en = len(w[i]) - 1
    if w[i][en] != w[i+1][0]:
        result = 'No'

nw = set(w)

if len(nw) != n:
    result = 'No'
print(result)

Measured memory_bytes: 3188
package main

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

type t struct {
	X int
	H int
}
type byX []t

func (a byX) Len() int           { return len(a) }
func (a byX) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byX) Less(i, j int) bool { return a[i].X < a[j].X }

func main() {
	N := readInt()
	D := readInt()
	A := readInt()
	XH := make([]t, N)
	for i := 0; i < N; i++ {
		XH[i].X = readInt()
		XH[i].H = (readInt() + (A - 1)) / A
	}

	sort.Sort(byX(XH))
	result := 0
	cs := make([]int, N)
	for i := 0; i < N; i++ {
		x, h := XH[i].X, XH[i].H
		if i != 0 {
			cs[i] += cs[i-1]
		}
		h -= cs[i]
		if h < 0 {
			continue
		}
		result += h
		cs[i] += h

		ok := i
		ng := N
		for ng-ok != 1 {
			m := ok + (ng-ok)/2
			if XH[m].X <= x+2*D {
				ok = m
			} else {
				ng = m
			}
		}
		if ng != N {
			cs[ng] -= h
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> students(n);
    rep(i, n) {
        cin >> students[i].first;
        cin >> students[i].second;
    }

    vector<P> checkpoints(m);
    rep(i, m) {
        cin >> checkpoints[i].first;
        cin >> checkpoints[i].second;
    }

    for (P p : students) {

        ll max_distance = INF;
        ll max_index = 0;

        for (int i = 0; i < m; i++) {
            P c = checkpoints[i];
            ll h = abs(p.first - c.first);
            ll w = abs(p.second - c.second);
            ll distance = h + w;
            if (distance < max_distance) {
                max_index = i;
                max_distance = distance;
            }
        }

        cout << max_index + 1 << endl;

    }


}



Measured memory_bytes: 256
loop do
  h,w = gets.split.map(&:to_i)
  break if h == 0 && w == 0

  1.upto(h) do |v|
    if v.odd?
      1.upto(w) do |wv|
        if wv.odd?
          print '#'
        else
          print '.'
        end
      end
    else
      1.upto(w) do |wv|
        if wv.odd?
          print '.'
        else
          print '#'
        end
      end
    end
    puts
  end
  puts
end

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

int main() {
    int a,b,res;
    cin>>a>>b;
    res=a%500;
    if(res<=b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 256
template<class T> inline void chmin(T & a, T b) { if (a > b) a = b; }

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

void solve() {
	llong N, K; cin >> N >> K;
	vector<llong> h(N);
	rep(i, N) scanf("%lld", &h[i]);

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

	llong res = (1LL << 60);
	for (int i = 0; i + K - 1 < N; i++) chmin(res, h[i + K - 1] - h[i]);
	cout << res << endl;
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  string s;
  cin>>s;
  int cnt[26];
  memset(cnt, 0, sizeof(cnt));
  int n = s.size();
  for (int i =0 ; i < n; ++i) {
  	cnt[s[i]-'a']++;
  }
  int i;
  for (i = 0; i < 26; ++i) {
  	if (cnt[i] % 2) break;
  }
  if (i >= 26) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
import copy
import sys
from _operator import itemgetter
from collections import Counter
from math import log2, pi, ceil

stdin = sys.stdin

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

n, l = na()
m = n * (n + 1) // 2 + (l - 1) * n
li = []
for i in list(range(l + 1 - 1, l + n)):
    li.append((abs(i), i))
print(m - sorted(li, key=itemgetter(0))[0][1])

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main() {
  int K,S,Z,res=0;
  cin>>K>>S;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
        int Z=S-i-j;
        if(Z<0||Z>K)continue;
        res++;
      }
    }
  cout<<res;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<functional>
#define For(i, N) for (i = 0; i < N; i++)
#define rep(N) for (int i = 0; i < N; i++)

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

int main() {
	int N;
	vb v;
	int d;
	int ans = 0;
	cin >> N;
	rep(101)v.push_back(false);
	while (cin >> d) v[d] = true;
	for (bool b : v)if (b)++ans;
	say(ans);
}

Measured memory_bytes: 256