akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int N,K,L;
double T,U,V;
bool getca[10500];
const int INF=1e9;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
const int MAX_N=1e2+5;
class UnionFind
{
    int par[MAX_N];
    int rnk[MAX_N];
    int sizes[MAX_N];
    public:
    void init(int n)
    {
        for(int i=0;i<n;i++)
        {
            par[i]=i;
            rnk[i]=0;
            sizes[i]=1;
        }
    }
    int find(int x)
    {
        if(par[x]==x)
        {
            return x;
        }
        else
        {
            return par[x]=find(par[x]);
        }
    }
    void unite(int x,int y)
    {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rnk[x]<rnk[y]) swap(x,y);
        par[y]=x;
        if(rnk[x]==rnk[y]) rnk[x]++;
        sizes[x]+=sizes[y];
    }
    bool same(int x,int y)
    {
        return find(x)==find(y);
    }
    int size(int x)
    {
        return sizes[find(x)];
    }
};


//UnionFindが無いと動かないぞ!
class Edge{
    public:
    int source,target,cost;
    Edge(int source=0,int target=0,int cost=0):
    source(source),target(target),cost(cost){}
    bool operator < (const Edge &e ) const {
        return cost < e.cost;
    }
};
int kruskal(int N,vector<Edge> edges) {
    int minmax=INF;
    int maxweight=0;
    int minweight=0;
    bool canttree=false;
    sort(edges.begin(),edges.end());
    UnionFind uf;
    for(int j=0;j<edges.size();j++)
    {
        canttree=false;
        uf.init(N+1);
        minweight=edges[j].cost;
        //int source,target;
        for(int i=j;i<edges.size();i++){
            Edge e=edges[i];
            if(!uf.same(e.source,e.target)){
                maxweight=edges[i].cost;
                uf.unite(e.source,e.target);
            }
        }
        for(int i=2;i<=N;i++)
        {
            if(!uf.same(1,i)) canttree=true;
        }
        if(!canttree)minmax=min(minmax,maxweight-minweight);
    }
    return minmax;
}

int main()
{
  int N,M;
  while(cin >> N >> M && N)
  {
      vector<Edge> edges;
      for (int i = 0; i < M; i++)
      {
          int source,target,cost;
          cin >> source >> target >> cost;
          edges.push_back(Edge(source,target,cost));
      }
      int ans=kruskal(N,edges);
      if(ans==INF)
      {
          cout << -1 << endl;
      }
      else
      {
          cout << ans << endl;
      }
  }
  return 0;
}



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

int search(vector<long> a, int n, int key) {
	int i = 0;
	a.push_back(key);
	while (a[i] != key)i++;
	return i != n;
}

int main() {
	int n, q, ans = 0;
	cin >> n;
	vector<long>s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> q;
	vector<long>t(q);
	for (int i = 0; i < q; i++) {
		cin >> t[i];
	}

	for (int i = 0; i < q; i++) {
		ans += search(s, n, t[i]);
	}
	cout << ans << endl;
}



Measured memory_bytes: 3280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	static int tot;
	static boolean[] par;
	static int[] nextPar;
	static long[] minus;
	
	static void calc(int pos, boolean inv) {
		if (pos == tot) {
			return;
		}
		if (par[pos] != inv) {
			calc(pos + 1, !inv);
			minus[pos] = minus[pos + 1];
			nextPar[pos] = nextPar[pos + 1] + 1;
		} else {
			calc(pos + 1, inv);
			minus[pos] = minus[pos + 1] + nextPar[pos + 1] + 1;
			nextPar[pos] = tot - pos - 1 - nextPar[pos + 1];
		}
	}
	
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		char[] vals = sc.next().toCharArray();
		tot = 0;
		par = new boolean[vals.length];
		int ones = 0;
		long ans = 0;
		for (int i = 0; i < vals.length; i++) {
			ans += i / 2 + 1;
			if (vals[i] == '0') {
				par[tot++] = ones % 2 == 1;
			} else {
				ones++;
			}
		}
		
		nextPar = new int[tot + 1];
		minus = new long[tot + 1];
		
		calc(0, false);
		out.println(ans - minus[0]);
		
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int d,t,s;
  cin>>d>>t>>s;
  if(s*t >= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



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

// input
int N, A;


void input() {
    cin >> N >> A;
}


int main() {
    input();
    string ans;
    if (N % 500 <= A) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 3576
#pragma GCC optimize("Ofast")
#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 ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll ans = 1e18;
    vector<int> C(N);
    rep(i,K) C[N-1-i] = 1;
    do {
        ll cost = 0;
        ll H = 0;
        rep(i,N) {
            if (C[i] && H >= A[i]) {
                cost += H+1-A[i];
                H++;
            } else {
                chmax(H,A[i]);
            }
        }
        chmin(ans,cost);
    } while (next_permutation(all(C)));

    cout << ans << ln;
}

Measured memory_bytes: 256
#include <stdio.h>

static int *A;

void print(int *A, int n) {
  for (int i = 0; i < n; i++)
	printf((i == n - 1 ? "%d\n" : "%d "), *(A + i));
}

void insertion_sort(int *A, int n) {
  for (int i = 1; i < n; i++) {
	int val = A[i];
	int j = i - 1;
	while (0 <= j && val < A[j]) {
	  A[j + 1] = A[j];
	  j--;
	}
	A[j + 1] = val;
	print(A, n);
  }
}

int main() {
  int n;
  scanf("%d", &n);
  int A[n];
  for (int i = 0; i < n; i++)
	scanf("%d", A + i);

  print(A, n);
  insertion_sort(A, n);

  return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define MAX (1123456789)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> sep;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] != s[i])sep.push_back(i);
    }
    int k = n;
    for (int i = 0; i < sep.size(); i++) {
        int l = max(n - sep[i], sep[i]);
        k = min(k, l);
    }
    cout << k << endl;
}


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

int main()
{
  int n ;
  cin>>n;
  int a , b , c=0;
  bool temp = false;
  for( int i = 0 ; i<n ;i++)
  {
    cin>>a>>b;
    if(a==b)
    {
      c++;
      if(c>=3)
        temp =true;
    }
    else
      c=0;

  }
  if(temp)
    cout<<"Yes\n";
  else
    cout<<"No\n";
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    double n,m;
    double su;
    cin >> n >> m;
    vector <int> a(n);
    su = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        su += a[i];
    }

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

    // cout << su/(4*m) << endl;
    for(int i=0;i<m;i++){
        // << a[n-i-1];
        if(a[n-i-1] < su/(4*m)){
            cout << "No";
            return 0;
        }

    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,x;

inline LL gcd(LL a,LL b) {
    LL r;
    while (b) {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

int main() {
    cin >> n >> x;
    cout << 3*(n-gcd(n,x)) << endl;
    return 0;
}

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

int main(){
    double N,K;
    cin >> N >> K;

    double ans;

    double pow2[20];
    pow2[0] = 1;
    for(int i = 1; i <= 19; i++) {
        pow2[i] = pow2[i-1]*2;
    }

    for(int n = 1; n <= N; n++) {
        if(n >= K){
            ans += 1;
            continue;
        }

        double tmp = K/n;

        int j=0;
        while(tmp > pow2[j]){
            j++;
        }
        ans += (double)1/pow2[j];
    }
    
    cout << std::setprecision(12) <<  (double)ans/N << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    double w;
    while (true) {
        cin >> w;
        if (cin.eof()) break;
        else if (w <= 48)           cout << "light fly"    << endl;
        else if (w > 48 && w <= 51) cout << "fly"          << endl;
        else if (w > 51 && w <= 54) cout << "bantam"       << endl;
        else if (w > 54 && w <= 57) cout << "feather"      << endl;
        else if (w > 57 && w <= 60) cout << "light"        << endl;
        else if (w > 60 && w <= 64) cout << "light welter" << endl;
        else if (w > 64 && w <= 69) cout << "welter"       << endl;
        else if (w > 69 && w <= 75) cout << "light middle" << endl;
        else if (w > 75 && w <= 81) cout << "middle"       << endl;
        else if (w > 81 && w <= 91) cout << "light heavy"  << endl;
        else if (w > 91)            cout << "heavy"        << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

an = a%10
bn = b%10
cn = c%10
dn = d%10
en = e%10

ans = 0

if an==0:
    an = 10
if bn==0:
    bn = 10
if cn==0:
    cn = 10
if dn==0:
    dn = 10
if en==0:
    en = 10

arfa = min([an,bn,cn,dn,en])

for x in [a,b,c,d,e]:
    ans += math.ceil(x/10)*10
print(ans - 10 + arfa)


Measured memory_bytes: 3064
#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); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9


int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  C *= 2;
  int sum = 0;

  if(A + B > C){
    sum += C *min(X, Y);
    int box = min(X,Y);
    X-= box;
    Y-= box;
  }
  if(A > C){
    sum += C*X;
    X = 0;
  }
  if(B > C){
    sum += C*Y;
    Y=0;
  }
  sum += A * X + B*Y;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
flag = True
a.sort()
for i,j in zip(a[0:len(a)-1],a[1:len(a)]):
    if i == j:
        flag = False
        break
if flag == True:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 26808
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");

  //文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
    if(a * b % 2 == 0){
     console.log("Even");
    }else{
      console.log("Odd");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
int main(void){
    long long int n,k,h;
    cin>>n>>k;
    std::deque<long long int> deq;
    for (int i=0;i<n;i++) {
        cin>>h;
        deq.emplace_back(h);
    }
    long long int dp[100001];
    const long long INF=1LL<<60;
    for (int i=0;i<=n;i++) {
        dp[i]=INF;
    }
    dp[0]=0;
    for (int i=1;i<n;i++) {
        for (int j=1;j<=k;j++) {
            if (i-j>=0) {
                chmin(dp[i],dp[i-j]+abs(deq[i]-deq[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 5180
use std::io;
use std::str::FromStr;

fn main() {
    get_line();
    let mut xs: Vec<i32> = reads(&get_line());
    xs.sort();
    let mut ans = 0;
    let mut turn = 1;
    while let Some(x) = xs.pop() {
        ans += turn * x;
        turn *= -1;
    }
    println!("{}", ans);
}

fn get_line() -> String {
    let mut inp = String::new();
    io::stdin().read_line(&mut inp).expect("read error");
    inp.trim().to_string()
}

fn reads<T>(input: &str) -> Vec<T>
where
    T: FromStr,
    T::Err: std::fmt::Debug,
{
    input
        .trim()
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
/*
## 题意:
有一个(n*m)的矩阵,要求每次交换两行,或者两列.使得矩阵对称
a[i][j]=a[n-i+1][m-j+1]

单独考虑行和列?
12!
*/
int n,m,cnt[26],a[50][50];
char s[50];
bool chk1(int x,int y){
	int i;
	for (i=0;i<26;i++)cnt[i]=0;
	for (i=1;i<=m;i++){
		cnt[a[x][i]]++;
		cnt[a[y][i]]--;
	}
	for (i=0;i<26;i++)if (cnt[i])return 0;
	return 1;
}
bool chk2(int x,int y){
	int i;
	for (i=0;i<26;i++)cnt[i]=0;
	for (i=1;i<=n;i++){
		cnt[a[i][x]]++;
		cnt[a[i][y]]--;
	}
	for (i=0;i<26;i++)if (cnt[i])return 0;
	return 1;
}
void swa1(int x,int y){
	for (int i=1;i<=m;i++){
		swap(a[x][i],a[y][i]);
	}
}
void swa2(int x,int y){
	for (int i=1;i<=n;i++){
		swap(a[i][x],a[i][y]);
	}
}
void chk(){
	int i,j;
	for (i=1;i<=n;i++){
		for (j=1;j<=m;j++){
			if (a[i][j]!=a[n-i+1][m-j+1]){
				return ;
			}
		}
	}	
	printf("YES\n");
	exit(0);
}
void dfs2(int x){
	if (x>=m-x+1){
//		printf("?\n");
		chk();
		return ;
	}
	for (int i=x+1;i<=m-x+1;i++){
		if (chk2(x,i)){
			swa2(m-x+1,i);
			dfs2(x+1);
			swa2(m-x+1,i);
		}
	}
}
void dfs1(int x){
//	printf("x=%d\n",x);
	if (x>=n-x+1){
		dfs2(1);
		return ;
	}
	for (int i=x+1;i<=n-x+1;i++){
		if (chk1(x,i)){
			swa1(n-x+1,i);
			dfs1(x+1);
			swa1(n-x+1,i);
		}
	}
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	read(n); read(m);
	int i,j;
	for (i=1;i<=n;i++){
		scanf("%s",s+1);
		for (j=1;j<=m;j++){
			a[i][j]=s[j]-'a';
		}
	}/*
	for (i=1;i<=n;i++){
		for (j=1;j<=n;j++)can1[i][j]=chk1(i,j);
	}
	for (i=1;i<=m;i++){
		for (j=1;j<=m;j++)can2[i][j]=chk2(i,j);
	}*/
	for (i=1;i<=n;i++){
		swa1(i,(n+1)/2);
		for (j=1;j<=m;j++){
			swa2(j,(m+1)/2);
			dfs1(1);
			swa2(j,(m+1)/2);
		}
		swa1(i,(n+1)/2);
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	char buf[100001];
	int table[50001];

	ll ans = 0;

	for(int i = 0; i <= 50000; i++)table[i] = 0;

	int num = 0;

	scanf("%s",buf);

	for(int i = 0;buf[i] != '\0';i++){
		if(buf[i] == '(')num++;
		else{
			num--;
		}
		table[num]++;
	}

	for(int i = 0; i <= 50000; i++){
		if(table[i] >= 2){
			for(int k = 1; k <= table[i]-1; k++){
				ans += k;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 2996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt()-1;
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			if(i == arr[i]) {
				count++;
				i++;
			}
		}
		System.out.println(count);
	}
}

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

def parent(i):
    return i//2

def left(i):
    return 2*i

def right(i):
    return 2*i+1

def maxHeapify(A, i):
    l = left(i)
    r = right(i)
    # 左の子、自分、右の子で値が最大のノードを選ぶ
    if l <= H and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r <= H and A[r] > A[largest]:
        largest = r
    
    if largest != i:
        A[i], A[largest] = A[largest], A[i] # pythonはこれで要素の入れ替えが可能
        maxHeapify(A, largest)

def buildMaxHeap(A, H):
    for i in range(H//2, 0, -1):
        maxHeapify(A, i)

H = int(input())
A = [None] + list(map(int, input().split()))

buildMaxHeap(A, H)

print(' ' + ' '.join(map(str, A[1:])))


Measured memory_bytes: 64248
// :(

// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 

using namespace std; 

  

const int MAX = 1000001; 

  
// structure to store queries 

struct Query 
{ 

    int l, r, idx; 
}; 

  
// cmp function to sort queries according to r 

bool cmp(Query x, Query y) 
{ 

    return x.r < y.r; 
} 

  
// updating the bit array 

void update(int idx, int val, int bit[], int n) 
{ 

    for (; idx <= n; idx += idx&-idx) 

        bit[idx] += val; 
} 

  
// querying the bit array 

int query(int idx, int bit[], int n) 
{ 

    int sum = 0; 

    for (; idx>0; idx-=idx&-idx) 

        sum += bit[idx]; 

    return sum; 
} 

void answeringQueries(std::vector<int> a, std::vector<Query> qu) 
{ 

    // initialising bit array 

    int bit[a.size()+1]; 

    memset(bit, 0, sizeof(bit)); 

  

    // holds the rightmost index of any number 

    // as numbers of a[i] are less than or equal to 10^6 

    int last_visit[MAX]; 

    memset(last_visit, -1, sizeof(last_visit)); 
  

    // answer for each query 

    int ans[qu.size()]; 

    int query_counter = 0; 

    for (int i=0; i<a.size(); i++) 

    { 

        // If last visit is not -1 update -1 at the 

        // idx equal to last_visit[arr[i]] 

        if (last_visit[a[i]] !=-1) 

            update (last_visit[a[i]] + 1, -1, bit, a.size());

  

        // Setting last_visit[arr[i]] as i and updating 

        // the bit array accordingly 

        last_visit[a[i]] = i; 

        update(i + 1, 1, bit, a.size()); 

  

        // If i is equal to r of any query  store answer 

        // for that query in ans[] 

        while (query_counter < qu.size() && qu[query_counter].r == i) 

        { 

            ans[qu[query_counter].idx] = 

                     query(qu[query_counter].r + 1, bit, a.size())- 

                     query(qu[query_counter].l, bit, a.size()); 

            query_counter++; 

        } 
        
    } 

  

    // print answer for each query 

    for (int i=0; i<qu.size(); i++) 

        cout << ans[i] << endl; 
} 

  
// driver code 

int main() { 
  int N, Q;
  std::cin >> N >> Q;
  std::vector<int> c(N);
  for (auto& e : c) std::cin >> e;
  std::vector<Query> queries(Q);
  for (int i = 0; i < Q; ++i)
    std::cin >> queries[i].l >> queries[i].r, --queries[i].l, --queries[i].r, queries[i].idx = i;
  std::sort(begin(queries), end(queries), cmp); 
  answeringQueries(c, queries); 
}


Measured memory_bytes: 27156
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).map{|v|v-1}

dp = Array.new(n+1, -1)
seen = Array.new(n+1, -1)
dp[0] = 0
seen[0] = 0

lo = nil
hi = nil
1.upto(n) do |i|
  go = a[dp[i-1]]
  if seen[go] != -1
    lo = seen[go]
    dp[i] = go
    hi = i
    break
  end
  seen[go] = i
  dp[i] = go
end

if k < lo
  puts dp[k] + 1
else
  ans = dp[lo + (k - lo) % (hi - lo)] + 1
  puts ans
end

Measured memory_bytes: 32120
#include <iostream>
#include <algorithm>
#define N 10000
using namespace std;
struct s{
  int d;
  int p;
  int dcnt;
};
int main(){
  int n,m,i,j,flag,kitaiti;
  struct s data[N];
  while(1){
    flag=0;
    kitaiti=0;
    cin >> n >> m;
    if(n==0&&m==0) break;
    for(i=0;i<n;i++){
      cin >> data[i].d >> data[i].p;
      data[i].dcnt=data[i].d;
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
    if(data[j].p>data[j-1].p) swap(data[j],data[j-1]);
      }
    }
    for(i=0;i<n;i++){
      if(flag==0){
    if(m>=data[i].dcnt) m-=data[i].dcnt;
    else{
      flag=1;
      kitaiti=(data[i].dcnt-m)*data[i].p;
    }
      }
      else{
    kitaiti=kitaiti+data[i].dcnt*data[i].p;
      }
    }
    cout << kitaiti << endl;
  }
  return 0;
}

Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            string s = ReadString();
            string ans = $"{s[0]}{s.Length - 2}{s[s.Length - 1]}";
            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13140
x, y, a, b, c = map(int, input().split())
red = sorted(list(map(int, input().split())), reverse=True)
green = sorted(list(map(int, input().split())), reverse=True)
white = sorted(list(map(int, input().split())), reverse=True)
red_index = x-1
green_index = y-1
white_index = 0

while white_index < c:
  if red[red_index] < green[green_index]:
    if red[red_index] < white[white_index]:
      red[red_index] = white[white_index]
      red_index = max(red_index-1, 0)
      white_index += 1
    else:
      break
  else:
    if green[green_index] < white[white_index]:
      green[green_index] = white[white_index]
      green_index = max(green_index-1, 0)
      white_index += 1  
    else:
      break
print(sum(red[0:x])+sum(green[0:y]))

Measured memory_bytes: 106980
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

vector<ll> p(1000001);
vector<ll> pri;

void era(){
    for (int i=2; i<1000001; i++) {
        if(p[i]==0)continue;
        int j=i;
        while (j<1000001) {
            j+=i;
            if(j>=1000001)break;
            p[j]=0;
        }
    }
}

int main(){
    rep(i, 1000001) p[i]=i;
    era();
    for (int i=2; i<1000001; i++) {
        if(p[i]!=0)pri.push_back(p[i]);
    }
    for(;;){
        int n,p;
        cin >> n >>p;
        if(n==-1 and p==-1)break;
        int ub = 0, ob=pri.size();
        while (ob-ub>1) {
            int mean = (ub+ob)/2;
            if (pri[mean]>=n) {
                ob = mean;
            }
            if (pri[mean]<n) {
                ub = mean;
            }
        }
        while (pri[ob-1]<=n) {
            ob++;
        }
        vector<ll> ans;
        for (int i=ob;i<=ob+p and i<pri.size();i++ ) {
            for (int j=ob; j<=i and j<pri.size(); j++) {
                ans.push_back(pri[i-1]+pri[j-1]);
            }
        }
        sort(ans.begin(), ans.end());
        cout << ans[p-1]<<endl;
    }
}

Measured memory_bytes: 9800
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  int root(int x) {
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int n,m;
  cin >> n>> m;
  UnionFind tree(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    tree.unite(a,b);
  }
  int ans = 0;

  rep(i,n){
    maxs(ans,tree.size(i));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4040
while True :
    n = int(input())
    if n == 0 :
        break
    
    S = 1
    for i in range(n) :
        S *= (i+1)
    
    ans = 0
    while True :
        if S % 10 != 0 :
            break
        else :
            S = S // 10
            ans += 1
    print(ans)
        


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int h,w;cin >> h >> w;
  vector<string> a(h);
  rep(i,w+2) cout << (i==w+1?"#\n":"#");
  rep(i,h){
    string s;cin >> s;
    cout << '#' << s << '#' << endl;
  }
  rep(i,w+2) cout << (i==w+1?"#\n":"#");
}


Measured memory_bytes: 256
a, b = gets.chomp.split(' ').map(&:to_i)
#p a                                                                                       
#p b                                                                                       

n = 0

# 安直に全探索                                                                             
[*1..9].each{|x|
  [*0..9].each{|y|
    [*0..9].each{|z|
      tmp = 10001 * x + 1010 * y + 100 * z
      n += 1 if a <= tmp and tmp <= b
    }
  }
}

puts n


Measured memory_bytes: 1788
import java.util.*;
public class Main {
	//0010 start
	//0051 sample match
	int m,c,n;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			m = sc.nextInt();
			c = sc.nextInt();
			n = sc.nextInt();
			if((m|c|n) == 0) break;
			ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
			ArrayList<ArrayList<Integer>> store = new ArrayList<ArrayList<Integer>>();
			for(int i = 0 ; i < m + 1; i++){
				store.add(new ArrayList<Integer>());
			}
			int maxk = 0;
			for(int i = 0 ; i < n; i++){
				int k = sc.nextInt();
				maxk = Math.max(maxk, k);
				list.add(new ArrayList<Integer> ());
				for(int j = 0 ; j < k; j++){
					int b = sc.nextInt();
					list.get(i).add(b);
					store.get(m).add(b);
				}
			}
			int sum = 0;
			int [] res = new int[10];
			for(int i = 0 ; i < maxk; i++){
				for(int j = 0 ; j < n; j++){
					if(list.get(j).size() <= i) continue;
					int num = list.get(j).get(i);
					res[0] = find(store, num);
					sum += res[0];
					
					res[1] = put(store, num);
					sum += res[1];
					if(res[1] != 1){
						int num2 = store.get(0).get(0);
						sum++;
						res[2] = put(store, num2);
						sum += res[2];
						store.get(0).remove(0);
						
						res[3] = find(store, num);
						sum += res[3];
						res[4] = put(store, num);
						sum += res[4];
					}
				}
			}
			System.out.println(sum);
		}
	}
	
	private int put(ArrayList<ArrayList<Integer>> store, int num) {
		for(int i = 0 ; i < store.size(); i++){
			if(store.get(i).size() < c || i == store.size()-1){
				store.get(i).add(num);
				return i+1;
			}
		}
		return -1;
	}

	private int find(ArrayList<ArrayList<Integer>> store, int num) {
		for(int i = 0 ; i < store.size(); i++){
			for(int j = 0; j < store.get(i).size(); j++){
				if(store.get(i).get(j) == num){
					store.get(i).remove(j);
					return i + 1;
				}
			}
		}
		return -1;
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  
  cin >> N ;
  
  int monster[N+1];
  int hero[N];
  long counter=0;
  
  for(int i=0;i<N+1;i++){
    cin >> monster[i];
  }
  for(int i=0;i<N;i++){
    cin >> hero[i];
  }
  
  int kill = 0;
  for(int i=0;i<N;i++){
    kill = min(monster[i],hero[i]);
    counter += kill;
    hero[i] -= kill;
    
    kill = min(monster[i+1],hero[i]);
    counter += kill;
    monster[i+1] -= kill;
  }
  cout << counter << endl;
}


Measured memory_bytes: 1024
// 2012/11/19 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[1000001];

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<=1000000; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<=1000000; i++){
		if(is_prime[i]){
			for(int j=i*i; j<=1000000; j+=i){
				is_prime[j] = false;
			}
		}
	}

	while(true){
		int n, x;
		cin >> n >> x;

		if(n==0&&x==0)
			break;

		int K[30];
		for(int i=0; i<n; i++){
			cin >> K[i];
		}

		bool dp[1000001];

		dp[0] = true;
		for(int i=1; i<=x; i++){
			dp[i] = false;
		}

		for(int i=0; i<n; i++){
			for(int j=K[i]; j<=x; j++){
				if(!dp[j]&&dp[j-K[i]]){
					dp[j] = true;
				}
			}
		}

		int ans = -1;
		for(int i=x; i>=2; i--){
			if(dp[i]&&is_prime[i]){
				ans = i;
				break;
			}
		}

		if(ans!=-1){
			cout << ans << endl;
		}
		else{
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  int c, r;
  cin >> c >> r;
  int r_sum = 0;
  int c_sum[r] = {0};
  REP(i, c)
  {
    REP(j, r) {
      int num;
      cin >> num;
      cout << num << " ";
      r_sum += num;
      c_sum[j] += num;
    }
    cout << r_sum << "\n";
    r_sum = 0;
  }

  int sum = 0;
  REP(i, r)
  {
    cout << c_sum[i] << " ";
    sum += c_sum[i];
  }
  cout << sum << "\n";
}



Measured memory_bytes: 3100
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<iomanip>
#include<math.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
#define INF 1000000000000000000LL

int main(){
    ll a; cin>>a;
    double b; cin>>b;
    // cout << "b=" << b << endl;
    double b1 = b*100+0.5;
    int b2 = int(b1);
    // cout << "b1=" << b1 << endl;
    // cout << "b2=" << b2 << endl;
    ll c = (a*b2)/100;
    // cout << a*b2 << endl;
    cout << setprecision(18) << c << endl;
}

Measured memory_bytes: 3724
/*
 * atcoder/dp_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <cstring>

#define ll long long
#define Int ll
#define loop(__x, __start, __end) for(Int __x = __start; __x < __end; __x++)
#define loopdown(__x, __start, __end) for(Int __x = __start; __x > __end; __x--)
#define rep(__n) for(Int __x = 0; __x < __n; __x++)
#define span(__a,__x,__y) __a.begin()+__x,__a.begin()+__y
#define span_all(__a) __a.begin(),__a.end()
#define len(__x) (__x.size())
#define last(__x) (__x[__x.size()-1])

using namespace std;

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

const Int MAX_N = 10e5+200;
Int N;
Int A[MAX_N][3], dp[MAX_N][3];

void input() {
  cin >> N;
  loop(n,1,N+1) loop(i,0,3) cin >> A[n][i];
}

void solve() {
  memset(dp, 0, sizeof(dp));
  for (int n=1; n<=N; n++) {
    for (int k=0; k<3; k++) {
      chmax(dp[n][k], dp[n-1][(k+1)%3] + A[n][k]);
      chmax(dp[n][k], dp[n-1][(k+2)%3] + A[n][k]);
    }
  }
  cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 26880
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int c = 0;
		for(int x = 0; x <= K; x++) {
			for(int y = 0 ; y <= K; y++) {
				int z = S - x - y;
				if(0 <= z && z <= K) {
					c += 1;
				}
			}
		}
		System.out.println(c);
	}
}

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


int32_t main()
{
 ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
 int n,ct=0,ctt=0; cin>>n;
 string s; cin>>s;
 for(int i=0;i<n;i++)
 {
     if(s[i]=='R'){ct++;}
 }
 for(int i=0;i<ct;i++){if(s[i]=='R')ctt++;}
 cout<<ct-ctt;
}


Measured memory_bytes: 3964
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    char s[201], t[101], p[101];

    scanf ("%s %s", s, p);
    strcpy (t, s);
    strcat (s, t);

    if (strstr (s, p) == NULL) printf ("No\n");
    else printf ("Yes\n");

    return 0;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,k,c=0,sum=0;
    c_p_c();
    cin>>n>>m>>k;
    // cout<<__gcd(n,m)<<endl;
    for (int i = min(n,m); i>0; --i)
    {
    	/* code */
    	if(n%i==0 and m%i==0){
    		// watch(i);
    		c++;
    	}



    	if(c==k)
    	{
    		cout<<i<<endl;
    		break;
    	}
    }

    return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <bits/stdc++.h>
#define t97 1000000007

using namespace std;
typedef long long ll;

void dm(vector<vector<ll> >& m) {
    for(ll i = 0; i < m.size(); i++) {
        for(ll j = 0; j < m[i].size(); j++) {
            if(j != m[i].size()-1) {
                cout << m[i][j] << " ";
            } 
            else {
                cout << m[i][j] << endl;
            }
        }
    }
}

void dv(vector<ll>& v) {
    for(ll i = 0; i < v.size()-1; i++) {
        cout << v[i]<<" ";
    }
    cout << v[v.size()-1]<<endl;
}

void swap(ll& a, ll& b) {
    ll temp = a;
    a = b;
    b = temp;
}

ll minval(ll a, ll b) {
    if(a < b) {
        return a;
    }
    return b;
}

ll maxval(ll a, ll b) {
    if(a > b) {
        return a;
    }
    return b;
}

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

ll powmod(ll a, ll b, ll mod){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll c = powmod(a,b/2, mod);
        return (c*c)%mod;
    }
	else{
        return (a*powmod(a,b-1, mod))%mod;
    }
}

ll modInverse(ll A,ll M)
{
    return powmod(A,M-2,M);
}

pair<ll, ll> getValues(ll player, vector<ll>& v, ll start, ll end, vector<vector<pair<ll, ll> > >& dp) {
	pair<ll, ll> ans, max1, max2;
	max1.first = max2.first = ans.first = 0;
	max1.second = max2.second = ans.second = 0;
	if(start > end) {
		return ans;
	}
	if(dp[start][end].first != -1 && dp[start][end].second != -1) {
		return dp[start][end];
	}
	if(player == 0) {
		max1 = getValues(player^1, v, start+1, end, dp);
		max1.first += v[start];
		max2 = getValues(player^1, v, start, end-1, dp);
		max2.first += v[end];
		if(max1.first > max2.first) {
			dp[start][end] = max1;
			return max1;
		}
		else if(max1.first < max2.first) {
			dp[start][end] = max2;
			return max2;
		}
		else {
			if(max1.second < max2.second) {
				dp[start][end] = max1;
				return max1;
			}
			else {
				dp[start][end] = max2;
				return max2;
			}
		}
	}
	else {
		max1 = getValues(player^1, v, start+1, end, dp);
		max1.second += v[start];
		max2 = getValues(player^1, v, start, end-1, dp);
		max2.second += v[end];
		if(max1.second > max2.second) {
			dp[start][end] = max1;
			return max1;
		}
		else if(max1.second < max2.second) {
			dp[start][end] = max2;
			return max2;
		}
		else {
			if(max1.first < max2.first) {
				dp[start][end] = max1;
				return max1;
			}
			else {
				dp[start][end] = max2;
				return max2;
			}
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin); 
//    freopen("output.txt", "w", stdout);
	ll n;
	cin>>n;
	vector<ll> v(n);
	pair<ll, ll> p;
	p.first = -1;
	p.second = -1;
	vector<pair<ll, ll> > tempv(n, p);
	vector<vector<pair<ll, ll> > > dp;
	for(ll i = 0; i < n; i++) {
		dp.push_back(tempv);
	}
	for(ll i = 0; i < n; i++) {
		cin>>v[i];
	}	
	pair<ll, ll> ans = getValues(0, v, 0, n-1, dp);
	cout << ans.first - ans.second << endl;
	
    return 0;
}

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

int main(){
	int n;
	map<string,int> s;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
		char a[11];
		cin>>a;
		auto it=s.find(a);
		if(it == s.end()){
			ans++;
			s[a]=1;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 19256
#include<stdio.h>
#include<algorithm>
using namespace std;
int min(int a,int b){return a<b?a:b;}
int main(){
	int a[3],b[2];
	int i,j;
	for(i=0;i<3;i++)scanf("%d",&a[i]);
	for(i=0;i<2;i++)scanf("%d",&b[i]);
	sort(a,a+3);
	sort(b,b+2);
	printf("%d\n",a[0]+b[0]-50);
	return 0;
}

Measured memory_bytes: 1036
#include <iostream>

using namespace std;

int main() {

  int n;
  cin >> n;
  for(int i = 1;i <= 9;i++){
    if(n % i == 0){
      if(n / i <= 9){
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && b ==c){
      cout << "No" << endl ;
    return 0;  
    }
    else if(a == b || b == c || c == a){
        cout << "Yes" << endl ;
        return 0;
    }
        cout << "No" << endl ;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
kachi=list(map(int,input().split()))
cost=list(map(int,input().split()))
delta=[kachi[i]-cost[i] for i in range(n)]
sum=0
delta.sort(reverse=True)
j=0
while(delta[j]>0):
  sum+=delta[j]
  j+=1
  if j==n:
    break
print(sum)

Measured memory_bytes: 3064
n,m = map(int,input().split())
p = list(map(int,input().split()))
p.insert(0,0)
def find(A,x):
  p = A[x]
  if p == x:
    return x
  else:
    A[x] = find(A,p)
    return A[x]
  
def union(A,x,y):
  rx = find(A,x)
  ry = find(A,y)
  A[ry] = rx
  A[y] = rx
  
def same(A,x,y):
  return find(A,x) == find(A,y)

l = [i for i in range(n+1)]
for _ in range(m):
  x,y = map(int,input().split())
  union(l,x,y)
  
count = 0
for i in range(1,n+1):
  if same(l,i,p[i]):
    count += 1
print(count)
    
  
  



  

  


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N, M;
int LL, UL;
int main(void){
    int L, R;
    LL = 0;
    UL = 100001;
    cin >> N >> M;
    REP(i, M){
        cin >> L >> R;
        LL = max(L, LL);
        UL = min(R, UL);
    }
    cout << max(0, UL-LL+1) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

class BIT{
public:
  ll n,bit[555555];
  BIT(){fill(bit,bit+555555,0);}
  void add(ll i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  ll sum(ll i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll d[n];
  d[0]=0;
  REP(i,1,n) {
    d[i]=d[i-1];
    if(a[i]>a[d[i-1]]) d[i]=i;
  }
  ll c[n];
  mem(c);
  BIT b=BIT();
  b.n=n+1;
  priority_queue<P> que;
  ll sum=0,cnt=0;
  rrep(i,n) {
    que.push(P(a[i],i));
    if(d[i]!=i) continue;
    while(!que.empty()&&(!i||que.top().F>=a[d[i-1]])) {
      P p=que.top();que.pop();
      b.add(p.S+1,p.F);
      cnt++;
    }
    c[i]=b.sum(n)-sum;
    if(i) c[i]-=a[d[i-1]]*cnt;
    sum+=c[i];
  }
  rep(i,n) pr(c[i]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 8056
class mod_comb_k():
  def __init__(self, MAX_N = 10**6, mod = 10**9+7):
    self.fact = [1]
    self.fact_inv = [0] * (MAX_N + 4)
    self.mod = mod
    if MAX_N > mod:print('MAX_N > mod !')
    for i in range(MAX_N + 3):
      self.fact.append(self.fact[-1] * (i + 1) % self.mod)
    self.fact_inv[-1] = pow(self.fact[-1], self.mod - 2, self.mod)
    for i in range(MAX_N + 2, -1, -1):
      self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % self.mod
  def comb(self, n, k):
    if n < k:
      print('n < k !')
      return 0
    else:return self.fact[n] * self.fact_inv[k] % self.mod * self.fact_inv[n - k] % self.mod
h,w,a,b=map(int,input().split())
c=mod_comb_k()
mod=10**9+7
ans=c.comb(h+w-2,w-1)
for i in range(b):
  ans-=(c.comb(i+h-a-1,i)*c.comb(a+w-2-i,a-1))%mod
print(ans%mod)

Measured memory_bytes: 154104