akhauriyash/Code-Regression huggingface dataset:
Akari = []
for i in range(3):
  Akari.append(list(map(int,input().split())))
A = sum(Akari,[])

N = int(input())
B = []
for i in range(N):
  B.append(int(input()))

for j in range(N):
  if B[j] in A:
    A[A.index(B[j])] = 0
ans = 'No'

for k in range(3):
  if A[k] == A[k+3] == A[k+6]:
    ans = 'Yes'
  elif A[3*k] == A[3*k+1] == A[3*k+2]:
    ans = 'Yes'
  elif A [0] == A[4] == A[8]:
    ans = 'Yes'
  elif A [2] == A[4] == A[6]:
    ans = 'Yes'
    
print(ans)

Measured memory_bytes: 3064
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, A, B = li_input()

    ansmax = min(A, B)
    ansmin = max(0, (A + B) - N)

    print(ansmax, ansmin)


main()


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N;
const ll MOD = 1e9 + 7;

int main()
{
	scanf("%lld",&N);

	map<ll,ll> fact;
	for(ll i = 1;i <= N;i++){
		ll t = i;
		for(ll j = 2;j * j <= t;j++){
			while(t % j == 0){
				fact [j]++;
				t /= j;
			}
		}
		if(t != 1) fact [t]++;
	}

	ll ans = 1;
	for(const auto& it : fact){
		(ans *= it.second + 1) %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
def solve(N, A, S):
    
    # s == 0 のa を組み合わせて s==1 の任意のa を張ることができれば0
    # 下から
    
    if int(S[-1]) == 1:
        return 1
    
    B = [None] * max(A).bit_length()
    for i in reversed(range(N)):
        a = A[i]
        s = int(S[i])
        
        if s == 0: #基底生成
            while a:
                l = a.bit_length()-1
                if B[l] == None:
                    B[l] = a
                    break
                a ^= B[l]
        else: # i以上の基底で張れなければ 1
            while a:
                l = a.bit_length()-1
                if B[l] == None:
                    return 1
                a ^= B[l]
    return 0

T = int(input())
for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    print(solve(N, A, S))

Measured memory_bytes: 9096
#include<iostream>
using namespace std;
long long int a[200005];
int main(){
	int n;
	cin>>n;
	int k;
	cin>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n-k;i++){
		if(a[i]<a[i+k]){
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
}



Measured memory_bytes: 5124
#include<stdio.h>
#include<string.h>

#define N 1010

#define max(a,b)((a) < (b)?(b) : (a))

int Q[N][N];
char i[N],j[N];

int A(void);

int main()
{
  int x = 0,n;
  scanf("%d\n",&n);
  while(x < n)
    {
      
      fgets(i, N, stdin);
      fgets(j, N, stdin);

      printf("%d\n",A());

      x++;
    }
  return 0;
}
int A(void)
{
  int i_size;
  int j_size;
  int x = 1,y = 1;

  i_size = strlen(i)-1;
  j_size = strlen(j)-1;

  memset(Q,0,sizeof(Q));

  for(x = 1;x < i_size+1;x++)
    {
      for(y = 1;y < j_size+1;y++)
	{
	  int mx = max(Q[x][y-1],Q[x-1][y]);
	  if(i[x-1] == j[y-1])
	    {
	      mx = max(mx,(Q[x-1][y-1]+1));
	    }
	  Q[x][y] = mx;
	}
    }
  return Q[i_size][j_size];
}



Measured memory_bytes: 5828
import java.util.Scanner;

class Main {
  
  public static void main(String args[]) {
    
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int x = n%10;
    
    if(x == 3)
      System.out.print("bon");
  	else if(x == 0 || x == 1 || x == 6 || x == 8)
       System.out.print("pon");
    else 
       System.out.print("hon");

  }
  
}
  
  
  
  



Measured memory_bytes: 35580
from copy import copy

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = copy(a)
b.reverse()

def count_more_x(x : int):
    j = 0
    ret = 0
    for i in range(len(b)):
        while j < len(a) and b[i]+a[j] < x:
            j += 1
        ret += j
    return n*n-ret

def sum_more_x(x : int):
    j = 0
    ret = 0
    for i in range(len(b)):
        while j < len(a) and b[i]+a[j] < x:
            j += 1
        ret += b[i]*(n-j)+c[j]
    return ret

lower = 0
upper = 1000000
while upper-lower > 1:
    middle = (upper+lower)//2
    if count_more_x(middle) < m:
        upper = middle
    else:
        lower = middle

left = lower

lower = 0
upper = 1000000
while upper-lower > 1:
    middle = (upper+lower)//2
    if count_more_x(middle) >= m:
        lower = middle
    else:
        upper = middle

right = upper

# print(left, right)
# print(count_more_x(right))
c = copy(a)
value = 0
for i in range(len(c)-1, -1, -1):
    value = value + c[i]
    c[i] = value
c.append(0)
ans = sum_more_x(right) + left*(m-count_more_x(right))
print(ans)



Measured memory_bytes: 61116
M, D = map(int, input().split())
ans = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        if d >= 10:
            d10 = int(str(d)[0])
            d1 = int(str(d)[1])
            if d1 >= 2 and d10 >= 2 and d1 * d10 == m:
                ans += 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int x,y,z;
	int ii = 0;
	while(1){
		ii++;
		scanf("%d%d",&x,&y);
		if(y == 0 && x == 0)break;
		if(x > y){
			z = y;
			y = x;
			x = z;
		}
		printf("%d %d\n",x,y);
		}
		
		
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */
int N;
vector<int> p;
vector<set<int>> ip;

// ip[x] := x のことが嫌いな人の集合
// x を右隣に置きたくない人の集合

bool check(const vector<int> &res) {
  for(int i = 0; i + 1 < res.size(); i++) {
    if(res[i + 1] == p[res[i]]) return false;
  }
  return true;
}

const int NOKORI = 5;

// res は確定，rem を全探索
void last(vector<int> &res, vector<int> &rem) {
  do {
    if(check(rem)) {
      for(int i = 0; i < res.size(); i++) cout << res[i] + 1 << " ";
      for(int i = 0; i < rem.size(); i++) cout << rem[i] + 1 << " ";
      cout << endl;
      return;
    }
  }while(next_permutation(ALL(rem)));
  cout << -1 << endl;
  return;
}


void solve() {
  if(N <= NOKORI) {
    vector<int> res, rem(N);
    for(int i = 0; i < N; i++) rem[i] = i;
    last(res, rem);
    return;
  }

  vector<int> res;
  set<int> rem;
  for(int i = 0; i < N; i++) rem.insert(i);
  while(N - (int)res.size() > NOKORI) {
    int dame = -1;
    if(res.size() > 0) dame = p[res.back()];
    

    // とりあえず貪欲に
    int ne = -1;
    for(auto it : rem) {
      if(it == dame) continue;
      ne = it;
      break;
    }
    
    // ne を選んでしまうと詰むときは取り替える
    if(ip[p[ne]].size() + res.size() == N - 1) {
      ne = p[ne];
    }

    // ne を選ぶ
    // drken さん，ここら辺が綺麗すぎる
    res.push_back(ne);
    rem.erase(ne);
    ip[p[ne]].erase(ne);
  }
  
  vector<int> vrem;
  for(int i = 0; i < N; i++) if(rem.count(i)) vrem.push_back(i);
  last(res, vrem);
}

int main() {
  cin >> N;
  p.resize(N);
  ip.assign(N, set<int>());
  for(int i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
    ip[p[i]].insert(i);
  }

  solve();
  return 0;
}


Measured memory_bytes: 15232
/*
ID: Nipun Paul
LANG: C++
PROB: God knows
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int a,b,c,d,lcm=0;
    cin>>a>>b>>c>>d;
    lcm=(c*d)/__gcd(c,d);
    a--;
    cout<<b-a-(b/c + b/d - b/lcm)+(a/c + a/d - a/lcm)<<endl;
    return 0;
}


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

int main() {
  int N, M;
  int A, B;
  vector<vector<int>> aisle(200001); 
  cin >> N >> M;
  for (int i=0;i<M;i++) {
    cin >> A >> B;
    aisle[A].push_back(B);
    aisle[B].push_back(A);
  }

  int dis[1000001], dir[100001]; // 距離と方向

  for (int i=1;i<N+1;i++) {
    dis[i] = 100000;
    dir[i] = 1;
  }
  dis[1] = 0;

  vector<int> roomlist;
  vector<int> roomlist_cp;

  roomlist.push_back(1);

  while(roomlist.size()) { // 更新できなくなるまで
    roomlist_cp = roomlist;
    roomlist.clear();
    for (int j: roomlist_cp) { // 部屋について
      for (int k: aisle[j]) { // 通路について
        if (dis[k] > dis[j]+1) {
          dis[k] = dis[j]+1;
          dir[k] = j;
          roomlist.push_back(k);
        }
      }
    }
  }

  cout << "Yes" << endl;
  for (int i=2;i<N+1;i++) {
    cout << dir[i] << endl;
  }
}

Measured memory_bytes: 13248
#include <stdio.h>

int main(){
	char ch;
	while((ch = getchar()) != EOF){
			if(ch >= 97 && ch <= 122)
				printf("%c",ch-32);
			else if(ch >= 65 && ch <= 90)
				printf("%c",ch+32);
			else
				printf("%c",ch);
	}
}



Measured memory_bytes: 2628
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    sort(S.begin(), S.end());
    if (S == "abc"){cout << YES<<endl;} else{cout<<NO<<endl;}
}

int main(){

    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}



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

int main()
{
    int N;
    int K;
    int have = 0;

    cin >> N >> K;

    vector<int> d(K);
    vector<int> A(N,0);

    for(int i = 0; i < K; i++){
        cin >> d[i];
        for(int j = 0;j < d[i]; j++){
            int num;
            cin >> num;
            A[num - 1] += 1;
        }
    }
    rep(i,N){
        if(A[i] != 0){
            have += 1;
        }
    }
    cout << N - have << endl;
}

Measured memory_bytes: 3624
import sys
from collections import deque


def main():
    n = int(input())
    a = deque()
    for _ in range(n):
        command = sys.stdin.readline().strip().split()
        if command[0] == 'insert':
            a.appendleft(int(command[1]))
        elif command[0] == 'delete':
            try:
                a.remove(int(command[1]))
            except:
                pass
        elif command[0] == 'deleteFirst':
            a.popleft()
        elif command[0] == 'deleteLast':
            a.pop()
    print(' '.join(map(str, a)))


if __name__ == "__main__":
    main()



Measured memory_bytes: 45944
#!/usr/bin/env python3
n = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(n-1,0,-1):
    if h[i-1] - h[i] == 1:
        h[i-1] -= 1
        ans = 1
    elif h[i] >= h[i-1]:
        ans = 1
    else:
        ans = 0
        break
if n == 1:
    print('Yes')
elif ans == 1:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 14224
#include <stdio.h>
int main(){
int n,i,x=0;
int a[100000]={};
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++){
if((a[a[i]-1]==i+1)&&i<a[i]){
x++;}
}
printf("%d\n",x);
return 0;}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int a[100100];
int main(){
	cin >> N;
	int cnt = 0;
	for(int i=0;i<N;i++){
		cin >> a[i];
		if(a[i]%2==0)cnt++;
	}
	if(cnt%2==1)cout << "First" << endl;
	else{
		int r = 0;
		while(1){
			int c = 0;
			int g = 0;
			int odd = -1;
			for(int i=0;i<N;i++){
				// cout << a[i] << ' ';
				if(a[i]%2==1){
					c++;
					g = __gcd(g,a[i]-1);
					odd = a[i];
				}else{
					g = __gcd(g,a[i]);
				}
			}
			if(c!=1)break;
			if(odd==1)break;
			for(int i=0;i<N;i++){
				if(a[i]%2==1)a[i]--;
				a[i] /= g;
			}
			c = 0;
			for(int i=0;i<N;i++){
				if(a[i]%2==0)c++;
			}
			if(c%2==0)r++;
			else break;
		}
		if(r%2==0)cout << "Second" << endl;
		else cout << "First" << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int n = 1e5;
    vector<int> p(n + 1, 1);
    p[0] = 0, p[1] = 0;
    for (int i = 2; i <= n; i++) {
        for (int j = 2; i * j <= n; j++) {
            p[i * j] = 0;
        }
    }
    vector<int> res(n + 1, 0);
    for (int i = 1; i <= n; i += 2) {
        if (p[i] == 1 && p[(i + 1) / 2] == 1) {
            res[i] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        res[i] += res[i - 1];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << res[r] - res[l - 1] << endl;
    }
}


Measured memory_bytes: 3848
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long k = scanner.nextLong();

        if (k < a) {
            System.out.println((a - k) + " " + b);
        } else {
            final long diff = k - a;
            System.out.println(0 + " " + Math.max(0, (b - diff)));
        }
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <string>
using namespace std;
int main()
{
    while(1)
    {
        string r,a;
        int hit=0;
        int blow=0;
        cin>>r>>a;if(r=="0")return 0;
        for(int i=0;i<4;++i){
            for(int j=0;j<4;++j){
                if(r[i]==a[j]){
                    if(i==j){
                        hit++;
                    }else{
                        blow++;
                    }
                }
            }
        }
        cout<<hit<<" "<<blow<<endl;
    }
    return 0;
}

Measured memory_bytes: 1184
from operator import mul
from functools import reduce

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
    if k >= 2:
      res += ncr(k, 2)

for k in A:
  temp = res
  m = d[k]
  if m >= 2:
    temp -= ncr(m, 2)

  d[k] -= 1
  if d[k] >= 2:
    temp += ncr(d[k], 2)
  print(temp)
  d[k] += 1


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

int main(void){
    string s, t;
    int a[26], b[26];
    cin >> s;
    cin >> t;
    for (int i = 0; i < 26; i++) a[i] = b[i] = 0;
    for (int i = 0; i < s.size(); i++) a[s[i] - 'a']++;
    for (int i = 0; i < t.size(); i++) b[t[i] - 'a']++;
    
    string sn, tn;
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < a[i]; j++) sn += 'a' + i;
    }
    for (int i = 25; i >= 0; i--) {
        for (int j = 0; j < b[i]; j++) tn += 'a' + i;
    }
    
    if (sn < tn) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    //cout << sn << endl << tn << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream &operator << (ostream &os, const vector<T> &);
template<size_t n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, const tuple<T...> &){}
template<size_t n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream &os, const tuple<T...> &t){
    os << (n == 0 ? "" : " ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T> ostream &operator << (ostream &os, const tuple<T...> &t){
    _ot<0>(os, t); return os;
}
template<class T, class U> ostream & operator << (ostream &os, const pair<T,U> &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T> ostream &operator << (ostream &os, const vector<T> &v){
    for(size_t i = 0; i < v.size(); i++) os << v[i] << (i + 1 == v.size() ? "" : ", "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << make_tuple(__VA_ARGS__) \
                   << " (L : " << __LINE__ << ")" << endl)
#else
#define dump(...)
#endif
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
void fastios(){ ios_base::sync_with_stdio(0); cin.tie(0); }
int const mod = 1000000007;
auto const inf = numeric_limits<int>::max()/8;

using Weight = long long;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

pair<vector<Weight>, bool> bellmanFord(const Graph &g, int s){
    int n = g.size(); const Weight inf = numeric_limits<Weight>::max() / 8;
    Edges es;
    for(int i = 0; i < n; i++) for(auto &e : g[i]) es.emplace_back(e);
    vector<Weight> dist(n, inf); dist[s] = 0;
    bool negCycle = false;
    for(int i = 0;; i++){
        bool update = false;
        for(auto &e : es){
            if(dist[e.src] != inf && dist[e.dst] > dist[e.src] + e.weight){
                dist[e.dst] = dist[e.src] + e.weight;
                update = true;
            }
        }
        if(!update) break;
        if(i > n) { negCycle = true; break; }
    }
    return make_pair(dist, !negCycle);
}

int V,E,r;

int main(){
    while(cin >> V >> E >> r){
        Graph g(V);
        rep(i,E){
            int a,b,c;
            cin >> a >> b >> c;
            g[a].eb(a,b,c);
        }
        auto ans = bellmanFord(g,r);
        if(ans.second){
            for(int i = 0; i < V; i++){
                if(ans.first[i] > 1e10) cout << "INF";
                else cout << ans.first[i];
                cout << endl;
            }
        } else {
            cout << "NEGATIVE CYCLE" << endl;
        }
    }
}

Measured memory_bytes: 3244
n,m = map(int,input().split())

a = []
for i in range(n):
    k = [int(j) for j in input().split()]
    a.append(k[1:])

ans = 0
for i in range(1,m+1):
    check = 0
    for j in a:
        if i not in j:
            check =1
            break
    if check == 0:
        ans += 1
print(ans)
        


Measured memory_bytes: 3060
N,M=map(int,input().split())
A=[0]*(10**5+10)
for _ in range(M):
    l,r=map(int,input().split())
    A[l]+=1
    A[r+1]-=1
for i in range(10**5+9):
    A[i+1]+=A[i]
print(A.count(M))

Measured memory_bytes: 6900
import itertools
grid = []
for _ in range(3):
    grid.append(list(map(int,input().split())))

sum = sum(list(itertools.chain.from_iterable(grid)))
if sum % 3 != 0:
    print('No')
    exit()

for i in range(-100,101):
    a1 = i
    b1 = grid[0][0] - a1
    b2 = grid[0][1] - a1
    b3 = grid[0][2] - a1
    a2 = grid[1][0] - b1
    a3 = grid[2][0] - b1
    if a1 + a2 + a3 + b1 + b2 + b3 == sum // 3:
        print('Yes')
        exit()
print('No')

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

class OddString {
public:
	OddString(char*);
	char* GetString();

private:
	char* s;
};

OddString::OddString(char str[]) {
	int length = strlen(str);
	int oddStrLength = (length + 1) / 2;
	s = new char[oddStrLength + 1];

	for (int i = 0; i < oddStrLength; i++) {
		s[i] = str[i * 2];
	}
	s[oddStrLength] = '\0';
}

char* OddString::GetString() {
	return s;
}

int main() {
	const int MAX_LENGTH = 100'000;
	char input_str[MAX_LENGTH + 1];
	cin >> input_str;
	OddString os(input_str);
	cout << os.GetString() << endl;
}


Measured memory_bytes: 384
S = sorted(list(input()))

p = len(S) // 2
g = len(S) // 2
if len(S) % 2 ==1:
    g += 1
T = ['g'] * g + ['p'] * p
ans = 0
for i in range(len(S)):
    if T[i] == 'g' and S[i] == 'p':
        ans -= 1
    if T[i] == 'p' and S[i] == 'g':
        ans += 1
print(ans)


Measured memory_bytes: 5400
import java.io.*;
public class Main {
    public static void main(String args[]) {
        
        BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
        try {
            int x = 0;
            int y = 0;
            String str = input.readLine();
            String[] a = str.split("[\\s]+");
            x = Integer.parseInt(a[0]);
            y = Integer.parseInt(a[1]);
            System.out.println(x*y + " " + (x*2 + y*2));
        } catch(IOException e) {
        }
    }
}

Measured memory_bytes: 24280
#define _CRT_SECURE_NO_WARNINGS 1

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

LL a[maxn];

int main() {
    int n;
    sd(n);
    rep(i,1,n) {
        slld(a[i]);
    }
    sort(a+1,a+n+1);
    LL ans = a[n];
    int res = n - 2;
    per(i,n-1,1) {
        if(res <= 0) break;
        if(res == 1) {
            ans += a[i];
            res--;
        } else {
            ans += a[i] * 2;
            res -= 2;
        }
    }
    plld(ans);
    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a*n,b) << endl;
}


Measured memory_bytes: 764
H,N=map(int,input().split())
A=[]
B=[]
for i in range(N):
   a,b=map(int,input().split())
   A.append(a)
   B.append(b)

DP=[[0]*(H+1) for i in range(N)]
DP.insert(0,[float("inf")]*(H+max(A)))
DP[0][0]=0

for i in range(1,N+1):
   for j in range(1,H+1):
      if j-A[i-1]>0:
         DP[i][j]=min(DP[i-1][j],DP[i][j-A[i-1]]+B[i-1])
      else:
         DP[i][j]=min(DP[i-1][j],B[i-1])

print(DP[N][H])

Measured memory_bytes: 121196
#include<iostream>
#include<string>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)

int main(){
  int n;
    string s;
    cin >> n;
    cin >> s;
    int c = 0;
    rep (i, 1, n) if (s[i] == 'E') c++;
    int res = c;
    rep (i, 1, n) {
        if (s[i] == 'E') c--;
        if (s[i-1] == 'W') c++;
        if (res > c) res = c;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long j,i,minn=-1,s,a,b;
	scanf("%lld%lld",&a,&b);
	if(b-a>=2019)
	{
		printf("0");
		return 0;
	}
	a=a%2019;
	b=b%2019;
	if(a>=b)
	{
		printf("0");
		return 0;
	}
	minn=0x7fffffff;
	for(i=a;i<b;i++)
	{
		for(j=i+1;j<=b;j++)
		{
			s=i*j%2019;
			minn=min(minn,s);
		}
	}
	printf("%lld",minn);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
tmp = 1
pin= 0
A.sort()
if A[0] == 0:
    pin = 1
    print(0)
for i in range(N):
    tmp = tmp * A[i]
    if tmp > 10 ** 18:
        if pin == 0:
            print(-1)
            pin = 1
        break
if pin == 0:
    print(tmp)

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

int main() {
	int n; cin >> n;
	int a[n], res[n] = {};
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(i % 2 == 0) res[0] += a[i];
		else res[0] -= a[i];
	}
	for (int i = 1; i < n; i++)
	{
		res[i] = 2 * a[i-1] - res[i-1];
	}

	for (int i = 0; i < n; i++)
	{
		cout << res[i];
		if(i != n-1) cout << " ";
		else cout << endl;
	}

	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
//#define MOD (1000000007)
#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

bool ispal(string s){
    string ss=s;
    reverse(all(ss));
    return ss==s;
}

signed main(){
    FASTER;
    string s;cin>>s;
    int n=s.size();
    string a=s.substr(0,(n-1)/2);
    string b=s.substr((n+3)/2-1);
    if(ispal(s) && ispal(a) && ispal(b)){
        cout<<"Yes";
    }else cout<<"No";
    
}

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


int main() {
	int a, b, k;
	cin >> a >> b >> k;
	int ans[101];
	int y = 0;
	for (int i = 1; i <= 100; i++) {
		if (a%i == 0 && b%i == 0) {
			ans[y] = i;
			y++;
		}
	}
	y--;
	cout << ans[y - k + 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
//using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
////////////////

void solve(){
  ini(H , W , K);
  vector<string> s(H); in(s);
  vi cnt(H , 0);
  rep(i,H) each(x , s[i]) cnt[i] += (x == '#');
  vvi ans(H , vi(W , 0));
  // とりあえずイチゴのない列だけ決める
  int idx = 1;
  rep(i , H){
    if(cnt[i] == 0) continue;
    int nya = 0;
    rep(j , W){
      ans[i][j] = idx;
      if(nya + 1 < cnt[i] && s[i][j] == '#') idx++ , nya++;
    }
    idx++;
  }

  rep(i , H){
    if(ans[i][0] == 0){
      if(i != 0 && ans[i-1][0] != 0) copy(ans[i-1].begin() , ans[i-1].end() , ans[i].begin());
    }
  }
  repr(i , H){
    if(ans[i][0] == 0){
      if(i != H-1 && ans[i+1][0] != 0) copy(ans[i+1].begin() , ans[i+1].end() , ans[i].begin());
    }
  }
  each(x , ans) out(x);
}

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

ll x[55], y[55];
int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  map<pair<ll,ll>, int> cnt;
  for(int i=0;i<n;i++) {
    cin >> x[i] >> y[i];
    for(int j=0;j<i;j++) {
      auto p = make_pair(x[i] - x[j], y[i] - y[j]);
      auto q = make_pair(x[j] - x[i], y[j] - y[i]);
      cnt[p]++;
      cnt[q]++;
    }
  }
  int best = n;
  for(auto p:cnt) {
    best = min(best, n-p.second);
  }
  cout << best <<endl;
}


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

int main()
{
	using namespace std;
	long long a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0, count = 0,nagax=0,nagay=0;
	int answer[100][100] = {};
	std::string str,strs;
	std::string dream[4] = { "maerd","remaerd","esare","resare" };
	bool okada = false, okada2 = true;
	cin >> str;

	for (int i = 0; i < str.size(); i++) {
	strs+=str[str.size() - (i + 1)];
	}
	for (int i = 0; i < strs.size();) {
		okada=false;
	for (int j = 0; j < 4;j++) {

  
		if (strs.substr(i, dream[j].size()) == dream[j]) {
			okada = true;
			i += dream[j].size();
		}


	}
	if (okada == false) {
		okada2 = false;
		break;
	}
	}
	if (okada2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	}



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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
 	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n), b(n);
	rep(i, n) cin >>a[i];
	b=a;
	sort(all(b));
	int z1 = b[n/2-1], z2 = b[n/2];
	rep(i, n){
		cout <<((a[i] <= z1)? z2: z1) <<"\n";
	}
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    int name[5];
    for(int i = 0; i < 5; i++) name[i] = 0;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        if(s[0] == 'M') name[0]++;
        if(s[0] == 'A') name[1]++;
        if(s[0] == 'R') name[2]++;
        if(s[0] == 'C') name[3]++;
        if(s[0] == 'H') name[4]++;
    }
    ll allcount = 0;
    for(int bit = 0; bit < 1<<5; bit++){
        int temp = bit;
        int count = 0;
        int idx = 0;
        vector<int> num;
        while(temp > 0){
            if(temp & 1){
                count++;
                num.emplace_back(idx);
            }
            idx++;
            temp >>= 1;
        }
        if(count != 3) continue;
        ll smallcount = 1;
        for(int a : num){
            smallcount *= name[a];
        }
        allcount += smallcount;
    }
    cout << allcount << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(x,n) for(ll i=x;i<n;i++)

void solve(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    fr(0,n){
        cin>>a[i];
    }

    ll dp[n];
    dp[0]=0;
   
    for(ll i=1;i<n;i++){
         ll j=1,best=INT_MAX;
        while((i-j)>=0 and j<=k){
        best=min(best,abs(a[i]-a[i-j])+dp[i-j]);
        j++;
       }
       dp[i]=best;
    }
    cout<<dp[n-1]<<endl;

}

int main()
{
    solve();

    
}

Measured memory_bytes: 5188
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N; cin >> N;
  vector<int> L(N);
  REP(i, N) cin >> L[i];
  sort(ALL(L), greater<int>());
  int ma = L[0];
  int sum = 0;
  for (int i = 1; i < N; i++) sum += L[i];
  if (ma < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===


int main() {
	int N;
	cin >> N;
	int cnt = 0;
	Vi a(N), a_sorted(N);
	for (int i = 0; i < N; ++i) {
		int tmp;
		cin >> tmp;
		a[i] = tmp;
		a_sorted[i] = tmp;
	}
	sort(a_sorted.begin(), a_sorted.end());
	for (int i = 0; i < N; ++i) {
		if (a[i] != a_sorted[i]) ++cnt;
	}
	if (cnt <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    map<ll, ll> mp;
    ll E = 0;
    for(int q=0; q<a; q++){
        ll x; cin>>x;
        mp[x]++;
        E += x;
    }
    int z; cin>>z;
    for(; z--;){
        ll b,c; cin>>b>>c;
        ll k = mp[b];
        mp[b] = 0; E -= k*b;
        mp[c] += k; E += k*c;
        cout<<E<<"\n";
    }
}

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

int main(){
	int n;
	int s1 = 0, s2 = 0; 
	cin >> n;
	int* w = new int[n];
	int o, omin;	//絶対値
	/*入力*/
	for(int i = 0; i < n; i++){
		cin >> w[i];
	}

	/*計算*/
	for(int t = 0; t < n - 1; t++){
		for(int i = 0; i <= t; i++){
			s1 += w[i];
		}
		for(int j = t + 1; j < n; j++){
			s2 += w[j];
		}
		if((s1 - s2)>0){
			o = s1 - s2;
		}else{
			o = s2 - s1;
		}
		if(t == 0)omin = o;
		if(omin > o)omin = o;
		s1 = 0;
		s2 = 0;
	}

	/*出力*/
	cout << omin << endl;
	delete[] w;
	return 0;
}


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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

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

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

int main()
{
  int n;
  long long k;
  cin >> n >> k;
  int a[n];
  long long loop[n] = { 0 };
  bool was[n] = { false };
  long long was_tmp[n] = { 0 };
  
  REP(i, n) cin >> a[i]; 
  
  int pos = 1;
  int tmp_loop = 0;
  while(k > 0)
  {
    pos--;
    if(was[pos])
    {
      if(loop[pos] == 0)
      {
        loop[pos] = tmp_loop - was_tmp[pos];
      }
      k = k % loop[pos];
      if(k==0)
      {
        pos++;
        break;
      }
    }
    was[pos] = true;
    was_tmp[pos] = tmp_loop;
    pos = a[pos];
    tmp_loop++;
    k--;
  }
  
  cout << pos << endl;
  
  return 0;
}

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

int main () {
  int n;
  cin >> n;
  
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0 or i % 5 == 0) {
      continue;
    }
    sum += i;
  }
  cout << sum;
}


Measured memory_bytes: 3564
import java.util.*; 

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = i;
        }
        
        int[][] data = new int[n][2];
        for (int i = 0; i < n; i++) {
            data[i][0] = sc.nextInt();
            data[i][1] = sc.nextInt();
        }
        
        double tmp = 0;
        int kaijou = 0;
        
        // 順列全探索
        do {
            for (int i = 0; i < n-1; i++) {
                int p = array[i];
                int q = array[i+1];
                
                int x1 = data[p][0];
                int x2 = data[q][0];
                int y1 = data[p][1];
                int y2 = data[q][1];
                
                tmp += Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
            }
            kaijou++;
        } while (nextPermutation(array));
        
        
        tmp = tmp / kaijou;
        System.out.println(tmp);
        
    }
    
    public static boolean nextPermutation(int[] array) {
        for (int i = array.length - 1; i > 0; i--) {
            if (array[i - 1] < array[i]) {
                int j = find(array, array[i - 1], i, array.length - 1);
                int temp = array[j];
                array[j] = array[i - 1];
                array[i - 1] = temp;
                Arrays.sort(array, i, array.length);
                return true;
            }
        }
        return false;
    }
	 
    private static int find(int[] array, int dest, int f, int l) {
        if (f == l) return f;
        
        int m = (f + l + 1) / 2;
        return (array[m] <= dest) ? find(array, dest, f, m - 1) : find(array, dest, m, l);
    }
}

Measured memory_bytes: 22612
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <queue>

int main() {
  size_t N;
  scanf("%zu", &N);

  auto enc = [&](size_t i, size_t j) {
    if (i > j) std::swap(i, j);
    return i*N+j;
  };

  std::vector<std::vector<size_t>> g(N*N);

  std::vector<size_t> indeg(g.size());
  for (size_t i = 0; i < N; ++i) {
    std::vector<size_t> h(N-1);
    for (auto& hi: h) scanf("%zu", &hi), --hi;

    for (size_t j = 1; j < h.size(); ++j) {
      g[enc(i, h[j-1])].push_back(enc(i, h[j]));
      ++indeg[enc(i, h[j])];
    }
  }

  std::vector<int> dp(g.size());

  // for (size_t i = 0; i < N; ++i)
  //   for (size_t j = 0; j < N; ++j)
  //     if (i != j) dp[enc(i, j)] = inf;

  std::queue<size_t> q;
  // for (size_t i = 0; i < g.size(); ++i) {
  //   if (indeg[i] == 0) {
  //     q.push(i);
  //     dp[i] = 1;
  //   }
  // }
  for (size_t i = 0; i < N; ++i)
    for (size_t j = 0; j < i; ++j) {
      size_t ij = enc(i, j);
      if (indeg[ij] == 0) {
        q.push(ij);
        dp[ij] = 1;
      }
    }

  if (q.empty()) return puts("-1"), 0;

  while (!q.empty()) {
    size_t v = q.front();
    q.pop();
    for (size_t w: g[v]) {
      dp[w] = std::max(dp[w], dp[v]+1);
      --indeg[w];
      if (indeg[w] == 0) q.push(w);
    }
  }

  if (*std::max_element(indeg.begin(), indeg.end()) > 0)
    return puts("-1"), 0;

  // for (size_t i = 0; i < N; ++i)
  //   for (size_t j = 0; j < i; ++j)
  //     fprintf(stderr, "%zu vs. %zu: %d\n", i, j, dp[enc(i, j)]);

  int res = 0;
  for (size_t i = 0; i < N; ++i)
    for (size_t j = 0; j < i; ++j)
      res = std::max(res, dp[enc(i, j)]);

  if (res == 0) return puts("-1"), 0;
  printf("%d\n", res);
}


Measured memory_bytes: 51072
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    d = list(map(int, input().split()))
    if n == 1:
        print(d[0])
        exit()
    dc = defaultdict(int)
    dc[0] = 1
    for i in range(n):
        v = d[i]
        if dc[v] >= 2 or (dc[v] == 1 and (v == 12 or v == 0)):
            print(0)
            exit()
        dc[v] += 1
    
    dd = []
    ddt = []
    for i in range(0, 13):
        if (i == 0 or i == 12) and dc[i] == 1:
            ddt.append(i)
        elif dc[i] == 1:
            dd.append(i)
        elif dc[i] == 2:
            ddt.append(i)
            ddt.append(24 - i)


    
    ans = 0
    for i in range(1 << len(dd)):
        d3 = []
        for j in range(len(ddt)):
            d3.append(ddt[j])

        for j in range(len(dd)):
            if (i & (1 << j)):
                d3.append(dd[j])
            else:
                d3.append(24 - dd[j])
        
        d3 = sorted(d3)
        t = float("inf")
        for i in range(len(d3) - 1):
            t = min(t, d3[i + 1] - d3[i])
        t = min(t , 24 - d3[-1])
        ans = max(t, ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74220
#include<stdio.h>
typedef long long int lli;
int main() {
  char s[3];
  scanf("%s", &s);
  
  if(s[1]=='B'){
      s[1] = 'R';
  }

  else{
      s[1] = 'B';
  }

  printf("%s", s);

  return 0;
}



Measured memory_bytes: 1668