akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define M 1046527
#define L 14
char H[M][L];

//?°?????¬??????¬??¢?????°???
int getChar(char c) {
  switch (c) {
    case 'A': return 1;
    case 'C': return 2;
    case 'G': return 3;
    case 'T': return 4;
    default: return 0;
  }
}
//?°?????¬??????¬??¢?????°?????¶??????key
long long getKey(char str[]) {
  long long ret = 0, p = 1;
  int i;
  for(i = 0; str[i] != '\0'; i++) {
    ret += p * getChar(str[i]);
    p *= 5;
  }
  return ret;
}
int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}
int find(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}
int Insert(char str[]) {
  long long key, h, i;
  key = getKey(str);
  for(i = 0; ; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) {
      return 1;
    } else if(strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}
int main()
{
    int i,n;
    char str[L],cmd[9];
    for(i=0;i<M;i++){ 
         H[i][0]='\0';
    }
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s %s",cmd,str);
        if(cmd[0]=='i'){
            Insert(str);
        }
        else
        {
            if(find(str)){
                printf("yes\n");
             }
            else{
                printf("no\n");
             }
        }
    }
    return 0;
}

Measured memory_bytes: 17060
import sys
input = sys.stdin.readline

n, W = map(int, input().split())
dp = [[0 for i in range(W + 1)] for j in range(n + 1)]
wv = [[int(x) for x in input().split()] for _ in range(n)]

for i in range(n):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j - wv[i][0]] + wv[i][1], dp[i + 1][j])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(max(dp[-1]))


Measured memory_bytes: 171528
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define vi vector<int>
#define P push_back
#define F first
#define S second
#define debug(x) cout<<(x)<<" "
#define pi vector<pair<int,int> >
#define FOR(i,x,n) for(int i=x;i<n;i++)
#define all(a) a.begin(),a.end()
using namespace std;
int main(){
    boost; 
    int n,d;
    cin>>n>>d;
    vector<vector<int> > x(n,vector<int> (d));
    for(int i=0;i<n;i++)
    for(int j=0;j<d;j++)cin>>x[i][j];
    ll count=0;

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ll sum=0;
            for(int k=0;k<d;k++){
                sum+=abs(x[i][k]-x[j][k])*abs(x[i][k]-x[j][k]);
            }
            ll g=sqrt(sum);
            if(g*g==sum)count++;
        }
    }
    cout<<count;




    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
string s;
int a[2];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  FOR(i, 0, sz(s)) a[(s[i]-'0') == i%2]++;
  cout << min(a[0], a[1]) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>




int main(){
	int q ; 
	scanf("%d", &q);
	int A[q*2 ];
	int head = q;
	int end = q;
	int order;
	int hob;
	int position;
	int data;
	//printf("%d %d\n", head , end);
	while(q--){
		scanf("%d", &order);
		switch(order){
			case 0 :
				scanf("%d%d", &hob, &data);
				if(hob == 0){
					head--;
					A[head] = data;
				
				}
				else{
					A[end] = data;
					end++;
				
				}
				//printf("%d %d\n", head , end);
				break;
				
			case 1 :
				scanf("%d", &position);
				printf("%d\n", A[head + position]);
				break;	
							
			case 2 :
				scanf("%d", &hob);
					if(hob == 0){
					head++;
				}
				else{
					end--;
				}
				//printf("%d %d\n", head , end);
				break;
			
		}
		
		
		
		
	}
	return 0 ;
} 


Measured memory_bytes: 3308
def power(x,n,mod):
  digit = len(str(bin(n)))-2
  a = len(x)
  dp = [x]*digit
  for i in range(1,digit):
    dp[i] = dot(dp[i-1],dp[i-1],mod)
  ans = [[0]*a for _ in range(a)]
  for i in range(a):
    ans[i][i] = 1
  for i in range(digit):
    if 1<<i & n:
      ans = dot(dp[i],ans,mod)
  return ans

def dot(A,B,mod):
  p = len(A)
  q = len(A[0])
  r = len(B)
  s = len(B[0])
  if q!=r:
    print('掛け算できません')
    return
  ans = [[0]*s for _ in range(p)]
  for i in range(p):
    for j in range(s):
      for k in range(q):
        ans[i][j] += A[i][k]*B[k][j]
        ans[i][j] %= mod
  return ans

def solve():
  N, K = map(int, input().split())
  mat = [list(map(int, input().split())) for _ in range(N)]
  init = [[0]*N for _ in range(N)]
  for i in range(N):
    init[i][i] = 1
  mod = 10**9+7
  dp = dot(init,power(mat,K,mod),mod)
  ans = sum(map(sum,dp))%mod
  return ans
print(solve())

Measured memory_bytes: 75416
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

struct Info
{
	int d;
	int m;
	int cnt;

	Info()
	{
		cnt = 0;
		d = -1;
	}
};

int main()
{
	string s;
	map<int, Info> m;
	int mon = 0;

	while (getline(cin, s))
	{
		if (s == "")
		{
			mon = 1;
			continue;
		}
		stringstream ss;
		ss << s;

		int c, d;
		ss >> c;
		ss.ignore();
		ss >> d;

		if (mon == 0)
		{
			m[c].m = 0;
			if (m[c].d == -1)
			{
				m[c].d = d;
			}
			m[c].cnt++;
		}
		else
		{
			if (m.count(c))
			{
				if ((m[c].m == 0 && m[c].d >= d) || (m[c].m == 1 && m[c].d <= d))
				{
					m[c].m = 1;
					m[c].d = d;
					m[c].cnt++;
				}
			}
		}
	}

	for (auto i : m)
	{
		if (i.second.m == 1)
		{
			cout << i.first << " " << i.second.cnt << endl;
		}	
	}
}


Measured memory_bytes: 3172
// 0 - BLACK
// 1 - WHITE

#include <iostream>
#include <vector>

using namespace std;

const long long MOD = 1e9+7;
const int maxN = 1e5+2;

int n;
vector<int> v[maxN];

bool vis[maxN];
long long dp[maxN][2];

void dfs(int nod){
    vis[nod] = true;
    dp[nod][0] = dp[nod][1] = 1;

    for(auto it : v[nod]){
        if(vis[it] == false){
            dfs(it);
            int toAdd = (dp[it][1] + dp[it][0]);
            dp[nod][1] = (dp[nod][1] * toAdd) % MOD;
            
            dp[nod][0] = (dp[nod][0] * dp[it][1]) % MOD;
        }
    }
}

int main(){
    cin >> n;
    for(int i = 1; i < n; i++){
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    dfs(1);

    cout << (dp[1][0] + dp[1][1]) % MOD;

    return 0;
}

Measured memory_bytes: 11520
#include<cstdio>
#include<queue>
#include<vector>
#define MA 10005
#define INF (1<<30)
using namespace std;
struct Node{
    short id;//根据题意，id最大在short有效范围内
    int weight;
};

short n;
vector<pair<int, int> >adj[MA];//加权有向图的邻接表
priority_queue<Node> PQ;//优先级队列
bool state[MA];//节点状态，false为未访问
int dis[MA];//节点到0点的权值总和

/**重载'<'以自定义优先级队列的优先级，这里定义为权值小优先，与默认的大优先相反*/
bool operator < (const Node node1, const Node node2){
    if(node1.weight==node2.weight)
        return node1.id > node2.id;//权值相同比id，意义不大
    return node1.weight > node2.weight;//返回与正常比较相反的结果
}

/**初始化*/
void init(){
    for(short i=0;i<n;i++)
        dis[i] = INF;//初始权值置为无穷
    dis[0] = 0;//0点权值为0
    Node ini;//0点
    ini.id=0;ini.weight = 0;//0点初始值
    PQ.push(ini);//将0点推入队列
}

/**狄克斯特拉算法*/
void dijkstra(){
    while(!PQ.empty()){//执行至队列为空
        Node nowNode = PQ.top();//从队列中取出元素
        PQ.pop();//清除取出的元素
        short nowId = nowNode.id;//当前元素的ID
        state[nowId] = true;//该节点已从队列中清除，设为访问完毕
        if(dis[nowId]>nowNode.weight)continue;//取出最小值，如果不是最短路径则忽略
        int nowSize = adj[nowId].size();//空间换时间，减少部分运算量
        for(int i=0; i<nowSize; i++){//遍历当前元素的邻接节点
            short nextId = adj[nowId][i].first;//下一个节点的ID
            if(state[nextId]) continue;//如果该节点已被读取则跳过
            int nextWeight = dis[nowId] + adj[nowId][i].second;//0到下一个节点的权值
            if(dis[nextId] > nextWeight){//发现了更短的路径
                dis[nextId] = nextWeight;//更新权值数组对应的数据
                Node nextNode;//即将推入队列的节点
                nextNode.id=nextId; nextNode.weight = nextWeight;//将数据存入节点
                PQ.push(nextNode);//将存有数据的节点推入队列
            }
        }
    }
}

int main(){
    int id, flag, nextId, weight;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&id, &flag);
        while(flag--){
            scanf("%d%d", &nextId, &weight);//读取邻接表
            adj[id].push_back(make_pair(nextId, weight));
        }
    }
    init();//执行初始化
    dijkstra();//执行狄克斯特拉算法
    for(short i=0;i<n;i++){//输出全部节点数据
        printf("%d %d\n", i, ((dis[i]==INF)?(-1):(dis[i])));
    }
    return 0;
}



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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define REPR(i,n,m) for(int i=n;i>m;i--)
#define ALL(v) v.begin(),v.end()
#define elif else if
using ll=long long;

int gcd(int x,int y){
    int a;
    while(y!=0){
        a=x%y;
        x=y;
        y=a;
    }
    return x;
}

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

/*----------template----------*/

int main(){
    int k,x;
    cin>>k>>x;

    if(500*k>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
    if((a==5 && b==5 && c==7) ||
      a==5 && b==7 && c==5 || a==7 && b==5 && c==5){
      System.out.println("YES");
      }else{
        System.out.println("NO");
      }
	}
}


Measured memory_bytes: 9428
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

class UnionFindTree{
public:
    std::vector<int> parent;
    std::vector<int> rank;
 
    UnionFindTree(int n){
        parent.resize(n, 0);
        rank.resize(n, 0);
 
        for(int i = 0; i < n; i++){
            parent[i] = i;
        }
        return;
    }
    ~UnionFindTree(){
        return;
    }
 
    int find(int x){
        if(parent[x] == x){
            return x;
        }
        else{
            return parent[x] = find(parent[x]);
        }
    }
 
    void unite(int x, int y){
        x = find(x);
        y = find(y);
 
        if(x == y){
            return;
        }
 
        if(rank[x] < rank[y]){
            parent[x] = y;
        }
        else{
            parent[y] = x;
            if(rank[x] == rank[y]){
                rank[x]++;
            }
        }
    }
 
    bool is_same(int x, int y){
        return find(x) == find(y);
    }
};

class Edge{
public:
	int u;
	int v;
	int cost;

	Edge(){
		return;
	}
	
	~Edge(){
		return;
	}
	bool operator < (const Edge &r){
		return this->cost < r.cost;
	}
};


int main(int argc, char **argv){
	int n;
	std::vector<int> A;
	std::vector<Edge> edges;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	A.resize(n * n);
	for(int i = 0; i < n; i++){
		int offset = i * n;
		for(int j = 0; j < n; j++){
#if INPUT_FROM_FILE
			ifs >> A[offset + j];
#else
			std::cin >> A[offset + j];
#endif
		}
	}

	for(int i = 0; i < n; i++){
		int offset = i * n;
		for(int j = i + 1; j < n; j++){
			if(A[offset + j] >= 0){
				Edge e;
				e.u = i;
				e.v = j;
				e.cost = A[offset + j];

				edges.push_back(e);
			}
		}
	}

	std::sort(edges.begin(), edges.end());
   UnionFindTree uft(n);
   int result = 0;
 
    for(int i = 0; i < edges.size(); i++){
        Edge &e = edges[i];
        if(!uft.is_same(e.u, e.v)){
            uft.unite(e.u, e.v);
            result += e.cost;
        }
    }
 
    std::cout << result << std::endl;
	return 0;
}


Measured memory_bytes: 3116
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val M = mutableMapOf<Int, Int>()
    A.forEach { M[it] = M.getOrElse(it, { 0 }) + 1 }
    var ans = 0
    for ((k, v) in M) if (v != k) if (v - k > 0) ans += Math.min(v - k, v) else ans += v
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 60060
#pragma GCC optimize("O2,unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
string get(string s, int k) {
	int n = s.size();
	int suf = 1;
	while(suf < n && s[s.size()-1-suf] == s.back()) suf++;
	while(k && suf < n) {
		if(--k) {
			string t = s;
			reverse(all(t));
			t = s + t;
			s = t.substr(suf, n);
		} else {
			string t = s;
			reverse(all(t));
			t = s + t;
			s = t.substr(n-suf, n);
		}
		suf *= 2;
	}
	return s;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	char mn = 'z'+1;
	int n, k;
	string s;
	cin >> n >> k >> s;
	for(auto i : s) mn = min(mn, i);
	if(k > 12) return cout << string(n, mn), 0;
	string u = s;
	reverse(all(u));
	u = s + u;
	string ans(1, 'z'+1);
	for(int i = 0; i+n-1 < 2*n; i++) ans = min(ans, get(u.substr(i, n), k-1));
	cout << ans;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int rcnt = 0, bcnt = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'R') {
				rcnt++;
			} else {
				bcnt++;
			}
		}
		System.out.println((rcnt > bcnt) ? "Yes" : "No");
	}
}


Measured memory_bytes: 23380
s = input()
total_sum = 0
n = len(s)
for i in range((2**(n-1))):
    before_cut = 0
    for j in range(n-1):
        if ((i >> j ) & 1):
            total_sum += int(s[before_cut:j+1])
            before_cut = j+1
    total_sum += int(s[before_cut:len(s)])
print(total_sum)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x; --y;
  vector<int> ans(n + 1);
  rep(i, n) {
    queue<int> q;
    vector<int> dist(n, INF);
    auto push = [&] (int v, int d) {
      if(dist[v] != INF) return;
      dist[v] = d;
      q.push(v);
    };
    push(i, 0);
    while (!q.empty()) {
      
      int v = q.front(); q.pop();
      if(v - 1 >= 0) push(v - 1, dist[v] + 1);
      if(v + 1 < n) push(v + 1, dist[v] + 1);
      if(v == x) push(y, dist[v] + 1);
      if(v == y) push(x, dist[v] + 1);
    }
    rep(i, n) ans[dist[i]]++;
  }

  for(int i = 1; i <= n - 1; ++i) {
    cout << ans[i] / 2 << endl;
  }

}

Measured memory_bytes: 256
//C
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b;
	cin >> a >> b;
	for(int i = 1;i <= 100000;i++){
		if(floor(i*0.08) == a and floor(i*0.1) == b){
			cout << i;
			return 0;
		}
	}
	cout << -1;
	return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            ans = (500 * i) + (100 * j) + (50 * k)
            if ans == x:
                cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int a[12],memo = 0,cnt = 0;
    
    rep(i,0,12){
        
        cin >> a[i];
    }
    
    sort(a,a+12);
    
    rep(i,1,12){
        cnt++;
        if(a[i-1] != a[i]){
            if(cnt % 4){
                cout << "no" << endl;
                return 0;
            }
            cnt = 0;
        }
    }
    
    cnt++;
    if(cnt % 4){
        cout << "no" << endl;
        return 0;
    }
    
    cout << "yes" << endl;
    
    return 0;
}


Measured memory_bytes: 3136
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iomanip>

using namespace std;

void solve() {
    int k;
    string s;
    cin >> k;
    cin >> s;
    if (s.length() <= k) {cout << s;}
    else {
        for (int i = 0; i < k; i++) {
            cout << s[i];
        }
        cout << "...";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}


Measured memory_bytes: 3588
import numpy as np

d = int(input())

c = list(map(int, input().split()))

sd = np.zeros((d, 26), dtype=np.int)
for i in range(d):
  s = list(map(int, input().split()))
  s_array = np.array(s)
  sd[i, :] = s_array

pp = np.zeros(26, dtype=np.int)
  
for i in range(d):
  pp += c
  pp_max = np.argmax(pp)+1
  pp_max_val = np.max(pp)
  # print(np.sum(pp), pp_max, pp_max_val)
  sd_max = np.argmax(sd[i,:])+1
  sd_max_val = np.max(sd[i,:])
  # print(sd_max, sd_max_val)
  if np.sum(pp) >= sd_max_val:
    t = pp_max
    pp[pp_max-1] = 0
  else:
    t = sd_max
  print(t)

Measured memory_bytes: 27396
#include<iostream>
using namespace std;
const int maxn=305;
bool dp[10000025][2];
int a[maxn],n;

int dfs(int k,int t)
{
    if(dp[k][t]>0)
	 return dp[k][t];
    int ans=0;
    for(int i=1;i<=n;++i)
     if(k>=a[i])
	  ans|=!dfs(k-a[i],!t);
    return dp[k][t]=ans;
}

int main()
{
    int k;
    cin>>n>>k;
    for(int i=1;i<=n;++i)
     cin>>a[i];
    if(dfs(k,0)==false)
     cout<<"Second"<<endl;
    else
     cout<<"First"<<endl;
    return 0;
}

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

typedef long long ll;

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string a;
	cin>>a;

	if(a == "KIHBR" || a == "KIHBRA" || a == "KIHBAR" || a == "KIHBARA" || a == "KIHABR" || a == "KIHABRA" || a == "KIHABAR" || a == "KIHABARA" || a == "AKIHBR" || a == "AKIHBRA" || a == "AKIHBAR" || a == "AKIHBARA" || a == "AKIHABR" || a == "AKIHABRA" || a == "AKIHABAR" || a == "AKIHABARA") cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    int ans;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    int m = n/2;

    ans = abs(d[m-1] - d[m]);

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;

const int INF = 1000000009;

int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    int a[2005];
    P p[2005];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        p[i] = P(a[i], i);
    }
    sort(p, p + n);
    bool b[2005]{0};
    int ans = INF;
    for(int t = 0; t < n; t++){
        int d = 0;
        priority_queue<int, vector<int>, greater<int>> que1, que2;
        for(int i = 0; i < n; i++){
            if(b[i]){
                d = 0;
                while(que1.size()) que1.pop();
            }
            else{
                que1.push(a[i]);
                d++;
                if(d >= k){
                    que2.push(que1.top());
                    que1.pop();
                }
            }
        }
        if((int)que2.size() >= q){
            for(int i = 0; i < q - 1; i++) que2.pop();
            ans = min(ans, que2.top() - p[t].first);
        }
        else break;
        b[p[t].second] = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3672
N, M = map(int, input().split())

lst = [0]*(N+1)

for _ in range(M):
  a,b = map(int, input().split())
  lst[a] += 1
  lst[b] += 1
  
for i in lst:
  if i % 2 == 1:
    print('NO')
    exit()
    
print('YES')

Measured memory_bytes: 75456
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    vector<int> v(n*2);
    rep(i,n*2){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int ans=0;

    for(int i=0;i<n*2;i+=2){
        ans+=min(v[i],v[i+1]);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
vector<bool> issafe;

int main()
{
    int N, M; cin >> N >> M;
    vector<bool> issafe(N + 1, true);
  	//issafe.assign(N + 1, true);
    rep(i, M)
    {
        int a;
        cin >> a;
        issafe[a] = false;
    }

    vector<ll> dp(N + 1, 0);
    dp[0] = 1;
    if (issafe[1]) dp[1] = 1;

    Rep(i, 2, N + 1)
    {
        if (issafe[i - 1]) dp[i] += dp[i - 1];
        if (issafe[i - 2]) dp[i] += dp[i - 2];
        dp[i] %= MOD;
    }
    cout << dp[N] << endl;
}



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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    string s;
    int ans = 0, Bx = 0, xA = 0, BxA = 0;
    for (int i = 0; i < N; i++) {
        cin >> s;
        for (int i = 0; i < s.size() - 1; i++) {
            if (s[i] == 'A' && s[i + 1] == 'B') ans++;
        }
        if (s[0] == 'B' && s[s.size() - 1] == 'A') {
            BxA++;
        } else {
            if (s[0] == 'B') {
                Bx++;
            }
            if (s[s.size() - 1] == 'A') {
                xA++;
            }
        }
    }

    if (xA > 0 && Bx > 0 && BxA > 0) {
        ans += BxA + 1;
        xA--;
        Bx--;
    } else if (BxA > 0) {
        if (xA > 0) {
            ans += BxA;
            xA--;
        } else if (Bx > 0) {
            ans += BxA;
            Bx--;
        } else {
            ans += BxA - 1;
        }
    }
    ans += min(xA, Bx);

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


Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    IN(n);
    ll c[4] = {};
    rep(i, n) {
        INS(string, s);
        if (s == "AC") c[0]++;
        if (s == "WA") c[1]++;
        if (s == "TLE") c[2]++;
        if (s == "RE")  c[3]++;
    }
    cout << "AC x " << c[0] << endl;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  a--; b--;
  if(abs(a - b) % 2 == 1) {
    cout << "Borys" << endl;
  } else {
    cout << "Alice" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
L = [tuple(map(int,input().split())) for i in range(N)]
X = sorted(L, key = lambda k:k[1])
cnt = 0
ans = True
for i,j in X:
    cnt += i
    if cnt > j:
        ans = False
        break
        
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 83032
#include <iostream>
#include <map>
#include <vector>

#define X first
#define Y second

using namespace std;

int main(void){
	int n;
	int x,y;
	
	while(cin >> n && n){
		vector<pair<int,int> > pattern;
		vector<pair<int,int> > stars;
		map<pair<int,int>, bool> isExist;
		for(int i=0;i<n;i++){
			cin >> x >> y;
			pattern.push_back(make_pair(x,y));
		}
		
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> x >> y;
			isExist[make_pair(x,y)] = true;
			stars.push_back(make_pair(x,y));
		}
		
		//for all stars
		for(int i=0;i<stars.size();i++){
			vector<pair<int,int> > working;

			//calculate diffence
			int dx = stars[i].X - pattern[0].X;
			int dy = stars[i].Y - pattern[0].Y;
			
			working = pattern;
			for(int j=0;j<working.size();j++){
				working[j].X += dx;
				working[j].Y += dy;
			}
			
			bool isok = true;
			for(int j=0;j<working.size();j++){
				if(!isExist[working[j]]){
					isok = false;
					break;
				}
			}
			if(isok){
				cout << dx << " " << dy << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;


public class Main {
    static int pow(int a, int b){
        int ans = 1;
        for(int i=0; i<b; i++) ans *= a;
        return ans;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();

        System.out.println((X-Z)/(Y+Z));

    }
}


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

int N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  reverse(C.begin(), C.end());
  vector<long long> AtoB(N), BtoC(N);
  int k = 0;
  for (int i = 0; i < N; i++) {
    while (k < N && B[i] < C[k]) {
      BtoC[i]++;
      k++;
    }
    if (i < N - 1) {
      BtoC[i + 1] = BtoC[i];
    }
  }
  k = 0;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    while (k < N && A[i] < B[k]) {
      AtoB[i] += BtoC[k];
      k++;
    }
    if (i < N - 1) {
      AtoB[i + 1] = AtoB[i];
    }
    ans += AtoB[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 6112
N = int(input())
A = list(map(int, input().split()))

flag = True
for i in range(N):
  if A[i]%2 == 0:
    if A[i]%3!=0 and A[i]%5!=0:
      flag = False
if flag:
  print("APPROVED")
else:
  print("DENIED")

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  
  int B[M];
  for (int i=0; i<M; i++) {
    cin >> B[i];
  }
  
  int A[N][M];
  for (int i=0; i<N; i++) {
    for (int j=0; j<M; j++) {
      cin >> A[i][j];
    }
  }
  
  int ans=0;
  for (int i=0; i<N; i++) {
  	int ibuff=0;
    for (int j=0; j<M; j++) {
      ibuff += A[i][j]*B[j];
    }
    if ((ibuff+C) > 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>


using namespace std;
using ll = long long int; 

int main(void){

    ll n, a, b;
    cin>>n>>a>>b;

    ll ab= a + b;
    ll ans;
    if(n/ab>0) ans = (n/ab)*a + min(n%ab, a);
    else if(n<a) ans = n;
    else ans = a;
    if(a==0 && b==0) ans = 0;
    //cout<<n/ab<<" "<<n<<a<<n%ab<<endl;
    cout<<ans<<endl;
    return 0;


    

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int n;
char str[21][100000];

int main(void) {
  while(cin >> n, n != 0) {
    cin >> str[0];

    REP(i, 0, n) {
      int j = 0;
      int k = 0;
      int len = strlen(str[i]);
      while(k < len) {
        int s = k;
        while(k < len && str[i][k] == str[i][k + 1]) k++;
        int cnt = k - s + 1;
        int l = 0;
        int d[100];
        while(cnt != 0) {
          d[l] = cnt % 10;
          cnt /= 10;
          l++;
        }
        while(l > 0) {
          str[i + 1][j++] = '0' + d[--l];
        }
        str[i + 1][j++] = str[i][s];
        k++;
      }
      str[i + 1][j++] = '\0';
    }

    cout << str[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 1420
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, L, a[101010];

void solve() {
    int memo = -1;
    for (int i = 0; i < N - 1; i++) {
        if (a[i] + a[i + 1] >= L) {
            memo = i;
            break;
        }
    }
    if (memo == -1) {
        cout << "Impossible" << endl;
        return;
    }
    cout << "Possible" << endl;
    vi ans;
    ans.emplace_back(memo + 1);
    for (int i = memo; i >= 1; i--) {
        ans.emplace_back(i);
    }
    for (int i = memo + 2; i < N; i++) {
        ans.emplace_back(i);
    }
    reverse(all(ans));
    for (auto& x : ans)
        cout << x << endl;
}

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

    cin >> N >> L;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }


    solve();
    return 0;
}


Measured memory_bytes: 5056
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	long n = read.to!long;
	string s = readln.chomp;
	
	long r = 0, b = 0;
	foreach(c; s) if(c == 'R') r += 1; else b += 1;
	
	if(r > b) "Yes".writeln;
	else "No".writeln;
	
}


Measured memory_bytes: 256
// package app;

import java.util.Arrays;
import java.util.Scanner;

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

        int[] arr = new int[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = sc.nextInt();
        }

        // int A1 = sc.nextInt();
        Arrays.sort(arr);

        System.out.println(Math.abs(arr[1] - arr[0]) + Math.abs(arr[2] - arr[1]));
    }
}

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

int main()
{
	int br=0;
	string s;
	cin >> s;
	if(s[0]=='2') br++;
	if(s[1]=='2') br++;
	if(s[2]=='2') br++;
	if(s[3]=='2') br++;

	printf("%d", br);

    return 0;
}


Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//#define __DEBUG__
#ifdef  __DEBUG__
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#endif

//UnionFind
class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par = vector<int>(n, -1);
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    UnionFind uni(2 * N);
    REP(i, N - 1) {
        int u, v, w; cin >> u >> v >> w;
        u--; v--;
        if (w % 2 == 0) {
            uni.unite(u, v);
            uni.unite(u + N, v + N);
        }
        else {
            uni.unite(u, v + N);
            uni.unite(u + N, v);
        }
    }
    REP(i, N) {
        if (uni.same(0, i)) {
            cout << 0 << endl;
        }
        else {
            cout << 1 << endl;
        }
    }
    getchar(); getchar();
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    ll c = max(0LL, a - k);
    k = max(0LL, k - a);
    ll d = max(0LL, b - k);
    cout << c << " " << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n,k;cin>>n>>k;
    vector<vector<ll> >nxt(n,vector<ll>(64));
    rep(i,n){
        ll a;cin>>a;
        a--;
        nxt[i][0]=a;
    }
    REP(i,1,64){
        rep(j,n){
            nxt[j][i]=nxt[nxt[j][i-1]][i-1];
        }
    }
    ll ans=0;
    rep(i,64){
        if((1LL<<i)&k){
            ans=nxt[ans][i];
        }
    }
    cout<<ans+1<<endl;
}

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

using namespace std;

int N;
vector<int> DataInfo;
unsigned long long int DpResult[100][21];

void solve() {
	int add, sub;

	DpResult[0][DataInfo[0]] = 1;
	for (int i = 0; i < N - 2; ++i) {
		for (int j = 0; j < 21; ++j) {
			if (DpResult[i][j] == 0) {
				continue;
			}
			add = j + DataInfo[i + 1];
			sub = j - DataInfo[i + 1];

			if (add >= 0 && add < 21) {
				DpResult[i + 1][add] += DpResult[i][j];
			}
			if (sub >= 0 && sub < 21) {
				DpResult[i + 1][sub] += DpResult[i][j];
			}
		}
	}
	cout << DpResult[N - 2][DataInfo[N - 1]] << endl;
}

int main() {
	int num;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> num;
		DataInfo.push_back(num);
	}
	memset(DpResult, 0, sizeof(DpResult));
	solve();

	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; ll x; cin >> n >> x;
    vector<vector<ll>> dp(n+1,vector<ll>(n,LNF));
    ll ans = 0;
    rep(i,0,n){
        ll a; cin >> a;
        dp[0][i] = a;
        ans += a;
    }
    rep(i,0,n){
        ll s = 0;
        rep(j,0,n){
            chmin(dp[i+1][j],dp[0][j]);
            if(j==0){
                chmin(dp[i+1][j],dp[i][n-1]);
                s += dp[i+1][j];
                continue;
            }
            chmin(dp[i+1][j],dp[i][j-1]);
            s += dp[i+1][j];
        }
        debug(dp[i]);
        chmin(ans,s+x*(i+1));
    }
    cout << ans << endl;
} 

Measured memory_bytes: 31616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll m = 1000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll dist[201][201];
int N, M, R;
int r[9];


int main() {
	cin >> N >> M >> R;
	REP(i, N) {
		REP(j, N) {
			dist[i][j] = INF;
		}
	}
	REP(i, R) {
		int k;
		cin >> k;
		r[i] = k - 1;
	}
	REP(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		dist[a-1][b-1] = c;
		dist[b-1][a-1] = c;
	}
	REP(k, N) {
		REP(i, N) {
			REP(j, N) {
				dist[i][j] = min(dist[i][j], (dist[i][k] + dist[k][j]));
			}
		}
	}
	vector<int> v(R);
	REP(i, R) {
		v[i] = r[i];
	}
	VSORT(v);
	ll ans = INF;
	do {
		ll cnt = 0;
		REP(i, R - 1) {
			cnt += dist[v[i]][v[i+1]];
		}
		ans = min(ans, cnt);
	} while (next_permutation(v.begin(), v.end()));     // 次の順列を生成
	cout << ans << endl;
	return 0;
}

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

using namespace std;
#define INP "solve"
#define OUT "solve"
const int QQ = 3e5 + 10;
const int maxN = 1e5 + 10;
const int maxM = 1e6 + 10;
const int oo = 1e9;
const int module = 1e9 + 7;

void doc() {
    //freopen(INP ".inp","r",stdin);
    //freopen(OUT ".out","w",stdout);
}

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
}
int main(int argc,char *argv[]) {
    //srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    doc();
    solve();
}


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

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, n){
        int num;
        cin >> num;
        if((i+1)%2!=0){
            if(num%2!=0)  cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = int.Parse(inputs[0]);
            var m = int.Parse(inputs[1]);
            var list = new int[m];


            for (var i = 0; i < n; i++)
            {
                var l = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToList();
                for (var j = 0; j < l[0]; j++)
                {
                    list[--l[j + 1]]++;
                }

            }

            var result = list.Count(x => x == n);
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28364