akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(void){
  int m;
  while(1){
    cin>>m;
    if(m==0)break;
    map<int,int> card;
    vector<int> A;
    int a,b;
    for(int i=0;i<m;i++){
      cin>>a>>b;
      A.push_back(a);
      card[a]=b;
    }
    for(int i=m;i<7;i++){
      A.push_back(0);
      card[0]=0;
    }
    int max=0;
    for(int i=0;i<m;i++){
      max+=A[i]*card[A[i]];
    }
    map<int,int> pattern;
    for(int i=0;i<max+1;i++){
      pattern[i]=0;
    }
    int cost;
    for(int i0=0;i0<=card[A[0]];i0++){
      for(int i1=0;i1<=card[A[1]];i1++){
        for(int i2=0;i2<=card[A[2]];i2++){
          for(int i3=0;i3<=card[A[3]];i3++){
            for(int i4=0;i4<=card[A[4]];i4++){
              for(int i5=0;i5<=card[A[5]];i5++){
                for(int i6=0;i6<=card[A[6]];i6++){
                  cost=i0*A[0]+i1*A[1]+i2*A[2]+i3*A[3]+i4*A[4]+i5*A[5]+i6*A[6];
                  pattern[cost]=pattern[cost]+1;
                }
              }
            }
          }
        }
      }
    }
    int g;
    cin>>g;
    int n;
    for(int i=0;i<g;i++){
      cin>>n;
      cout<<pattern[n]<<endl;
    }
  }
  return 0;

}



Measured memory_bytes: 3124
#include <complex>
#include <iostream>
#include <cmath>
using namespace std;

typedef complex<double> xy_t;
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
const double eps = 1e-11;
double x[4],y[4];
int N;
int main() {
	cin >> N;
	for (int i=0; i<N; ++i) {
		for (int i=0; i<4; ++i) {
			cin >> x[i] >> y[i];
		}
		xy_t a[2] = {
					xy_t(x[0],y[0]) - xy_t(x[1],y[1]),
					xy_t(x[2],y[2]) - xy_t(x[3],y[3])
				};
		bool p = abs(cross_product(a[0],a[1]))/2 < eps;
		cout << ( p ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
int main (){
    int N,count;
    string s,t;
    cin >> N >> s >> t;
    count = N;
    
    for(int i=0;i<N;i++){
        if(s.substr(i,s.size()) == t.substr(0,t.size()-i)){
            cout << count;
            break;
            }
        else{
           
            count++;
        }
        if(i == N-1){
            cout << count;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	string s;
	cin >> s;
	int nextL=0,lastR=0,ans[200010]{0};
	for(int i=0;i<s.size();i++){
		while(s[nextL] != 'L' || nextL < i){
			nextL++;
		}
		if(s[i] == 'R'){
			lastR = i;
			if((nextL-i)%2 == 0){
				ans[nextL]++;
			}else{
				ans[nextL-1]++;
			}
		}else{
			if((i-lastR)%2 == 0){
				ans[lastR]++;
			}else{
				ans[lastR+1]++;
			}
		}
	}
	for(int i=0;i<s.size();i++){
		cout << ans[i] << ' ';
	}
	cout << '\n';
	return 0;
}

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

priority_queue <int> q;

int main()
{
	int x,n,m;
	scanf("%d%d",&n,&m);
	for(int i = 0;i < n;++i){
		scanf("%d",&x);
		q.push(x);
	}
	
	if(n == 1){
		int temp = q.top();q.pop();
		while(temp > 0 && m > 0){
			temp >>= 1;
			--m;
		}
		q.push(temp);
	}
	
	else{
		while(m && q.top() != 0){
			int temp = q.top();q.pop();
			while(temp >= q.top() && m > 0){
				temp >>= 1;
				--m;
			}
			q.push(temp);
		}
	}
	
	long long ans = 0;
	while(!q.empty()){
		ans += q.top();q.pop();
	}
	
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int N;
const int mod = 1e9 + 7;

void add_self (int& a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}

inline int Mul (int a, int b) {
  return (long long)a * b % mod;
}

struct Matrix {
  vector < vector < int > > t;

  Matrix () {
    t.resize (N, vector < int >(N));
  }

  Matrix operator * (const Matrix& b) const {
    Matrix c = Matrix();
    for (int i = 0; i < N; ++i)
      for (int j = 0; j < N; ++j)
        for (int k = 0; k < N; ++k)
          add_self (c.t[i][k], Mul (t[i][j], b.t[j][k]));
    return c;
  }
};

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long K;
  cin >> N >> K;
  vector < vector < int > > adj(N, vector < int >(N));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      cin >> adj[i][j];
  Matrix ans = Matrix();
  for (int i = 0; i < N; ++i)
    ans.t[i][i] = 1;
  Matrix m = Matrix();
  m.t = adj;
  while (K) {
    if (K & 1)
      ans = ans * m;
    m = m * m;
    K >>= 1;
  }
  int total = 0;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      add_self (total, ans.t[i][j]);
  cout << total;
}


Measured memory_bytes: 3716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(a, b) for(int a=0; a<b; ++a)

int main () {
    char s[6];
    scanf("%s", s);
    if((s[2]==s[3]) && (s[4]== s[5]))
        puts("Yes\n");
    else
        puts("No\n");
    return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    var a = 0.0
    var tmp = 0
    var cnt = 0
    for(i in 1 .. x){
        tmp = i
        cnt = 0
        while(tmp < y){
            cnt += 1
            tmp *= 2

        }
        a += 1.0 / x / Math.pow(2.0, cnt.toDouble())
    }
    println(a)
}

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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n = in();
	string s;
	cin >> s;

	int a = 0;
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == ')') a++;
		else a--;
		chmax(a, 0);
	}

	cout << string(max(0, a), '(') << s;
 
	int b = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '(')b++;
		else b--;
		chmax(b, 0);
	}
	cout << string(b, ')') << endl;
}	


Measured memory_bytes: 256
use std::f64::consts::PI;
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    let r: f64 = sc.next();
    println!("{:.6} {:.6}", PI * r * r, 2. * PI * r);
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }
}



Measured memory_bytes: 5076
N = int(input())

def dfs(x, n):
    if len(x) == n:
        s = "".join(chr(ord("a")+x[i]) for i in range(n))
        print(s)
    else:
        # 下桁に近づくにつれて文字の種類が増えるように再帰させる
        for i in range(max(x)+2):
            dfs(x+[i], n)

dfs([0], N)

Measured memory_bytes: 4340
N = int(input())
S = input()
color = [[], [], []]
for i in range(N):
    if S[i] == 'R':
        color[0].append(i)
    elif S[i] == 'G':
        color[1].append(i)
    elif S[i] == 'B':
        color[2].append(i)
rn = len(color[0])
gn = len(color[1])
bn = len(color[2])
mi = 0
for i in range(N):
    p = 0
    while i + 2*p <= N-1:
        if S[i] != S[i+p] and S[i+p] != S[i+2*p] and S[i] != S[i+2*p]:
           mi += 1
        p += 1
print(rn*gn*bn-mi)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
ll INF = 1000000009;
int main()
{
  ll h,w;
  cin >> h >> w;
  if (h % 3 == 0 || w % 3 == 0)
  {
    cout << 0 << "\n";
  }
  else
  {
    ll ans = INF * INF;
    for (ll i = 1; i < h; i++)
    {
      ll x1 = i*w;
      ll x2 = (h - i) * (w / 2);
      ll x3 = (h - i) * (w - w / 2);
      ll y2 = (h - i) / 2 * w;
      ll y3 = ((h - i) - (h - i) / 2) * w;
      ans = min(ans, max(x1, max(x3, x2)) - min(x1, min(x3, x2)));
      ans = min(ans, max(x1, max(y3, y2)) - min(x1, min(y3, y2)));
    }
    for (ll i = 1; i < w; i++)
    {
      ll x1 = i * h;
      ll x2 = (w - i) * (h / 2);
      ll x3 = (w - i) * (h - h / 2);
      ll y2 = (w - i) / 2 * h;
      ll y3 = ((w - i) - (w - i) / 2) * h;
      ans = min(ans, max(x1, max(x3, x2)) - min(x1, min(x3, x2)));
      ans = min(ans, max(x1, max(y3, y2)) - min(x1, min(y3, y2)));
    }
    cout << ans << "\n";
  }
}

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

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

using namespace std;


signed main(){
  int N;
  cin>>N;
  int C[N];
  int V[N];
  rep(i, N){
    cin >> V[i];
  }
  rep(i, N){
    cin >> C[i];
  }
  int sa=0;
  rep(i, N){
    if(V[i]>=C[i]){
      sa += V[i]-C[i];
    }
  }
  cout << sa << endl;
  return 0;
}


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

int main(){
    long long N, h, n, w;
    cin >> N;
    for(int h=1;h<=3500;h++){
        for(int n=1;n<=3500;n++){
            if(4*h*n - n*N - h*N > 0){
                if(h*n*N % (4*h*n - n*N - h*N) == 0){
                    w = h*n*N / (4*h*n - n*N - h*N);
                    if(w > 0){
                        cout << h << " " << n << " " << w << endl;
                        return 0;
                    }
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template <typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main()
{
    int H,W,K;
    cin >> H >> W >> K;
    ve<string> S(H);
    in(H,S);
    
    int ans = infi;
    
    for (int i = 0; i < (1<<(H-1)); i++) {

        ve<string> A;
        A.pb(S[0]);
        
        bitset<10> b(i);
        rep(j,H-1){
            if(b.test(j)){
                rep(k,W) if(S[j+1][k] == '1') A.back()[k]++;
            }else{
                A.pb(S[j+1]);

            }
        }
      
        /*
        cout << i << endl;
        rep(j,A.size()){
            cout << A[j] << endl;
        }
        */
        
        int n = A.size();
        vi B(n,0);
        
        int an = n-1;
        rep(j,W){
            
            rep(k,n){
                if(int(A[k][j]-'0') > K){
                    an = 10000;
                    break;
                }
                if(B[k]+int(A[k][j]-'0') > K){
                    
                    an++;
                    rep(m,n) B[m] = int(A[m][j]-'0');
                    break;
                }else{
                    B[k] += int(A[k][j]-'0');
                }
            }
        }
        
        
        chmin(ans,an);
        
     
    }
    
    
    cout << ans << endl;

    
    
    
    

    return 0;
}


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

int main(){
    ll n,m;
    cin >> n >> m;
    vector<vector<ll>> vec(m);
    
    for(ll i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        if(a>m) continue;
        vec[m-a].push_back(b);
    }
    
    priority_queue<ll> q;
    ll total = 0;
    
    for(ll i=m-1;i>=0;i--){
        for(auto p : vec[i]){
            q.push(p);
        }
        if(!q.empty()){
            total += q.top();
            q.pop();
        }
    }
    
    cout << total << endl;
    
    
    return 0;
}

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

using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// 0-indexed
class DSU {
private:

	const int n;
	std::vector<int> parent, sz;

public:

	DSU (const int n_) : n(n_), parent(n), sz(n, 1){
		for (int i = 0; i < n; ++i) parent[i] = i;
	}

	int get_root (const int i){
		if (parent[i] == i) return i;
		return parent[i] = get_root(parent[i]);
	}

	bool do_union (int i1, int i2){
		i1 = get_root(i1);
		i2 = get_root(i2);
		if (i1 == i2) return false;

		if (sz[i1] < sz[i2]) swap(i1, i2);
		parent[i2] = i1;
		sz[i1] += sz[i2];
		return true;
	}

	int get_size (const int i){
		return sz[get_root(i)];
	}
};

void solve(){
	int n, m;
	cin >> n >> m;

	DSU dsu{n};

	while(m--){
		int u, v;
		cin >> u >> v;
		--u, --v;
		dsu.do_union(u, v);
	}

	int ma = 0;
	for(int i = 0; i < n; ++i) ma = max(ma, dsu.get_size(i));
	cout << ma << "\n";
}

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

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


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

typedef long long ll;
int N;
vector<int> arr;
vector<ll> ps, ss;
priority_queue<int> pq;
ll sum;
int cnt;

int main() {
    scanf("%d", &N);
    arr.resize(3*N);
    for(int i = 0; i < 3*N; i++) {
        scanf("%d", &arr[i]);
    }
    ps.resize(3*N);
    sum = 0;
    cnt = 0;
    for(int i = 0; i < 3*N; i++) {
        pq.push(-arr[i]);
        sum += arr[i];
        cnt++;
        while(cnt > N) {
            int t = pq.top(); pq.pop();
            sum += t;
            cnt--;
        }
        ps[i] = sum;
    }
    while(!pq.empty()) pq.pop();
    ss.resize(3*N);
    sum = 0;
    cnt = 0;
    for(int i = 3*N - 1; i >= 0; i--) {
        pq.push(arr[i]);
        sum += arr[i];
        cnt++;
        while(cnt > N) {
            int t = pq.top(); pq.pop();
            sum -= t;
            cnt--;
        }
        ss[i] = sum;
    }
    ll ans = -1e18;
    for(int i = N - 1; i < 2*N; i++) {
        ans = max(ans, ps[i] - ss[i + 1]);
    }
    printf("%lld", ans);
}


Measured memory_bytes: 6648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N; cin >>N;
    int a = N % 10;
    if (a ==2 || a == 4 || a == 5 || a == 7 || a == 9){
        cout << "hon" << endl;
    }
    else if(a == 3){
        cout << "bon" << endl;
    }
    else{
        cout << "pon" << endl;
    }

}

Measured memory_bytes: 3652
import java.util.*;

class Main{
    int n,m,s,g1,g2;
    int[][] d;
    int INF = 700000000;

    void solve(){
	Scanner sc = new Scanner(System.in);
	while(true){
	    n = sc.nextInt();
	    m = sc.nextInt();
	    s = sc.nextInt();
	    g1 = sc.nextInt();
	    g2 = sc.nextInt();
	    if(n==0 && m==0 && s==0 && g1==0 && g2==0)break;

	    d = new int[n+1][n+1];
	    for(int i=0; i<=n; i++) Arrays.fill(d[i],INF);
	    for(int i=0; i<m; i++){
		int b1 = sc.nextInt();
		int b2 = sc.nextInt();
		int c = sc.nextInt();
		d[b1][b2] = c;
	    }
	    for(int i=0; i<=n; i++) d[i][i] = 0;

	    warshall_floyd();

	    int min = INF;
	    for(int i=1; i<=n; i++){
		min = Math.min(min,d[s][i]+d[i][g1]+d[i][g2]);
	    }
	    System.out.println(min);
	}
    }
    
    void warshall_floyd(){
	for(int k=1; k<=n; k++)
	    for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)d[i][j] = Math.min(d[i][j],d[i][k]+d[k][j]);
    }

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

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

template<typename G >
struct DoublingLCA {
    const int LOG;
    vector<int> dep;
    const G &g;
    int root;
    vector<vector<int>> table;

    DoublingLCA(const G &g, int root) : g(g), dep(g.size()), root(root), LOG(32 - __builtin_clz(g.size())) {
        table.assign(LOG, vector<int>(g.size(), -1));
    }

    void dfs(int idx, int par, int d) {
        table[0][idx] = par;
        dep[idx] = d;
        for(auto &to : g[idx]) {
            if(to != par)dfs(to, idx, d+1);
        }
    }

    void build() {
        dfs(root,-1,0);
        for(int k = 0; k+1 < LOG; k++) {
            for(int i = 0;i < table[k].size(); i++) {
                if(table[k][i] == -1)table[k+1][i] = -1;
                else table[k+1][i] = table[k][table[k][i]];
            }
        }
    }

    int query(int u, int v) {
        if(dep[u] > dep[v])swap(u,v);
        for(int i = LOG - 1; 0 <= i; i--) {
            if(((dep[v] - dep[u]) >> i) & 1) v = table[i][v];
        }
        if(u == v) return u;
        for(int i = LOG - 1; 0 <= i; i--) {
            if(table[i][u] != table[i][v]) {
                u = table[i][u];
                v = table[i][v];
            }
        }
        return table[0][u];
    }
};

int main(){
    ll n,u,v; cin >> n >> u >> v;
    u--;v--;
    vvl graph(n);
    rep(i,n-1) {
        ll a,b; cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    DoublingLCA<vvl> LCA(graph, v);
    LCA.build();
    Pll goal = {-1,-1};
    rep(i,n){
        ll dis = LCA.dep[i];
        ll t = LCA.dep[u] - LCA.dep[LCA.query(u,i)];
        if(0 < LCA.dep[LCA.query(u,i)] - t && goal.first < dis)goal = {dis, i};
    }
    if(goal.first == -1)goal = {LCA.dep[u], u};

    cout << goal.first - 1 << endl;
}

Measured memory_bytes: 15864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
int graph[10][10],a[10],visit[10];
int n,m;
int dfs(int now, int cnt)
{
    if(cnt==n) return 1;
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(graph[now][i]&&!visit[i])
        {
            visit[i]=1;
            ans+=dfs(i,cnt+1);
            visit[i]=0;
        }
    }
    return ans;
}
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        graph[a][b]=graph[b][a]=1;
    }
    visit[1]=1;
    cout<<dfs(1,1)<<endl;
    return 0;
}


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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int n;
    cin >> n;
    vector<int> v;
    for(;n>0;n/=10){
        v.push_back(n%10);
    }
    if((v[0]==v[1]&&v[1]==v[2])||(v[1]==v[2]&&v[2]==v[3])){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}



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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

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


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll ans;
  if (K<=A) ans = K;
  else if (K<=A+B) ans =A;
  else  ans = 2*A+B-K;
  
  cout << ans << endl;

}


Measured memory_bytes: 3604
#include<stdio.h> 
#define MAX 100001

typedef struct Card{
  char mark;
  int num;
  int index;
}c;

int n;

int Partition(c A[],int p,int r){
  c t,u;
  int i,j,s;
  s=A[r].num;
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j].num<=s){
      i++;
      t=A[i];        /*Exchange A[i] and A[j]*/
      A[i]=A[j];
      A[j]=t;
    }
  }
  u=A[i+1];          /*Exchange A[i+1] and A[r]*/
  A[i+1]=A[r];
  A[r]=u;
  return i+1;
}

void QuickSort(c Q[],int p,int r){
  int q;
  if(p<r){
    q=Partition(Q,p,r);
    QuickSort(Q,p,q-1);
    QuickSort(Q,q+1,r);
  }
}

int JudgeStability(c K[],int n){
  int i;
  for(i=1;i<n;i++){
    if((K[i-1].num==K[i].num) && (K[i-1].index>K[i].index)){
      return 0; /*Not Stable*/
    } 
  }
  return 1;
}

int main(){
  int i;
  c P[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&P[i].mark,&P[i].num);
    P[i].index = i;
  }

  QuickSort(P,0,n-1);
  if(JudgeStability(P,n)==1) printf("Stable\n");
  else if(JudgeStability(P,n)==0) printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",P[i].mark,P[i].num);
  }
  return 0;
}

Measured memory_bytes: 1776
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int wtime[100] ={};
  deque<int> deq;  
  int seat[17]={};
  int members[17];
  for(int t = 0; t <= 99*5 || !deq.empty(); t++){
    REP(i,17)if(seat[i] > 0)seat[i]--;
    if(t%5 == 0 && t <= 99*5) deq.push_back(t/5);
    while(!deq.empty()){
      int mem = deq.front();
      int nop = (mem%5==1)?5:2;
      int sitable = -1;
      for(int i = 0, con = 0; i < 17; i++){
        if(seat[i]==0)con++;
        else con = 0;
        if(con == nop){
          sitable = i + 1 - nop;
          break;
        }
      }
      if(sitable >= 0){
        deq.pop_front();
        REP(i,nop){
          seat[sitable+i] = 17*(mem%2)+3*(mem%3)+19;
          members[sitable+i] = mem;
        }
      }else{
        break;
      }
    }
    REP(i,deq.size())wtime[deq[i]]++;
    /*
    printf("%d:",t);
    REP(i,17)cout<< ((seat[i])?members[i]:0) <<" ";
    cout<<endl;
    */
  }
  int n;
  while(cin>>n)cout<<wtime[n]<<endl;
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef pair<int,int> P;

int main() {
  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  int H,W;
  cin>>H>>W;
  char A[1000][1000];
  queue<P> q;
  int sum = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>A[i][j];
      if(A[i][j]=='#'){
        q.push(P(i,j));
        sum++;
      }
    }
  }
  int count = 0;
  while(sum<H*W){
    count++;
    int sz = q.size();
    for(int i=0;i<sz;i++){
      P altas = q.front(); q.pop();
      int x = altas.first;
      int y = altas.second;
      for(int j=0;j<4;j++){
        int xx = x+dx[j];
        int yy = y+dy[j];
        if(xx>=0 && xx<H && yy>=0 && yy<W && A[xx][yy]=='.'){
          A[xx][yy]='#';
          sum++;
          q.push(P(xx,yy));
        }
      }
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 9360
#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#define n 100
using namespace std;
int main(){
	string s;
	int ans = 0;
	while(getline(cin,s)){
		bool start = false;
		int sn = 0;
		int t;
		for(int i=0;i<s.size();i++){
			if((not start) and s[i]>'0' and s[i]<='9'){
				start = true;
				sn = i;
				if(i==s.size()-1){
					istringstream is(s.substr(i,1));
					is >> t;
					ans += t;
				}
			}
			else if(start and (s[i]<'0' or s[i]>'9')){
				start = false;
				istringstream is(s.substr(sn,i-sn));
				is >> t;
				ans += t;
			}
			else if(start and s[i]>='0' and s[i]<='9' and i==s.size()-1){
				istringstream is(s.substr(sn,i-sn+1));
				is >> t;
				ans += t;
			}
		}

	}
	cout << ans << endl;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
int a[200010];
int main() {
    int n,k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = k+1; i <= n; i++) {
        if (a[i] > a[i-k]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4416
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

x=0
x_list=[1]
x_table=[0 for i in range(n+1)]
x_table[1]=1

for i in range(k):
  nx=a[x]

  if x_table[nx]!=0:
    inx=x_list.index(nx)
    loop=x_list[inx:]
    zan=k-i

    q=zan%len(loop)

    nx=loop[q-1]
    break

  else:
    x=nx-1
    x_list.append(nx)
    x_table[nx]+=1

print(nx)

Measured memory_bytes: 31332
from fractions import Fraction

n = input()
while n != 0:
    y = input()
    maxi = Fraction()
    maxi_num = 0
    
    while n > 0:
        n -= 1
        input_num = raw_input().split()
        b = int(input_num[0])
        r = int(input_num[1])
        t = int(input_num[2])
        
        money = None
        if t == 1:
            money = Fraction(100 + y * r, 100)
        else:
            money = Fraction(100 + r, 100) ** y
        if maxi < money:
            maxi = money
            maxi_num = b
    print maxi_num
    n = input()

Measured memory_bytes: 5900
import java.util.*;

class Main{
    
    int n;
    int[] kura, shiro, sen;
    double min;
    ArrayList<Integer> list;
    
    void solve(){
        Scanner sc = new Scanner(System.in);
        
        n = sc.nextInt();
        
        kura = new int[n];
        shiro = new int[n];
        sen = new int[n];
        for(int i=0; i<n; i++){
            kura[i] = sc.nextInt();
            shiro[i] = sc.nextInt();
            sen[i] = sc.nextInt();
        }
        
        double[][] dp = new double[1<<n][n];
        int[][] before = new int[1<<n][n];
        int[][] weight = new int[1<<n][n];
        for(int i=0; i<1<<n; i++){
            Arrays.fill(dp[i], -1.0);
            Arrays.fill(before[i], -1);
            Arrays.fill(weight[i], -1);
        }
        dp[0][0] = 0;
        for(int bit=0; bit<1<<n; bit++){
            for(int i=0; i<n; i++){
                if(dp[bit][i]>-1){
                    for(int j=0; j<n; j++){
                        if((bit&(1<<j))>0) continue;
                        double nn = dp[bit][i] + Math.abs(shiro[i] - shiro[j]) / (2000.0/(double)(70+weight[bit][i]));
                        int newBit = bit^(1<<j);
                        if(dp[newBit][j]<=0 || dp[newBit][j]>nn){
                            dp[newBit][j] = nn;
                            before[newBit][j] = i;
                            weight[newBit][j] = weight[bit][i] + sen[j] * 20;
                        }
                    }
                }
            }
        }

        int idx = 0;
        double min = Double.MAX_VALUE;
        for(int i=0; i<n; i++){
            if(dp[(1<<n)-1][i]>-1 && dp[(1<<n)-1][i]<min){
                min = dp[(1<<n)-1][i];
                idx = i;
            }
        }
        
        ArrayList<Integer> list = new ArrayList<Integer>();   
        list.add(new Integer(kura[idx]));
        int b = (1<<n)-1;
        while(before[b][idx]!=-1){
            list.add(new Integer(kura[before[b][idx]]));
            int newbit = b ^ (1<<idx);
            idx = before[b][idx];
            b = newbit;
        }

        
        for(int i=list.size()-2; i>0; i--) System.out.print(list.get(i)+" ");
        System.out.println(list.get(0));
    }

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

Measured memory_bytes: 33180
// 2014/08/01 Tazoe

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int a, b, C;
	cin >> a >> b >> C;

	double S = (double)a*(double)b*sin(M_PI*(double)C/180.0)/2.0;
	double c = sqrt((double)a*(double)a+(double)b*(double)b-2.0*(double)a*(double)b*cos(M_PI*(double)C/180.0));
	double L = (double)a+(double)b+c;
	double h = (double)b*sin(M_PI*(double)C/180.0);

	cout.precision(8);
	cout << fixed << S << endl;
	cout << fixed << L << endl;
	cout << fixed << h << endl;

	return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int main(){
	int a[5];
	for(int i=0;i<5;i++) scanf("%d",&a[i]);
	printf("%d\n",min(a[0],min(a[1],a[2]))+min(a[3],a[4])-50);
}

Measured memory_bytes: 1184
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    string S[N];
    rep(i, N) cin >> S[i];
    //numx(y)[i][j]:=i行(列)目のj列(行)目までの連結成分
    int numx[N][M], numy[M][N];
    //cntx(y)[i][j]:=i行(列)目j列(行)目までの下(右)の行(列)と繋がっている成分の数
    int cntx[N][M], cnty[M][N];
    rep(i, N){
        numx[i][0] = S[i][0]-'0';
        rep2(j, 1, M-1){
            numx[i][j] = numx[i][j-1];
            if(S[i][j-1] == '0' && S[i][j] == '1') numx[i][j]++;
        }
        cntx[i][0] = 0;
        rep(j, M){
            if(j > 0) cntx[i][j] = cntx[i][j-1];
            if(i != N-1 && S[i][j] == '1' && S[i+1][j] == '1') cntx[i][j]++; 
        }
    }
    rep(j, M){
        numy[j][0] = S[0][j]-'0';
        rep2(i, 1, N-1){
            numy[j][i] = numy[j][i-1];
            if(S[i-1][j] == '0' && S[i][j] == '1') numy[j][i]++;
        }
        cnty[j][0] = 0;
        rep(i, N){
            if(i > 0) cnty[j][i] = cnty[j][i-1];
            if(j != M-1 && S[i][j] == '1' && S[i][j+1] == '1') cnty[j][i]++;
        }
    }
    int sumx[N+1][M], sumy[M+1][N];
    rep(j, M){
        sumx[0][j] = 0;
        rep(i, N){
            sumx[i+1][j] = sumx[i][j] + cntx[i][j] - numx[i][j];
        }
    }
    rep(j, N){
        sumy[0][j] = 0;
        rep(i, M){
            sumy[i+1][j] = sumy[i][j] + cnty[i][j] - numy[i][j];
        }
    }
    //i行j列における連結成分の数
    int memo[N][M];
    rep(i, M){
        memo[0][i] = numx[0][i];
        rep2(j, 1, N-1){
            memo[j][i] = memo[j-1][i] + numx[j][i] - cntx[j-1][i];
        }
    }
    rep(i, Q){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        x1--, x2--, y1--, y2--;
        int ans = memo[x2][y2];
        ans += sumx[x1][y2]+sumy[y1][x2];
        if(y1 > 0) ans -= sumx[x1][y1-1];
        if(x1 > 0 && y1 > 0) ans -= cnty[y1-1][x1-1];
        cout << ans << endl;
    }
}

Measured memory_bytes: 116864
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)



signed main(){
  int n,a,b,c;
  cin>>n>>a>>b>>c;
  cout<<n-a-b+c<<endl;
  return 0;
}




Measured memory_bytes: 3096
#include<bits/stdc++.h>
#include<climits>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int              long long
#define umapii           unordered_map<int,int>
#define pqmaxi           priority_queue<int>
#define pqmini           priority_queue<int,vector<int>,greater<int>>
#define arr(type,a,n)    type* a = new type[n];
#define ff               first
#define ss               second
#define pb               push_back
#define w(t)             int t;cin>>t;while(t--)
#define popb             pop_back
#define mod              pow(10,9)+7;
#define mapii            map<int,int>
#define mp               make_pair
#define vint             vector<int>
#define presesion        fixed<<presesion(y)<<x
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>pbds;
int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += a[i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 3616
from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))

ruiseki = [0]
for ai in a:
    ruiseki.append(ruiseki[-1] + ai)

d = defaultdict(lambda:0)
for ri in ruiseki:
    d[ri] += 1

from math import factorial
def comb_naive(n:int, r:int)->int:
    if r > n: return 0
    ret = factorial(n) // (factorial(n-r)*factorial(r))
    return ret

ans = 0
for k in d.keys():
    ans += comb_naive(d[k], 2)
print(ans)


Measured memory_bytes: 41728
A = input()

n = len(A)
all_c = int(n * (n - 1) / 2) + 1

count_c = {}
for c in A:
    if c in count_c:
        count_c[c] += 1
    else:
        count_c[c] = 1

dup = 0
for v in count_c.values():
    if v > 1:
        dup += int(v * (v - 1) / 2)

print(all_c - dup)

Measured memory_bytes: 3500
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int teki = sc.nextInt();
		int waza = sc.nextInt();
      	long ret = 0;
      	int[] hoge = new int[teki];
      	if (teki <= waza){
        	System.out.println(0);
          	return;
        }
		for (int i = 0; i < teki; i++){
			hoge[i] = sc.nextInt();
		}
		Arrays.sort(hoge);
		for(int i = 0; i < teki - waza ; i++){
          	ret += hoge[i];
		}
		System.out.print(ret);
	}
}

Measured memory_bytes: 87696
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math

a, b = map(int, input().split())
c=gcd(a, b)
d=prime_factorize(c)
count=0
before=0
for i in range(len(d)):
    if d[i]!=before:
        count+=1
    before=d[i]

print(count+1)

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

int main() {
  int a;
  cin>>a;
  
  int s_1,s_2,s_3;
  s_3=a%10;
    s_2=a/10 %10;
    s_1=a/100;
    cout << s_1+s_2+s_3<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100010];

int main() {
    int n;
    while(~scanf("%d", &n)) {
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        map<int, int> mp;
        for(int i = 1; i <= n; i++) {
            mp[a[i]]++;
        }
        int cnt = 0;
        for(auto x:mp) {
            if(x.second % 2 != 0) cnt++;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <stdio.h>
#include <cmath>
#include <limits.h>
using namespace std;

typedef long long ll;

#define min(a, b) (((a) < (b))? (a):(b))
#define max(a, b) (((a) > (b))? (a):(b))
#define REP(i, a, n) for(int i=(a); i<(n); ++i)
#define rep(i, n) REP(i, 0, (n))
#define square(a) (a)*(a)
#define pb push_back

int n,d,x,a[110];
int main(){
	cin >> n;
	cin >> d >> x;
	rep(i,n) cin >> a[i];
	
	int eat = 0;
	rep(i,n){
		int j = 0;
		while(d >= j*a[i] + 1) j++;
		eat += j;
	}
	cout << x + eat;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int;  // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n) {
  int ret = 1;
  for (int i = 1; i < n + 1; ++i) {
    ret = ret * i;
  }
  return ret;
}

/* 最大公約数 */
template <typename T>
T gcd(T x, T y) { return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>
T lcm_n(vector<T> &numbers) {
  T l;
  l = numbers[0];
  for (int i = 1; i < numbers.size(); ++i) {
    l = lcm(l, numbers[i]);
  }
  return l;
}

/*
 * DP向け
 */
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  vector<ll> A(N);

  for (auto &v : A) {
    ll tmp;
    cin >> tmp;
    --tmp;
    v = tmp;
  }

  map<ll, ll> mem;
  vector<ll> ans(1, 0);
  mem[0] = 0;  //index番号を入れておく
  ll before = 0;
  ll first = 0;

  // for (ll i = 1; i < K; ++i) {
  //   auto result = find(mem.begin(), mem.end(), A[before]);
  //   if (result == mem.end()) {
  //     // 見つからん
  //   } else {
  //     // 見つかった
  //     first = distance(mem.begin(), result);
  //     mem.erase(mem.begin(), result);
  //     break;
  //   }
  //   mem.emplace_back(A[before]);
  //   before = A[before];
  // }
  ll r = -1;

  for (ll i = 1; i < K; ++i) {
    if (mem.find(A[before]) != mem.end()) {
      // 見つかった
      first = mem[A[before]];
      r = i - mem[A[before]];
      break;
    }
    mem[A[before]] = i;
    ans.emplace_back(A[before]);
    before = A[before];
  }

  // cout << first << endl;
  // cout << r << endl;
  // // cout << mem.size() << endl;
  // for (auto v : ans) {
  //   cout << v << "||";
  // }
  // cout << endl;

  if (r == -1) {
    // cout << "hoge";
    cout << A[before] + 1 << endl;
  } else {
    cout << ans[(K - first) % r + first] + 1 << endl;
  }

  // for (auto v : mem) {
  //   cout << v << ", ";
  // }

  return 0;
}


Measured memory_bytes: 15864
/*  ex9_1
    kento_titech*/
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define SIZE 11
typedef struct {//配列におけるスタックを構造体として定義
    int size;
    int count;
    char data[SIZE];
    char *tail;//配列の要素の末尾部分のポインタ
    char *head;//先頭部分のポインタ
} stack;

void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk, char x);
void pop(stack *stk);

stack stk;

int main(void){
    initialize_stack(&stk);
    char input[SIZE];
    int i;
    scanf("%s",input);
    for(i=0;i<strlen(input);i++){
        if(input[i]=='1'||input[i]=='0'){//'1','0'であればpush
            push(&stk,input[i]);
        }
        else//'B'のときpop
            pop(&stk);
    }
    print_stack(&stk);
    printf("\n");
    return 0;
}

void initialize_stack(stack *stk){//スタックの初期化
    stk->count = 0;
    stk->size = SIZE;
    stk->head=&(stk->data[0]);
    stk->tail=&(stk->data[0]);
}

void push(stack *stk,  char x){  //pushの定義  
    *(stk->tail) = x;
    stk->tail++;//末尾を一つ後ろに
    stk->count++;
}

void pop(stack *stk){//popの定義
    if(stk->count > 0){
        stk->tail--;//末尾を一つ前に
        stk->count--;
    }
}

void print_stack(stack *stk){//配列の中身を出力
    char *p;
    int i;    
    p = stk->head;
    for(i=0;i< stk->count;i++)//先頭からすべての要素を出力
        printf("%c",*p++);
}

Measured memory_bytes: 1640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<ctype.h>
#include<math.h>
#define PI 3.14159265359
#define N_MAX 10000
#define NUM 1000
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) > (y) ? (x) : (y))

bool prime(const int n)
{
  int i;
  if(n <= 1) return false;
  if(n == 2) return true;
  for(i = 2; i <= sqrt(n); i++)
    {
      if(n%i == 0) return false; 
    }
  return true;
}

int main()
{
  int i,n,count = 0,a[N_MAX];
  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&a[i]);
  for(i = 0; i < n; i++)
    {
      if(prime(a[i])) count++;
    }
  printf("%d\n",count);
  return 0;
}

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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, a, b;
	cin >> n >> a >> b;

	cout << (n * a < b ? n * a : b) << endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c, k = map(int,input().split())
 
if a >= k:
  print(k)
elif k > a and b >= k - a:
  print(a)
elif k > a and k - a > b and a != 0:
  print(a - (k - a - b))
elif k > a and k - a > b and a == 0:
  print(0 - (k - b))

Measured memory_bytes: 9100
use std::collections::*;
use std::io::*;
use std::*;
// template {{{
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        _get!($it; String).bytes().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_get!($it; $t)),*)
    };
}
// }}}

fn main() {
    let (n, k) = get!(usize, usize);
    let a = get!([i32]);
    for i in k..=n - 1 {
        let l = i - k;
        println!("{}", if a[i] > a[l] { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 5084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    string S, T;
    cin >> S >> T;
    bool ok = true;
    map<char,char> ma, ima;
    for (int i = 0; i < S.size(); ++i) {
        char s = S[i], t = T[i];
        if (ma.count(s)) if (ma[s] != t) ok = false;
        if (ima.count(t)) if (ima[t] != s) ok = false;
        ma[s] = t; ima[t] = s;
    }
    if (ok) puts("Yes");
    else puts("No");
}


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

int main() {
    int n, m;
    cin >> n;
    unordered_map<ll, int> counter;
    rep(i, n) {
        ll d;
        cin >> d;
        ++counter[d];
    }
    cin >> m;
    rep(i, m){
        ll t;
        cin >> t;
        if(counter[t]-- <= 0){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}

Measured memory_bytes: 8520
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#define lint long long
#define gc getchar()
#define N 200010
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int main()
{
	int n;scanf("%d",&n);lint s=0ll,v=LLONG_MAX;
	for(int i=1,a,b;i<=n;i++) 
		s+=(a=inn()),((b=inn())<a)?v=min(v,(lint)b):0;
	return !printf("%lld\n",max(0ll,s-v));
}

Measured memory_bytes: 256
N = int(input())
dict_names = dict()
for i in range(N):
  new_name = input()
  if new_name not in dict_names.keys():
    dict_names[new_name] = 1
  else:
    dict_names[new_name] += 1
max_count = max(count for count in dict_names.values())
list_of_max_counted_names = [name for name in dict_names if dict_names[name]==max_count]
list_of_max_counted_names.sort()
[print(name) for name in list_of_max_counted_names]

Measured memory_bytes: 32476