akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

using Graph = vector<vector<pair<int,int>> >;
Graph G;

vector<bool> ok;

// v は現在見ている頂点, p は v の親
void dfs(int v, int p ) {
  for (auto t : G[v]) {
    int next = t.F;
    if (next == p) continue;  // これがツリー探索で一般的な書き方
    int w = t.S;

    if(w % 2 == 0)ok[next] = ok[v];
    else ok[next] = !ok[v];
    dfs(next, v);
  }
}

int main(){
    int N;cin >> N;
    G.resize(N);
    ok.resize(N,false);
    rep(i,N-1){
        int u,v,w;cin >> u >> v >> w;
        u--;v--;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }

    int root = 0;
    ok[root] = true;
    dfs(root, -1); // root の親はいないので -1

    rep(i,N){
        if(ok[i])cout << 1 << endl;
        else cout << 0 << endl;
    }
}


Measured memory_bytes: 8576
#f
N,U,V = map(int,input().split())
U-=1
V-=1
tree =[[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)

from collections import deque
def shortest(tree,start):
    from_start=[None]*N
    q = deque([(-1,start,0)])
    while q:
        parent,x,time = q.popleft()
        if tree[x]==[parent] or (len(tree[x])==1 and parent==-1):#行き先が親しかない＝＝葉ノード
            from_start[x]=time
        for y in tree[x]:
            if y == parent:#親ノードを飛ばし
                continue
            q.append((x,y,time+1))#子ノードを追加
    return from_start

from_u = shortest(tree,U)
from_v = shortest(tree,V)

print( max([vv for uu,vv in zip(from_u,from_v) 
            if isinstance(uu, int) and isinstance(vv, int) and uu<vv])-1 )

Measured memory_bytes: 95272
import sys


#https://note.nkmk.me/python-union-find/
class AlgUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    uf = AlgUnionFind(n)
    cnt = n * (n - 1) // 2
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    ab.reverse()
    res = []
    for a, b in ab:
        res.append(cnt)
        a -= 1
        b -= 1
        if not uf.same(a, b):
            cnt -= uf.size(a) * uf.size(b)
        uf.union(a, b)
    res.reverse()
    print(*res, sep="\n")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 106716
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll n = 0, c = 1, k = 0, t = 1, ans = 0;
    cin >> n;

    vector<string>s(n, "");
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

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

    for (int i = 0; i < n-1; i++) {
        if (s[i] == s[i+1]) {
            c++;
        } else {
            ans = ans + c*(c-1)/2;
            c = 1;
        }
    }

    ans = ans + c*(c-1)/2;

    cout << ans << endl;
}


Measured memory_bytes: 7296
#include<iostream>
#include <vector>
#include <cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<math.h>
#include <list>
#define ll long long 
using namespace std;




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

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ll A;
    string B;
    cin >> A >> B;
    string BB = "";
    BB += B[0];
    BB += B[2];
    BB += B[3];
    ll b = stoll(BB);
    cout << (A*b)/100 << endl;
}

Measured memory_bytes: 3632
def number(c) # H8 -> 8
  c[1, c.size-1].to_i
end

def bubble_sort(a, n)
  0.upto(n-2){|i|
    (n-1).downto(i+1){|j|
      if number(a[j]) < number(a[j-1])
        t=a[j];a[j]=a[j-1];a[j-1]=t
      end
    }
  }
end

def selection_sort(a, n)
  n.times{|i|
    m=i
    i.upto(n-1){|j|
      m = j if number(a[j]) < number(a[m])
    }
    t=a[i];a[i]=a[m];a[m]=t
  }
end

n=gets.to_i
b=gets.split
s=b.dup

bubble_sort(b, n)
puts b*" "
puts "Stable"

selection_sort(s, n)
puts s*" "
puts (b==s ? "Stable" : "Not stable")


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


int main()
{
    int n; ll k;
    cin >> n >> k;
    vector<int> to(n);
    rep(i,n) {
        cin >> to[i];
        to[i]--;
    }


    vector<int> seen(n,-1);
    vector<int> path(n);
    int s;
    int cur = 0;
    int sz = 0;
    for(;;sz++) {
        if(seen[cur] != -1) {
            s = seen[cur]; // pathの[s]~[sz-1]がcycle
            break;
        }
        else {
            seen[cur] = sz;
            path[sz] = cur;
            cur = to[cur];
        }
    }

    if(k < s) {
        cout << path[k] + 1 << endl;
    }
    else {
        k -= s;
        cout << path[s + k%(sz-s)] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5644
import java.util.*;
public class Main {
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	int k = sc.nextInt();
    	int[] except = new int[n];
    	prepare(n);

    	for (int i = 0; i < m; i++) {
    		int a = sc.nextInt()-1;
    		int b = sc.nextInt()-1;
    		union(a,b);
    		except[a]++;
    		except[b]++;
    	}
    	for (int i = 0; i < k; i++) {
    		int a = sc.nextInt()-1;
    		int b = sc.nextInt()-1;
    		if(find(a) == find(b)){
    		except[a]++;
    		except[b]++;
            }
    	}


    	for (int i = 0; i < n; i++) {
	    	System.out.print(desc[find(i)]-except[i] + " ");
	    }
    }
	private static int[] parent;
	private static int[] desc;

	private static void prepare(int n) {
		parent = new int[n];
		for (int i = 0; i < n; i++) {
			parent[i] = i;
		}
		desc = new int[n];
	}

	private static void union(int a, int b) {
		int xroot = find(a);
		int yroot = find(b);
		if (xroot == yroot) return;
		if (desc[xroot] >= desc[yroot]) {
			parent[yroot] = xroot;
			desc[xroot] += desc[yroot]+1;
		} else {
			parent[xroot] = yroot;
			desc[yroot] += desc[xroot]+1;
		}
	}

	private static int find(int a) {
		if (parent[a] == a) {
			return a;
		} else {
			return find(parent[a]);
		}
	}
}



Measured memory_bytes: 99252
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		char[]in=s.nextLine().toCharArray();
		long res=1,n=in.length;
		int c[]=new int[26];
		for(int i=0;i<n;++i){
			res+=i-c[in[i]-'a']++;
		}
		System.out.println(res);
	}
}

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

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

    int n, m;
    cin >> n >> m;
    int fav[m + 1];
    memset(fav, 0, sizeof(fav));
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int a;
            cin >> a;
            fav[a]++;
        }
    }
    
    int res = 0;
    for (auto f: fav) {
        res += f == n;
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
// vector<ll> A;

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

  int ans = 0;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      int cij = 0;
      int cji = 0;

      for (int k = 1; k <= N; k++) {
        int n = k;
        int tail = k % 10;
        int head = 0;
        while (n >= 10) {
          n /= 10;
        }
        head = n;

        if (i == head && j == tail) {
          cij++;
        }
        if (j == head && i == tail) {
          cji++;
        }
      }

      ans += cij * cji;
    }
  }

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


Measured memory_bytes: 888
#define _GLIBCXX_DEBUG
#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()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int m;
  cin >> m;
  cout << 48 - m << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    ll x; cin >> x;
    ll mod = x%11;
    if(mod==0)cout << x/11*2 << endl;
    else if(mod<=6)cout << x/11*2+1 << endl;
    else cout << x/11*2+2 << endl;
    return 0;
}

Measured memory_bytes: 256
k,s=[int(i) for i in input().split()]
count = 0
for y in range(k+1):
 if y < s - k * 2 or s - y < 0:
  continue
 for x in range(k+1):
   if s - x - y >= 0 and s - x - y <= k:
      count = count+1
print(count)

Measured memory_bytes: 2940
#include <stdio.h>
int main(){
	int a = 0,b = 0;
	int c = 0;
	int count = 1;
	while(scanf("%d %d",&a,&b) != EOF){
		c = a + b;
		while(1){
			if(c / 10 < 10){
				count++;
				break;
			}
			else{
				c /= 10;
				count++;
			}
		}
		printf("%d\n",count);
		count = 1;
	}
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	if(n>=65 && n<=90){
		cout<<"1"<<endl;
		
	}else if(n>=97 && n<=122){
		
		cout<<"2"<<endl;
	}else{
		cout<<0<<endl;
	}
}


Measured memory_bytes: 3100
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

int n,m,a,b,c,x,y,aa[100010],ba[100010],ms[1000010];
bool r,br,ar;
string s;
char ca,cb;


int main(){
    cin>>n;
    m=0;
    for(int i=0;i<n;i++)cin>>aa[i];
    
    for(int i=0;i<100;i++){
        x=0;
        br=false;
        for(int j=0;j<n;j++){
            ar=(i<aa[j]);
            if(ar==false and br==true)x+=1;
            br=ar;
        }
        m+=x;
        m+=br;
        
    }
    printf("%d\n",m);
}


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

using namespace std;

const int mod = (int) 1e9 + 7;

int main() {
  int n;
  cin >> n;
  
  if (n == 3) {
    cout << 61 << '\n';
    return 0;
  }

  auto check = [](string s) {
    assert(s.length() == 4);
    if (s.substr(0, 3) == "AGC" || s.substr(1, 3) == "AGC") {
      return false;
    }
    for (int i = 0; i < 3; i++) {
      swap(s[i], s[i + 1]);
      if (s.substr(0, 3) == "AGC" || s.substr(1, 3) == "AGC") {
        return false;
      }
      swap(s[i], s[i + 1]);
    }
    return true;
  };

  vector<string> alpha = {"A", "T", "C", "G"};
  map<string,int> dp;
  for (auto a : alpha) {
    for (auto b : alpha) {
      for (auto c : alpha) {
        dp[a + b + c]++;
      }
    }
  }

  for (int i = 0; i < n - 3; i++) {
    map<string,int> dp_new;
    for (auto c : alpha) {
      for (auto s : dp) {
        string t = s.first + c;
        if (check(t)) {
          (dp_new[t.substr(1, 3)] += s.second) %= mod;
        }
      }
    }
    swap(dp, dp_new);
  }

  int ans = 0;
  for (auto i : dp) {
    ans = (ans + i.second) % mod;
  }
  cout << ans << '\n';
    
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
const int MX = 100005;
char s[MX];
int n, len, l, r;
bool used[MX];
vector<int> G[MX];
int dfs(int t){
	int ret = s[t] - (t ? s[t-1] : 0);
	used[t] = true;
	for(int nx: G[t]) if(!used[nx]) ret += dfs(nx);
	return ret;
}
int main(){
	scanf("%s\n%d", s, &n);
	len = (int)strlen(s);
	rep(i,n){
		scanf("%d%d", &l, &r); l--;
		G[l].push_back(r);
		G[r].push_back(l);
	}
	rep(i,(len+1)/2){
		G[i].push_back(len-i);
		G[len-i].push_back(i);
	}
	dfs(0);
	rep(i,len) if(!used[i] && dfs(i) % 26) return 0*puts("NO");
	puts("YES");
}

Measured memory_bytes: 7680
#include <iostream>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

#define MAX 100000

typedef pair<int, int> P;

int main(){
	vector <P> city[20];
	int n;
	int m;
	int a, b, c, d;
	char e;
	cin >> n;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> e >> b >> e >> c >> e >> d;
		city[a].push_back(P(c, b));
		city[b].push_back(P(d, a));
	}
	int citty[20];
	for (int i = 0; i < 20; i++) {
		citty[i] = MAX;
	}
	int x1, x2, y1, y2;
	cin >> x1 >> e >> x2 >> e >> y1 >> e >> y2;

	citty[x1] = 0;
	priority_queue< P, vector<P>, greater<P> > pq;
	pq.push(P(0, x1));

	while (!pq.empty()) {
		P p = pq.top();
		pq.pop();
		int v = p.second;
		if (citty[v] < p.first) {
			continue;
		}
		for (int i = 0; i < city[v].size(); i++) {
			P pp = city[v][i];
			if (citty[pp.second] > citty[v] + pp.first) {
				citty[pp.second] = citty[v] + pp.first;
				pq.push(P(citty[pp.second], pp.second));
			}
		}
	}
	int ouro = citty[x2];

	for (int i = 0; i < 20; i++) {
		citty[i] = MAX;
	}
	citty[x2] = 0;
	pq.push(P(0, x2));
	while (!pq.empty()) {
		P p = pq.top();
		pq.pop();
		int v = p.second;
		if (citty[v] < p.first) {
			continue;
		}
		for (int i = 0; i < city[v].size(); i++) {
			P pp = city[v][i];
			if (citty[pp.second] > citty[v] + pp.first) {
				citty[pp.second] = citty[v] + pp.first;
				pq.push(P(citty[pp.second], pp.second));
			}
		}
	}
	int fukuro = citty[x1];
	cout << y1-y2-ouro-fukuro << endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k;
	cin >> k;
	int cur = 0, p10 = 7;
	set<pair<int, int>> s;
	for (int i = 1;; i++) {
		cur = (cur + p10) % k;
		p10 = (p10 * 10) % k;
		if (!cur) {
			cout << i;
			return 0;
		}
		if (s.count({cur, p10})) {
			cout << -1;
			return 0;
		}
		s.insert({cur, p10});
	} 
}



Measured memory_bytes: 50468
#include <bits/stdc++.h>
#define f first
#define s second

using namespace std;
const int MAXN=3e3+5;
pair<int,int> dp[MAXN][MAXN];

int S,T;
string s,t;

int main(){
    cin>>s>>t;
    S=s.size();
    T=t.size();
    for(int i=0;i<=S;i++)dp[i][T]={0,-1};
    for(int i=0;i<=T;i++)dp[S][i]={0,-1};
    for(int i=S-1;i>=0;i--)
        for(int j=T-1;j>=0;j--){
            dp[i][j]={dp[i+1][j].f,0};
            if(dp[i][j].f<dp[i][j+1].f)dp[i][j]={dp[i][j+1].f,1};
            if(s[i]==t[j]&&dp[i][j].f<dp[i+1][j+1].f+1)dp[i][j]={dp[i+1][j+1].f+1,2};
        }
        int i=0,j=0;
        string st="";
        while(i!=S&&j!=T){
            if(dp[i][j].s==0)i++;
            else if(dp[i][j].s==1)j++;
            else st+=s[i],i++,j++;
        }
        cout<<st;
}

Measured memory_bytes: 70784
n,a,b,c,d =map(int,input().split())
n -= 1
ans1 = a + c*n+d+c
ans2 = a+d*n+c+d
for i in range(n+1):
  ans1 -= d+c
  ans2 -= c+d
  if (ans1<= b and b<=ans2):
    print("YES")
    exit()
print("NO")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<map>

int64_t const MOD = 1e9+7;

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};
typedef mod_int<MOD> mint;

void add(int x, int y, int z, std::map<std::pair<int,int>,mint>&s, mint v) {
  if(x > y) std::swap(x, y);
  if(x > z) std::swap(x, z);
  if(y > z) std::swap(y, z);
  s[std::make_pair(x,y)] += v;
}
int main() {
  int N; std::cin >> N;
  std::map<std::pair<int,int>,mint> s;
  s[std::make_pair(0,0)] = mint(1);
  for(int i = 0; i < N; ++i) {
    int A; std::cin >> A;
    std::map<std::pair<int,int>,mint> n;
    for(auto p: s) {
      int x = p.first.first, y = p.first.second, z = i - x - y;
      if(A == x) add(x+1, y, z, n, p.second);
      if(A == y) add(x, y+1, z, n, p.second);
      if(A == z) add(x, y, z+1, n, p.second);
    }
    s.swap(n);
  }
  mint ans;
  for(auto p: s) ans += p.second;
  std::cout << ans.v_ << std::endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
ans=[]
l=list(map(int,input().split()))
if min(l)>=0:
    m=1
if max(l)<=0:
    m=-2
if max(l)>0 and min(l)<0:
    if max(l)>=-min(l):
        m=max(l)
    else:
        m=min(l)
    mi=l.index(m)
    for i in range(n):
        if m>0:
            if l[i]<0:
                ans.append([mi+1,i+1])
        else:
            if l[i]>0:
                ans.append([mi+1,i+1])
if m>0:
    for i in range(n-1):
        ans.append([i+1,i+2])
else:
    for i in range(n,1,-1):
        ans.append([i,i-1])
print(len(ans))
for i in ans:
    print(*i)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll f (ll a, ll m) {
  return (a*a) % m;
}

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  ll ans = 0;
  map<ll, int> ms;
  vector<ll> ans_log, xs;
  ll r = 0; int r_i = 0;
  rep(i,0,m+3) {
    if (ms[x] != 0) {
      r = ans_log[ms[x]-1] - xs[ms[x]-1];
      r_i = ms[x]-1;
      break;
    }
    ans += x;
    ans_log.pb(ans);
    xs.pb(x);
    ms[x] = i+1;
    x = f(x, m);
  }
  if (n <= r_i) {
    cout << ans_log[n-1] << endl;
    return 0;
  }

  ll kr = ans_log[len(ans_log)-1] - r;
  ll c_r = len(ans_log) - r_i;
  n -= r_i;
  ans = (n/c_r) * kr + r;
  n %= c_r;
  if (n == 0) {
    cout << ans << endl;
    return 0;
  }
  ans += ans_log[r_i - 1 + n] - r;
  cout << ans << endl;
  return 0;
}


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

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

using namespace std;
using lint = long long;

int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  vector<int> a(n);
  rep(i, n) scanf("%d", &a[i]);

  lint ans = 0;
  rep(i, n - 1) if (a[i] + a[i + 1] > x) {
    ans += a[i] + a[i + 1] - x;
    a[i + 1] = x - a[i];
    if (a[i + 1] < 0) {
      a[i] += a[i + 1];
      a[i + 1] = 0;
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define BLACK 2
#define GRAY 1
 
int n, M[MAX][MAX];
 
int prim(){
    int u,minv;
    int d[MAX],p[MAX],color[MAX];
     
    for(int i=0; i<n; i++){
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }
     
    d[0]=0;
     
    while (1) {
        minv=INFTY;
        u=-1;
        for(int i=0; i<n; i++){
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
         
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0; v<n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
     
    int sum =0;
    for(int i=0; i<n; i++){
        if(p[i] != -1) sum+= M[i][p[i]];
    }
    return sum;
}
 
int main(){
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int e;
            scanf("%d",&e);
            M[i][j] = (e == -1) ? INFTY:e;
             
        }
    }
    printf("%d\n", prim());
    return 0;
}



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

int main() {
  string s;
  cin >> s;
  while(s.size() > 0) {
    string sub = s.substr(0, min(11, (int)s.size()));
    if(sub.size() == 11 && sub == "dreameraser")
      s.erase(s.begin(), s.begin() + 11);
    else if(sub.size() >= 7 && sub.substr(0, 10) == "dreamerase")
      s.erase(s.begin(), s.begin() + 10);
    else if(sub.size() >= 7 && sub.substr(0, 7) == "dreamer")
      s.erase(s.begin(), s.begin() + 7);
    else if(sub.size() >= 6 && sub.substr(0, 6) == "eraser")
      s.erase(s.begin(), s.begin() + 6);
    else if(sub.size() >= 5 && sub.substr(0, 5) == "dream")
      s.erase(s.begin(), s.begin() + 5);
    else if(sub.size() >= 5 && sub.substr(0, 5) == "erase")
      s.erase(s.begin(), s.begin() + 5);
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

class MainClass
{

    public static void Main(string[] args)
    {
        var _ = LnInts();
        var N = _[0];var M = _[1];
        var As = LnInts();
        var total = 0;
        foreach(var i in As)
        {
            total += i;
        }
        var count = 0;
        foreach
        (var i in As)
        {
            if (i >= total / (4f * M)) count++;
        }
        Console.WriteLine(count >= M ? "Yes" : "No");
    }


    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b){if (a > b){var r = a % b;if (r == 0) return b; else return Gcd(b, r);}else{ var r = b % a; if (r == 0) return a; else return Gcd(a, r); }}
public static int[] LnInts(){var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);var ins = new int[vs.Length];for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]);return ins;}public static int LnInt(){var vs = Console.ReadLine().Trim();return int.Parse(vs);}public static long[] LnLngs(){var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);var ins = new long[vs.Length];for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]);return ins;}public static long LnLng(){var vs = Console.ReadLine().Trim();return long.Parse(vs);}public static string[] LnStrs(){var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);return vs;}public static string LnStr(){var vs = Console.ReadLine().Trim();return vs;}}





Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    string s,t;
    cin>>s>>t>>s;
    cout<<"A"<<t[0]<<"C"<<endl;
}

Measured memory_bytes: 3568
#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<algorithm>

using namespace std;

string s = "01234567";
string now, net;
map <string, int> mp;
int dt[] = {1, -1, 4, -4};

void bfs() {
	
	queue <string> que;
	que.push(s);
	while(que.size()) {
		now = que.front();
		que.pop();
		
		int pos = now.find('0');
		for(int i = 0; i < 4; i++) {
			
			int tpos = pos + dt[i];
			if(tpos >= 0 && tpos < 8 && !((pos == 3 || pos == 7) && i == 0) && !((pos == 0 || pos == 4) && i == 1)) {
				net = now;
				swap(net[pos], net[tpos]);
				if(mp[net] == 0) {
					mp[net] = mp[now] + 1;
					que.push(net);
				}
			}
		}
	}
	
	return;
}
int main() {
	
	bfs();
	mp[s] = 0;
	while(getline(cin, s)) {
		s.erase(remove(s.begin(),s.end(),' '),s.end());
		cout << mp[s] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 5364
#include<bits/stdc++.h>
#include<chrono>
#define ll long long
#define mod 1000000007
#define endl '\n'
#define tab ' '
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pi 3.141592653589793238460
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define RF(i,a,b) for(int i=(int)a;i>=(int)b;i--)
// a.exe < "C:/Users/Piyush Naithani/Desktop/Codechef/Testfiles/icpc2.txt"
using namespace std;

void solve()
{
    int a, b;
    cin >> a >> b;

    if(a==1 and b==2) cout<<3;
    else if(a==1 and b==3) cout<<2;
    else if(a==2 and b==3) cout<<1;
    else if(a==2 and b==1) cout<<3;
    else if(a==3 and b==1) cout<<2;
    else cout<<1;
    
    
}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
      // freopen("C:\Users\Piyush Naithani\Desktop\Codechef\Testfiles\icpc2.txt","r",stdin);
    
    // freopen("file name","w",stdout);
    #endif

    solve();

    return 0;
}


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

using namespace std;

int main(void){
  vector<string> str(3);
  
  for(int i = 0 ; i < 3 ; i++){
    cin >> str[i];
    transform(str[i].begin(),str[i].end(), str[i].begin(), ::toupper);
  }
  
  cout << str[0][0] << str[1][0] << str[2][0] << endl;
  
  return 0;
}

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

int main() {
  //入力を受け取る
  int N, X, T;
  cin >> N >> X >> T;
  
  //たこ焼きを焼く回数を求める
  int times = (N + X - 1) / X;
  
  //答えを求める
  int ans = times * T;
  
  //答えを出力する
  cout << ans << endl;
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll a, b;
    cin >> a >> b;
    if (a*b %2){cout << "Yes";}
    else{cout << "No";}
}
// Driver Function
int main()
{
    ll compte = 1;
   // test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    bool flag = false;
    int N = 100 * n;
    for (int i = 0; i < 100; i++) {
        if ((N + i) % 108 == 0) {
            flag = true;
            ans = (N + i) / 108;
            break;
        }   
    }   
    if (flag) {
        cout << ans << endl;
    }   
    else {
        cout << ":(" << endl;
    }   
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



def main():
    n =  I()
    final_slime = sorted(LI(), reverse=True)
    now_slime = [final_slime[0]]
    made_or_not = [0] * (2 ** n)
    made_or_not[0] = 1
    for i in range(n):
        k = 0
        for j in range(len(now_slime)):
            flag = 1
            while flag:
                if k == 2 ** n:
                    return 'No'
                if made_or_not[k] == 0 and now_slime[j] - 1 >= final_slime[k]:
                    now_slime += [final_slime[k]]
                    made_or_not[k] = 1
                    flag = 0
                k += 1
        now_slime.sort(reverse=True)
    return 'Yes'



print(main())

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    int m = 0;
    int preH;
    cin >> preH;
    for(int i = 1;i<n; i++){
        int H;
        cin >> H;
        if(H <= preH){
            m++;
            ans = max(ans, m);
        }else{
            ans = max(ans, m);
            m = 0;
        }
        preH = H;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
namespace {
  template <typename T> inline void read(T &x) {
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    for(;  isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
    x *= f;
  }
}
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lowbit(x) x & (-x)
#define pii pair<int,int>
#define fi first
#define se second
const int MAXN = 60;
int a[MAXN];
int main() {
  int n; read(n);
  int sum = 0;
  for(int i = 0; i < n; ++i) read(a[i]); 
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      sum += a[i] * a[j];
    }
  }
  cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int INF = 998244353;
ll func(ll a,ll b){//aのb乗を返す
    ll res = 1;
    for(int i = 0;i<b;i++){
        res *= a;
        res = res%INF;
    }
    return res;

}
using Graph = vector<vector<int>>;
/*
*/


int main() {
   ll N;
  cin >> N;
   vector<ll> D(N);
   rep(i,N){
       cin >> D[i];
   }
  
   if(D[0] != 0) cout << 0 << endl;
   else{
     sort(D.begin(),D.end());
     D.push_back(-1);

     vector<pair<ll,ll>> p;//(Di,Diの点の個数)のペア配列
     ll c = 1;//Diの個数
     for(int i = 0;i<N;i++){
       if(D[i] == D[i+1]) c++;
       else if(D[i] != D[i+1]){
           p.push_back(make_pair(D[i],c));
           c = 1;
       }
     }
     /*for(int i = 0;i<p.size();i++){
         cout << p[i].first << " " << p[i].second << endl;
     }*/
  
     bool flag = true;//隣あうp[i].firstの差が2以上ならfalse
     for(int i = 0;i<p.size()-1;i++){
         if(p[i+1].first - p[i].first >= 2){
             flag = false;
             break;
         }  
     }
     if(p[0].second >= 2) flag = false;
     
     if(flag){
       ll ans = 1;
       for(int i = 0;i<p.size()-1;i++){
           ans *= func(p[i].second,p[i+1].second);
           ans = ans%INF;
       }
       cout << ans << endl;
     }
     else cout << 0 << endl;
   }
}

Measured memory_bytes: 4080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int X = H1 * 60 + M1;
    int Y = H2 * 60 + M2;
    cout << Y - X - K << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl "\n"
 
int main ()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //#define int ll
  
  int n, m, x;
  cin >> n >> m >> x;

  vector <int> prices(n);
  vector <vector <int> > increase(n, vector <int> (m, 0));

  for (int i=0; i<n; i++){
    cin >> prices[i];
    for (int j=0; j<m; j++) cin >> increase[i][j];
  }  

  int ans = INT_MAX;
  for (int mask = 0; mask < (1<<n); mask++){
    int total_price = 0;
    vector <int> total_understanding(m, 0);
    for (int bit = 0; bit < n; bit++){
      if (mask&(1<<bit)){
        total_price += prices[bit];
        for (int algorithm = 0;algorithm < m; algorithm++){
          total_understanding[algorithm] += increase[bit][algorithm];
      }
    }
  }
  bool flag = true;
  for (int i=0; i<m; i++){
    if (total_understanding[i] < x){
      flag = false;
      break;
    }
  }

  if (flag) ans = min(ans, total_price);
}
if (ans != INT_MAX) cout << ans << endl;
else cout << -1 << endl;

  return 0;
  
}


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

int main(void){
    ll k;
    cin>>k;
    ll x = 7%k;
    int count=0;
    if(k%2==0) count = -1;
    else if(k%5==0) count = -1;
    else{
        rep(i,k){
            if(x==0){
                count = i+1;
                break;
            }
            x=(x*10+7)%k;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

// const abcd = "abcdefghijklnmopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

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

///////////////////////////////////////////////////

func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	H := next.Int()
	W := next.Int()
	s := make([]string, H)
	for i := 0; i < H; i++ {
		s[i] = next.Line()
	}
	ans := make([][]byte, H)
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if s[i][j] == '.' {
				cnt := 0
				for k := 0; k < 8; k++ {
					ny := i + dy[k]
					nx := j + dx[k]
					if in(ny, 0, H) && in(nx, 0, W) {
						log.Println(ny, nx)
						cnt += btoi(s[ny][nx] == '#')
					} else {
						continue
					}
				}
				ans[i] = append(ans[i], byte(cnt)+'0')
			} else {
				ans[i] = append(ans[i], '#')
			}
		}
	}
	for i := 0; i < H; i++ {
		fmt.Println(string(ans[i]))
	}

}

///////////////////////////////////////////////////
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) nextInt64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

int k;
int memo[100005];
vector<int> a;

int grundy(int n) {
	if(n < 0) return -1;
	auto& p = memo[n];
	if (p != -1) return p;

	set<int> s;
	rep(i, a.size()) {
		s.emplace(grundy(n - a[i]));
	}

	int res = 0;
	while (s.count(res)) res++;
	return p = res;
}

signed main() {
	int n;
	cin >> n >> k;
	a = vector<int>(n);
	cin >> a;

	rep(i,100005) memo[i]=-1;
	memo[0]=0;
	if (grundy(k)) {
		cout << "First" << endl;
	} else {
		cout << "Second" << endl;
	}
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define D 1000000007
using namespace std;
using ll = long long;

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

    ll ans = 1;
    ll alpha[26] = {0};

    for(int i=0; i<n; i++){
        alpha[s[i] - 'a']++;
        alpha[s[i] - 'a'] %= D;
    }
    for(int i=0; i<26; i++){
        ans *= (alpha[i]+1);
        ans %= D;
    }
    ans = ans - 1;
    cout<< ans << endl;
    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;


int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int a, b, c;
	cin>>a>>b>>c;
	set<pair<int, PII> > S;

	int res = 0;

	while(true)
	{
		if (S.count(MP(a, MP(b, c))))
		{
			cout<<-1<<endl;
			return 0;
		}

		S.insert(MP(a, MP(b, c)));

		if(a & 1) break;
		if(b & 1) break;
		if(c & 1) break;

		int A = b / 2 + c / 2;
		int B = a / 2 + c / 2;
		int C = a / 2 + b / 2;

		a = A;
		b = B;
		c = C;
		res++;
	}

	cout<<res<<endl;


}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep(i,j,n) for(int i=(j);i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	string s[3];
	int n[3] = {},now = 0;
	cin >> s[0] >> s[1] >> s[2];
	while(n[now] != s[now].length()){
		n[now]++;
		now = s[now][n[now] - 1] - 'a';
	}
	printf("%c\n",now + 'A');
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int ans=0;
    vector<vector<P>> testimony(n);
    rp(i,n){
        int a;
        cin >> a;
        rp(j,a){
            int x,y;
            cin  >> x >> y;
            x--;
            testimony[i].push_back(make_pair(x,y));
        }
    }
    for(int i=1; i<(1<<n); i++){
        bool ok=true;
        rp(j,n){
            if(i&(1<<j)){
                for(auto p:testimony[j]){
                    if(((i>>p.first)%2)^p.second)
                    {ok=false; break;}
                }
            }
            if(!ok) break;
        }
        if(ok) ans=max(ans,__builtin_popcount(i));
    }
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 256
n=int(input())
x=list(map(int,input().split()))
t=sorted(x)
m=n//2
a=t[m-1];b=t[m]
#print(a,b)
for i in range(n):
    if x[i]<=a:
        print(b)
    else:
        print(a)
  

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if ((A + B) > (C + D)) {
        cout << "Left";
    }
    else if ((A + B) == (C + D)) {
        cout << "Balanced";
    }
    else {
        cout << "Right";
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import math
import sys

def solve(N: int, a: "List[int]"):
    dp = [0] * N
    for i in range(N, 0, -1):
        if i > N // 2:
            dp[i-1] = a[i-1]
        else:
            for j in range(2, N // i+1):
                dp[i-1] += dp[j * i - 1]
            dp[i-1] += a[i-1]
            dp[i-1] %= 2
    print(sum(dp))
    s = []
    for i in range(N):
        if dp[i] == 1:
            s.append('%d' % (i + 1))
    if len(s) > 0:
        print(' '.join(s))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


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

int main(){
 int a[5];
 for (int i = 0; i < 5; i++) {
    cin >> a[i];
 }
 int k;
 cin >> k;
 bool flag = true;
 for (int i = 1; i < 5; i++) {
    if (a[i] - a[0] > k) flag = false;
 }
 if (flag)
     cout << "Yay!" << '\n';
 else
     cout << ":(" << '\n';

}


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

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

	long long N;
	vector<long long> A(5);
	cin >> N >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];

	printf("%lld",
	       5 - 1 +
	           (long long)(ceil((double)N / *min_element(A.begin(), A.end()))));

	return 0;
}

Measured memory_bytes: 256