akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n,q;
    string s;
    cin >> n >> q >> s;
    int cum[100001];
    int c=0;
    cum[0]=0;
    for (int i=1;i<n;i++) {
        if(s[i-1]=='A' && s[i]=='C') c++;
        cum[i]=c;
    }
    int l,r;
    for (int i=0;i<q;i++) {
        cin >> l >> r;
        cout << (cum[r-1] - cum[l-1]) << "\n";
    }
    return 0;
}


Measured memory_bytes: 1488
#include <stdio.h> 
#include <math.h>
int main(void)
{
	int a, i, j, n, x[100], y[100];
	double p, max;
	scanf("%d", &n);
	for (i = 0;i < n;i++)
	{
		scanf("%d", &x[i]);
	}
	for (i = 0;i < n;i++)
	{
		scanf("%d", &y[i]);
	}
	for (j = 1;j <= 3;j++)
	{
		p = 0.0;
		for (i = 0;i < n;i++)
		{
			p = p + pow((abs(x[i] - y[i])), j);
		}
		p = pow(p, 1.0 / j);
		printf("%f\n", p);
	}
	max = abs(x[0] - y[0]);
	for (i = 1;i < n;i++)
	{
		if (max < abs(x[i] - y[i]))
		{
			max = abs(x[i] - y[i]);
		}
	}
	printf("%f\n", max);
	return 0;
}

Measured memory_bytes: 696
import numpy as np
n,k = map(int,input().split())	
s=list(input())	

li = []
is1s = False
if s[0] == "1":
    is1s = True
cnt0 = 0
cnt1 = 0
for i in range(len(s)):
    if s[i] == "0" :
        cnt0 += 1
    elif s[i] == "1":
        cnt1 += 1
    if i >= 1:
        if s[i] == "0" and s[i-1] == "1":
            li.append(cnt1)
            cnt1 = 0
        elif s[i] == "1" and s[i-1] == "0": 
            li.append(cnt0)
            cnt0 = 0

if (cnt1 > 0):
    li.append(cnt1)
if (cnt0 > 0):
    li.append(cnt0)
pivot = 2 * k 
li = np.array(li)
anslist=[]
if(is1s):
    for i in range(len(li)):
        if(i % 2 == 0):
            tmp = np.sum(li[i:min(len(li), i+pivot+1)])
            anslist.append(tmp)
else:
    for i in range(len(li)):
        if(i % 2 == 1):
            tmp = np.sum(li[i:min(len(li), i+pivot+1)])
            anslist.append(tmp)
    anslist.append(sum(li[0:pivot]))

print(max(anslist))



Measured memory_bytes: 16052
#include <iostream>
using namespace std;
int main()
{
	int W=0 , H=0 , x=0 , y=0 , r=0 ;
	cin >> W >> H >> x >> y >> r ;
	if (x+r<=W&&x-r>=0&&y+r<=H&&y-r>=0)
	{
		cout << "Yes" << endl ;
	}
	else
	{
		cout << "No" << endl ;
	}
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    ll n;
    cin >> n;

    // 1
    // 11, 12
    // 111, 112, *113*, 121, 122, 123

    // mem[length] : set of pair<res, last number>
    vector<vector<pair<vll, ll>>> mem(11);
    vll e = {1};
    mem[0].push_back({e, 1});
    REP(i, 9) {
        for (auto pre : mem[i]) {
            for (ll j = 1; j <= pre.second + 1; j++) {
                vll nxt = pre.first;
                nxt.push_back(j);
                mem[i + 1].push_back({nxt, max(pre.second, j)});
            }
        }
    }
    for (auto res : mem[n - 1]) {
        REP(i, n) {
            cout << char('a' + res.first[i] - 1);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 20696
n, m = map(int, input().split())
mod = 10 ** 9 + 7
q = 100005
pow = [0] * q
pow[1] = 1
for i in range(2, q):
    pow[i] = pow[i - 1] * i
    pow[i] = pow[i] % mod

if abs(n - m) >= 2:
    print(0)
elif abs(n - m) == 1:
    print(pow[m] * pow[n] % mod)
else:
    print(2 * pow[m] * pow[n] % mod)

Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int a, b; cin >> a >> b;
    if((a*b)&1) cout << "Odd";
    else cout << "Even";
}


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

int main() {
    int N, sum_w=0;
    cin >> N;
    int W[200];
    for (int i=0; i<N; i++) {
        cin >> W[i];
        sum_w += W[i];
    }
    int s1=0;
    int ans=10000;
    for (int i=0; i<N; i++) {
        s1 += W[i];
        ans = min(ans, abs(s1*2-sum_w));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
a = [[0,0] for i in range(n)]
ac = 0
wa = 0

for i in range(m):
    p, s = input().split()
    p = int(p)-1
    if s == "WA" and a[p][1] == 0:
        a[p][0] += 1
    elif s == "AC" and a[p][1] == 0:
        ac += 1
        a[p][1] = 1

for i in a:
    if i[1] == 1:
        wa += i[0]

print(ac,wa)


Measured memory_bytes: 13172
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 46868
import java.util.Scanner;

public class Main{
  static int N,M,C,count,subcount,A;
  static int[] B;
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    M = sc.nextInt();
    C = sc.nextInt();
    B = new int[M];
    for(int i=0;i<M;i++){
      B[i]=sc.nextInt();
    }
    for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
          A = sc.nextInt();
          subcount += B[j]*A;
        }
      if(subcount+C>0){
        count++;
      }
      else{
      }
      subcount = 0;
    }
    System.out.println(count);
  }

}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  priority_queue<int> que;
  rep(i, N) {
    cin >> A[i];
    que.push(A[i]);
  }

  rep(i, M) {
    int temp = que.top();
    que.pop();
    que.push(temp / 2);
  }

  ll ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;
}

Measured memory_bytes: 1276
import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

x = int(input())

for i in range(-200, 200):
    for j in range(-200, 200):
        if int(i ** 5 - j ** 5) == x:
            print(i, j)
            sys.exit()



Measured memory_bytes: 64980
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    LL n;
    LL k;
    LL ans;
    vector<pair<LL, LL>> ab;
    LL tmp_a;
    LL tmp_b;
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> tmp_a >> tmp_b;
        ab.push_back(make_pair(tmp_a, tmp_b));
    }

    sort(ab.begin(), ab.end());
    for(int i=0; i<n; i++){
        if(k<=ab[i].second){
            ans=ab[i].first;
            break;
        }else{
            k=k-ab[i].second;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
/*
 * SAD
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back
const int inf = 1e9;
using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 2e5 + 5, M = 1000 * 1000 * 10 + 5, K = 55, Base = 27, MOD = 1e9
		+ 7, MOD2 = 998244353;
const ll MX = 1e15;
const int blkSz = 200;
const db EPS = 1e-7;
const int PI = 3;
int nxt[N][26];
char qC[N], qD[N];
vector<int> go[26][2];
string s;
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

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

	for(int i = 0; i < m; i++){
		cin >> qC[i] >> qD[i];
	}
	int suffix = 0, prefix = 0;
	for(int i =  m-1;i >= 0; --i){
//		cout << i << " " << prefix << '\n';
		if(qD[i] == 'R'){
			if(suffix <= n && qC[i] == s[n-suffix-1]){
				suffix++;
			}
			if(prefix != 0 && qC[i] == s[prefix-1])
				prefix--;
		}	else {
			if(prefix <= n && qC[i] == s[prefix])
				prefix++;
			if(suffix != 0 && qC[i] == s[n-suffix])
				suffix--;
		}
	}
//	cout << suffix << ' ' << prefix << '\n';
	cout << n - min(n,suffix+prefix) << '\n';




	return 0;
}


Measured memory_bytes: 900
a, b = map(int, input().split())

fi = str(a)*b
se = str(b)*a

num = max(a, b)

for i in range(num):
    ff = int(fi[i])
    ss = int(se[i])
    if ff<ss:
        print(fi)
        break
    elif ss<ff:
        print(se)
        break
    else:
        pass

    if i==num-1:
        print(fi)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_6_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var v = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

            int point = partition(v, 0, n - 1);

            for(int i=0; i < n; i++)
            {
                if (i == point)
                {
                    Console.Write('[');
                    Console.Write(v[i]);
                    Console.Write(']');
                    Console.Write(' ');
                }
                else
                {
                    Console.Write(v[i]);
                    if (i != n - 1)
                        Console.Write(' ');
                    else
                        Console.WriteLine();
                }
            }
        }

        public static int partition(List<int>A,int p,int r)
        {
            var x = A[r];
            var i = p-1;
            for(int j = p; j < r; j++)
            {
                if(A[j] <= x)
                {
                    i++;
                    var temp = A[i];
                    A[i] = A[j];
                    A[j] = temp;

                }
            }
            var temp2 = A[i + 1];
            A[i + 1] = A[r];
            A[r] = temp2;
            return i + 1;
        }
    }
}



Measured memory_bytes: 25192
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,j,H,W;cin>>H>>W;
	string s;
	vector<int>dp(W+1,mod);
	dp[1]=0;
	while(H--){
		string s;cin>>s;
		for(j=1;j<=W;j++){
			chmin(dp[j],dp[j-1]);
			if(dp[j]%2==0&&s[j-1]=='#'){dp[j]++;}
			if(dp[j]%2==1&&s[j-1]=='.'){dp[j]++;}
		}
	}
	cout<<(dp[W]+1)/2<<endl;
}


Measured memory_bytes: 256
# Contest: AtCoder Beginner Contest 145 (https://atcoder.jp/contests/abc145)
# Problem: A: Circle (https://atcoder.jp/contests/abc145/tasks/abc145_a)

def rint():
    return int(input())


def rints():
    return list(map(int, input().split()))


print(rint()**2)


Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;

int main()
{
	vector<int> t(101),p(101),x(101);
	int n, m,total=0,temp;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
		total += t[i];
	}
	temp = total;
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> p[i] >> x[i];
	}

	for (int i = 1; i <= m; i++) {
		total -= t[p[i]];
		total += x[i];
		cout << total << endl;
		total = temp;
	}


	return 0;
}

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

int main() {
  string s;
  cin >> s;
  string ans = "consonant";
  if(s == "a" || s == "i" || s == "u" || s == "e" || s == "o"){
    ans = "vowel";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
int main() {
	double a;
	cin >> a;
	cout << fixed << setprecision(10)<< a * a* M_PI << " " << a * 2 * M_PI << endl;
	return 0;
}


Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;



int main()
{
	int n, q;
	cin >> n >> q;
	vector<bool> su(n, true);

	for (int i = 0; i < q; i++) {
		int num;
		cin >> num;
		for (int j = 0; j < num; j++) {
			int tmp;
			cin >> tmp;
			tmp--;
			su[tmp] = false;
		}
	}

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

	printf("%d", ans);
	
	return 0;
}

Measured memory_bytes: 3688
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

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

  static int dp[1010][1010];
  m0(dp);
  dp[0][0] = 1;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] == '#') continue;
      if (i >= 1) dp[i][j] += dp[i - 1][j];
      if (j >= 1) dp[i][j] += dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }

  cout << dp[H - 1][W - 1] << endl;
  return 0;
}


Measured memory_bytes: 9216
// Aizu Vol-10 1008: What Color Is The Universe?
// 2017.8.18 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 499979
typedef struct { int n, c; } HASH;
HASH hash[HASHSIZ + 5], *hashend = hash + HASHSIZ;

int color, cnt;

int lookup(int n)
{
	HASH *p = hash + n % HASHSIZ;
	while (1) {
		if (p->n == n) return ++(p->c);
		if (p->n == 0) break;
		if (++p == hashend) p = hash;
	}
	p->n = n, p->c = 1;
	return 1;
}

int main()
{
	int n, i, k, c;

	while (scanf("%d", &n) && n) {
		memset(hash, 0, sizeof(hash)), cnt = 0;
		for (i = 0; i < n; i++) {
			scanf("%d", &k);
			if ((c = lookup(k)) > cnt) cnt = c, color = k;
		}
		if (cnt > n / 2) printf("%d\n", color);
		else puts("NO COLOR");
	}
	return 0;
}

Measured memory_bytes: 4524
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifdef APURBA
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) cout<<#a<<" --> "<<(a)<<" ";
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 1e9+7;
const int N = 1e6 +5;
typedef pair<int,int> pii;

vector<bool>mp(N,false);
void TEST_CASES(int cas)
{

    int k;
    cin>>k;
    if(k%2==0)
    {
        printf("-1\n");
        return;
    }
    int now = 0;
    for(int i=1;;i++)
    {
        now= now*10 + 7;
        now%=k;
        if(now==0)
        {
            printf("%d\n",i);
            return;
        }
        if(mp[now])
        {
            printf("-1\n");
            return;
        }
        mp[now]= true;
    }

}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }
    return 0;
}


template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os,set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


Measured memory_bytes: 3836
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
  int n, a;
  cin >> n >> a;
  if (n%500 <= a)
    puts("Yes");
  else
    puts("No");
  return 0;
}

Measured memory_bytes: 256
def solve():
    from itertools import accumulate
    from operator import add
    from sys import stdin
    f_i = stdin
    
    N, W, H = map(int, f_i.readline().split())
    
    X = [0] * (W + 1)
    Y = [0] * (H + 1)
    
    for i in range(N):
        x, y, w = map(int, f_i.readline().split())
        
        if x < w:
            X[0] += 1
        else:
            X[x - w] += 1
        if x + w > W:
            X[W] -= 1
        else:
            X[x + w] -= 1
        
        if y < w:
            Y[0] += 1
        else:
            Y[y - w] += 1
        if y + w > H:
            Y[H] -= 1
        else:
            Y[y + w] -= 1
    
    if 0 in accumulate(X[:-1], add) and 0 in accumulate(Y[:-1], add):
        print('No')
    else:
        print('Yes')

solve()


Measured memory_bytes: 8096
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a+b==15){
        cout<<"+"<<endl;
    }else if(a*b==15){
        cout<<"*"<<endl;
    }else{
        cout<<"x"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

string s[20];
int sum[20][1010];

signed main() {

    int h, w, k;
    cin >> h >> w >> k;

    for(int i = 0; i < h; i++)
        cin >> s[i];
    
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (s[i][j] == '1');
        }
    }

    
    int miv = h * w;
    
    for(int bit = 0; bit < (1 << h - 1); bit++) {
        int cnt = 0;
        
        for(int j = 0, pj = 0; j < w; j++) {
            bool f = false;
            for(int i = 0, pi = 0; !f and i < h; pi = ++i) {
                while(i < h - 1 and !((bit>>i)&1)) ++i;

                if(sum[i+1][j+1] + sum[pi][pj] - sum[i+1][pj] - sum[pi][j+1] > k) {
                    f = true;
                }
            }
            if(f) {
                if(j == pj) {
                    cnt = INF;
                    break;
                }
                cnt++;
                pj = j--;
            }
        }
        chmin(miv, cnt + __builtin_popcount(bit));
    }
    
    cout << miv << endl;
                
  
    return 0;
}



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

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let hmhmk = readn::<usize>(" ");
    let h1 = hmhmk[0];
    let m1 = hmhmk[1];
    let h2 = hmhmk[2];
    let m2 = hmhmk[3];
    let k = hmhmk[4];

    let t1 = h1 * 60 + m1;
    let t2 = h2 * 60 + m2;
    let dt = t2 - t1;
    println!("{}", dt - k);
}

Measured memory_bytes: 2100
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using T = tuple<int,int,int,int>;
map<T,int> mp;
int n, c[405][4];
long long ans;
T make(int *c){
	int id = 0, id2 = 0, r[12] = {};
	rep(i,12) r[i] = c[i%4];
	rep(i,4) if(r[id] < r[i]) id = i;
	id2 = id;
	rep(i,4) if(r[id2] > r[id+i]) id2 = id+i;
	return T(r[id2], r[id2+1], r[id2+2], r[id2+3]);
}
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d%d%d%d", c[i], c[i]+1, c[i]+2, c[i]+3);
		mp[make(c[i])]++;
	}
	rep(i,n){
		mp[make(c[i])]--;
		for(int j = i+1; j < n; j++) rep(k,4){
			int cc = c[j][0];
			long long part = 1;
			rep(i,3) c[j][i] = c[j][i+1];
			c[j][3] = cc;
			map<T,int> tmp_mp;
			int tmp_ar[4][4] = {{c[i][0],c[i][3],c[j][2],c[j][1]},{c[i][1],c[i][0],c[j][1],c[j][0]},{c[i][2],c[i][1],c[j][0],c[j][3]},{c[i][3],c[i][2],c[j][3],c[j][2]}};
			T tmp_t;
			tmp_mp[make(c[j])]++;
			rep(l,4){
				tmp_t = make(tmp_ar[l]);
				part *= mp[tmp_t] - tmp_mp[tmp_t];
				if(tmp_ar[l][0] == tmp_ar[l][2] && tmp_ar[l][1] == tmp_ar[l][3]){
					part *= tmp_ar[l][0] == tmp_ar[l][1] ? 4 : 2;
				}
				tmp_mp[tmp_t]++;
			}
			ans += part;
		}
	}
	printf("%lld\n", ans);
}

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

int ipow(int base, int k)
{
  int r = 1;
  while(k--) r *= base;
  return r;
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i)
    cin >> s[i] >> c[i];
  
  int first = (N == 1) ? 0 : ipow(10, N-1);

  int last = ipow(10, N);
  
  int ans = -1;
  for (int num = first; num < last; ++num)
  {
    string num_str = to_string(num);
    bool ok = true;
    for (int m = 0; ok && m < M; ++m)
      if (num_str[s[m]-1] - '0' != c[m])
        ok = false;

    if (ok)
    {
      ans = num;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
typedef long long Long;

int main(){
   Long n,m,t =0;
   cin >> n >> m;
   vector<Long> v(n);
   for(Long i=0 ; i<n ; ++i) cin >> v[i] , t+= v[i];
   sort(v.rbegin(),v.rend());

   if( v[m-1]*4*m >= t ) cout << "Yes";
   else cout << "No";
   return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
from collections import deque

ans = str(input())
n = int(input())
r = 2
be=deque()
af=deque()

for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            be.appendleft(str(x[2]))
        else :
            af.append(str(x[2]))

ans = ''.join(be) + ans + ''.join(af)
if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Measured memory_bytes: 69208
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()

if 30 <= X:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10580
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace alsing2020
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_alsing2020A();
            Console.Out.Flush();
        }
        public static void solve_alsing2020()
        {
        }

        public static void solve_alsing2020B()
        {
        }

        public static void solve_alsing2020A()
        {
            int[] lrd = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int cnt = 0;
            for (int i = lrd[0]; i <= lrd[1]; i++)
            {
                if (i % lrd[2] == 0)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 28156
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	string n; cin >> n;
	int res = 0;
	for (char x : n)if (x == '2')++res;
	cout << res << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,n,a,b,c=0;
    cin>>n;
    cin>>a;
    for(i=1;i<n;i++)
    {
        cin>>b;
        if(a>b)
        {
            c=c+(a-b);
            b=a;
        }
        a=b;
    }
     cout<<c;
    return 0;
}




Measured memory_bytes: 3628
using Yorukatsu053.Questions;
using Yorukatsu053.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu053.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/abc064/tasks/abc064_c
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var a = inputStream.ReadIntArray();
            var count = new int[9];

            foreach (var ai in a)
            {
                var color = Math.Min(ai / 400, 8);
                count[color]++;
            }

            var min = 0;
            for (int i = 0; i < 8; i++)
            {
                min += count[i] > 0 ? 1 : 0;
            }

            var max = min + count[8];
            min = Math.Max(min, 1);

            yield return $"{min} {max}";
        }
    }
}


namespace Yorukatsu053
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu053.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu053.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
I = input().split()
r = int(I[0])
c = int(I[1])
Rsum = 0
Csum = (c + 1) * [0]

o = [[0 for i2 in range(c + 1)] for i1 in range(r + 1)]

for i in range(r + 1):
    if i < r:
        Irc = input().split()
    for j in range(c):
        if i < r:
            o[i][j] = int(Irc[j])
            Rsum += o[i][j]
            Csum[j] += o[i][j]
        else:
            o[i][j] += Csum[j]
            Rsum += o[i][j]
    o[i][c] = Rsum
    Csum[c] = o[i][c]
    Rsum = 0

for i in range(r + 1):
    for j in range(c + 1):
        print(str(o[i][j]), end = '')
        if j != c:
            print(' ', end = '')
    print()

Measured memory_bytes: 8792
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int r, d, x; cin >> r >> d >> x;

  int temp = x;
  for(int i = 1; i <= 10 ; i++){
    temp = r*temp - d;
    cout << temp << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <limits>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl


using namespace std;

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

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

namespace math {
    int64_t gcd(int64_t u, int64_t v) {
        while (v != 0) {
            int64_t r = u % v;
            u = v;
            v = r;
        }
        return u;
    }
    int64_t lcm(int64_t m, int64_t n)
    {
        if ((0 == m) || (0 == n))
            return 0;

        return ((m / math::gcd(m, n)) * n);
    }
}

int main(void) {
    int64_t N, M;
    cin >> N >> M;

    string S, T;
    cin >> S;
    cin >> T;
    if (N < M) {
        swap(N, M);
        swap(S, T);
    }

    int64_t L = math::lcm(N, M);

    int64_t a = L / N;
    int64_t b = L / M;
    int64_t c = math::lcm(a, b);
    pv(L);
    pv(a);
    pv(b);
    pv(c);

    int64_t x = c / a;
    int64_t y = c / b;
    pv(x);
    pv(y);
    for (int64_t i = 0; i < L / c; i++) {
        if (S[x * i] != T[y * i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << L << endl;

    return 0;
}

Measured memory_bytes: 512
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif

bool pref_smaller_year_smaller(const pair<int,pii>& left, const pair<int, pii>& right) {
    if (left.second.first == right.second.first) return left.second.second < right.second.second;
    else return left.second.first < right.second.first;
}

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

    int N, M; cin >> N >> M;
    vi P(M), Y(M);
    REP(i, M) cin >> P[i] >> Y[i];

    vector<pair<int, pii>> c;
    REP(i, M) c.push_back(make_pair(i, pii(P[i], Y[i])));
    
    sort(c.begin(), c.end(), pref_smaller_year_smaller);

    map<int, int> mp;
    REP(i,M) {
        mp[c[i].second.first]++;
        c[i].second.second = mp[c[i].second.first];
    }

    sort(c.begin(), c.end());
    REP(i, M) printf("%06d%06d\n", c[i].second.first, c[i].second.second);

    return 0;
}

Measured memory_bytes: 8180
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
map <lld, lld> position;
set <lld> visited;
lld repeat;
void dfs1 (vector <lld> V[], lld x)
{
	visited.insert(x);
	for(lld i = 0; i < V[x].size(); i += 1){
		if (!visited.count(V[x][i])){
			dfs1(V , V[x][i]);
		}
		else  {
			repeat = V[x][i];
		}
	}
}
lld dfs2 (vector <lld> V[], lld x , lld dest)
{
	if (x == dest){
		return 0;
	}
	visited.insert(x);
	for(lld i = 0; i < V[x].size(); i += 1){
		if (!visited.count(V[x][i])){
			lld p = dfs2(V, V[x][i], dest) + 1;
			return p;
		}
	}
}
lld dfs3 (vector <lld> V[],lld x,lld k,lld c)
{
	if (c == k){
		return x;
	}
	visited.insert(x);
	for(lld i = 0; i < V[x].size(); i += 1){
		if (!visited.count(V[x][i])){
			lld y = dfs3(V, V[x][i], k, c + 1);
			return y;
		}
	}
}
void dfs4 (vector <lld> V[], lld x, lld c)
{
	position[c]  =  x;
	visited.insert(x);
	for(lld i = 0; i < V[x].size(); i += 1){
		if (!visited.count(V[x][i])){
			dfs4(V, V[x][i], c+1);
		}
	}
}
int main ()
{
      #ifndef ONLINE_JUDGE
      freopen("inputf.in",  "r",   stdin);
      freopen("outputf.in", "w",  stdout);
      #endif
      FastIO
      lld n, k;
      cin >> n >> k;
     	vector <lld> V[n+1];
      for(lld i = 1; i <= n; i += 1){
      	lld r;
      	cin >> r;
      	V[i].push_back(r);
      }
      dfs1(V, 1);
      visited.clear();
      lld count = dfs2(V, 1, repeat);
      if (count > k){
      	visited.clear();
      	cout << dfs3(V, 1, k, 0);
      }
      else{
      	k-= count;
      	visited.clear();
      	dfs4(V, repeat, 0);
      	lld len=position.size();
      	cout << position[k%len];
      }
      return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

ll n,m,q;
vector<vector<ll>> x(50,vector<ll>(4));
ll ans=0;

int getsum(vector<ll> a){
    ll sum=0;
    rep(i,q){
        if(a[x[i][1]-1]-a[x[i][0]-1] == x[i][2]) sum+=x[i][3];
    }
    if(sum>ans) ans=sum;
    return 0;
}

int recurse(ll pos,vector<ll> a){
    if(pos==0){
        rep(j,m){
            a[pos]=j+1;
            recurse(pos+1,a);
        }
    }else{
        for(int j=a[pos-1];j<=m;j++){
            a[pos]=j;
            if(pos!=n-1) recurse(pos+1,a);
            else getsum(a);
        }
    }
    return 0;
}

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

    cin >> n >> m >> q;
    rep(i,q) rep(j,4) cin >> x[i][j];

    vector<ll> a(n);
    recurse(0,a);
    
    print(ans);
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graphi = vector<vector<int>>;
using Graphs = vector<vector<char>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(){

    int h,w; cin >> h >> w;
    Graphs G(h,vector<char>(w));
    queue<pint> que;
    Graphi dist(h,vector<int>(w,-1));
    vector<int> dx = {-1,0,0,1};
    vector<int> dy = {0,1,-1,0};
    rep(i,h)rep(j,w){
        char c; cin >> c;
        G.at(i).at(j) = c;
        if(c == '#'){
            que.push(make_pair(i,j));
            dist.at(i).at(j) = 0;
        } 
    }
    int count = 0;
    while (!que.empty()) {
        count++;
        pint v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        int x = v.first;
        int y = v.second;

        // v から辿れる頂点をすべて調べる
        for (int i = 0; i <= 3; i++) {
            int nx = x + dx.at(i);
            int ny = y + dy.at(i);
            if(nx >= 0 && nx <= h-1 && ny >= 0 && ny <= w-1){
                if (dist.at(nx).at(ny) != -1) continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist.at(nx).at(ny) = dist.at(x).at(y) +1;
                que.push(make_pair(nx,ny));
            }
        }
    }
    int ans = -1;

    rep(i,h)rep(j,w) chmax(ans,dist.at(i).at(j));
    cout << ans << endl;

    return 0;   

}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;
const ll INF=(1LL<<60);
int stateA[MAX],stateB[MAX],N;
ll DA[MAX],DB[MAX];
vector<pair<int,ll>> A[MAX],B[MAX];
priority_queue<pair<ll,int>> Q;

void dijkstra(int u,int v){
    int cnt=1;
    for(int i=0;i<N;i++){
        stateA[i]=0;
        DA[i]=INF;
    }
    stateA[u]=1;
    DA[u]=0;
    for(int i=0;i<A[u].size();i++){
        Q.push(make_pair(-A[u][i].second,A[u][i].first));
        DA[A[u][i].first]=min(DA[A[u][i].first],DA[u]+A[u][i].second);
    }
    while(1){
        int a=Q.top().second;
        if(stateA[a]==0){
            Q.pop();
            stateA[a]=1;
            for(int i=0;i<A[a].size();i++){
                if(stateA[A[a][i].first]==0){
                    Q.push(make_pair(-(DA[a]+A[a][i].second),A[a][i].first));
                    DA[A[a][i].first]=min(DA[A[a][i].first],DA[a]+A[a][i].second);
                }
            }
            cnt++;
        }
        else Q.pop();
        if(cnt==N) break;
    }
    
    cnt=1;
    for(int i=0;i<N;i++){
        stateB[i]=0;
        DB[i]=INF;
    }
    stateB[v]=1;
    DB[v]=0;
    for(int i=0;i<B[v].size();i++){
        Q.push(make_pair(-B[v][i].second,B[v][i].first));
        DB[B[v][i].first]=min(DB[B[v][i].first],DB[v]+B[v][i].second);
    }
    while(1){
        int a=Q.top().second;
        if(stateB[a]==0){
            Q.pop();
            stateB[a]=1;
            for(int i=0;i<B[a].size();i++){
                if(stateB[B[a][i].first]==0){
                    Q.push(make_pair(-(DB[a]+B[a][i].second),B[a][i].first));
                    DB[B[a][i].first]=min(DB[B[a][i].first],DB[a]+B[a][i].second);
                }
            }
            cnt++;
        }
        else Q.pop();
        if(cnt==N) break;
    }
    return;
}

int main(){
    
    int M,s,t;cin>>N>>M>>s>>t;
    s--;t--;
    for(int i=0;i<M;i++){
        int u,v;
        ll a,b;
        cin>>u>>v>>a>>b;
        u--;v--;
        A[u].push_back(make_pair(v,a));
        A[v].push_back(make_pair(u,a));
        B[u].push_back(make_pair(v,b));
        B[v].push_back(make_pair(u,b));
    }
    
    dijkstra(s,t);
    
    ll D[N];
    
    for(int i=0;i<N;i++){
        D[i]=1000000000000000-DA[i]-DB[i];
    }
    
    for(int i=N-2;i>=0;i--){
        D[i]=max(D[i],D[i+1]);
    }
    
    for(int i=0;i<N;i++){
        cout<<D[i]<<endl;
    }
}


Measured memory_bytes: 22136