akhauriyash/Code-Regression huggingface dataset:
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
S=get_i
Q=gets.to_i
T=get_i
ans=0
T.each do|t|
  if S.include?(t)
      ans+=1
  end
end
puts ans


Measured memory_bytes: 7176
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int n;
vector<vector<int>> g;

void input() {
	cin >> n;
	g.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
}

vector<int> path;

tuple<bool, int> dfs(int s = 0, int p = -1) {
	int cnt_children = 0;
	int rem = 0;
	bool is_path = false;
	if (s == n - 1) is_path = true;
	for (auto c : g[s]) {
		if (c != p) {
			tuple<bool, int> tmp = dfs(c, s);
			is_path |= get<0>(tmp);
			cnt_children += get<1>(tmp) + 1;
			if (get<0>(tmp)) rem = get<1>(tmp) + 1;
		}
	}
	if (is_path)
		path.push_back(cnt_children + 1 - rem);
	return make_tuple(is_path, cnt_children);
}

int main() {
	input();
	dfs();
	reverse(path.begin(), path.end());
	int f_ptr = 0, s_ptr = path.size() - 1;
	int cnt_f = 0, cnt_s = 0;
	while (f_ptr <= s_ptr) {
		cnt_f += path[f_ptr++];
		if (s_ptr >= f_ptr)
			cnt_s += path[s_ptr--];
	}
	if (cnt_f > cnt_s)
		cout << "Fennec" << endl;
	else
		cout << "Snuke" << endl;
	return 0;
}

Measured memory_bytes: 9980
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    for(int T = 0; T < t ; T++){
        ll x, n;
        cin >> x >> n;
        ll p[n], a[102] = {0};
        ll ans = 101;
        for(int i= 0; i < n; i++){
            cin >> p[i];
            a[p[i]] = 1;
        }
        ll index = 123;
        for(int i = 101; i >= 0; i--){
            if(a[i] == 0){
                ll d = abs(x - i);
                if(d <= ans){
                       ans = d;
                       index = i;
                }
            }
        }
        std::cout << index << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import itertools
import math
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
tmp = [ i for i in range(1,1+N)]
a = b = 0

for li,i in zip(itertools.permutations(tmp),range(1,math.factorial(N)+1)):
    if P==list(li):
        a = i
    if Q==list(li):
        b = i
    if a!=0 and b!=0:
        break

print(abs(a-b))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    int sum = 0;
    for(int i=0; i<n-1; i++){
        sum += l.at(i);
    }
    if(l.at(n-1) < sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int ans = 0;
    K *= 2;
    for (int i = 0; i < N - 1; i++) {
        if (S[i] == S[i + 1]) ++ans;
        else if (S[i] != S[i + 1] && K != 0) {
            ++ans;
            --K;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>   
using namespace std;
#define N 100
#define REP(i, n) for(int i=0; i<n; i++)
int n;
int a[2][N];
int b[2][N];
int main(void){
    cin>>n;
    REP(i,n)cin>>a[0][i];
    REP(i,n)cin>>a[1][i];
    b[0][0]=a[0][0];
    b[1][0]=a[0][0]+a[1][0];
    REP(i,n){
        if(i>0&&i<n){
            b[0][i]=b[0][i-1]+a[0][i];   
        }
    }
    REP(i,n){
        if(i>0&&i<n){
            b[1][i]=max(b[1][i-1],b[0][i])+a[1][i];   
        }
    }
    printf("%d",b[1][n-1]);    
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		String ans ="NG";
		for(int i=A;i<=B;i++){
			if ((i%K)==0){
				ans="OK";
			}
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 35708
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 5e5+10;

int k,m,n;
char s[maxn];
vector<int> a[maxn];
int ans[maxn],deg[maxn];
queue<int> q;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1)+1;
	for(register int i=1;i<n;i++){
		if(s[i]=='<'){deg[i+1]++;a[i].push_back(i+1);}
		else {deg[i]++;a[i+1].push_back(i);}
	}
	for(register int i=1;i<=n;i++){
		ans[i]=0;
		if(!deg[i])q.push(i);
	}
	long long anss=0;
	while(!q.empty()){
		int x=q.front();q.pop();
		anss+=ans[x];
		for(register int i=0;i<a[x].size();i++){
			int y=a[x][i];
			ans[y]=max(ans[y],ans[x]+1);
			deg[y]--;
			if(!deg[y])q.push(y);
		}
	}
	printf("%lld\n",anss);
	return 0;
}

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

using namespace std;

const int maxn = 2e5+10;

int a[maxn];
int tem[maxn];

int main(void)
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	int k = n/2 + 1;

	for (int i = n; i >= k; i--)
		tem[i] = a[i];

	for (int i = n/2; i >= 1; i--)
	{
		bool x = 0;

		for (int j = 2*i; j <= n; j += i)
			x ^= tem[j];

		if (x != a[i]) tem[i] = 1;
		else tem[i] = 0;
	}

	int qtd = 0;
	for (int i = 1; i <= n; i++)
		if (tem[i])
			++qtd;

	printf("%d\n", qtd);
	for (int i = 1; i <= n; i++)
		if (tem[i])
			printf("%d\n", i);
}

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

int main(int argc, char const *argv[]) {
  int tmp;
  std::cin >> tmp;

  if (tmp == 25) {
    std::cout << "Christmas" << '\n';
  } else if (tmp == 24) {
    std::cout << "Christmas Eve" << '\n';
  } else if (tmp == 23) {
    std::cout << "Christmas Eve Eve" << '\n';
  } else {
    std::cout << "Christmas Eve Eve Eve" << '\n';
  }
  return 0;
}

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

using namespace std;

template <class T> class Queue
{
private:
	vector<T> q;
	int head;
	int tail;
	bool is_full;
	bool is_empty;
public:
	Queue(int n)
	{
		q.resize(n);
		head = 0;
		tail = 0;
		is_full = false;
		is_empty = true;
	}
	bool isEmpty()
	{
		return is_empty;
	}
	bool isFull()
	{
		return is_full;
	}
	void enqueue(T a)
	{
		if (this->is_full)
		{
			cout << "ERROR : Queue is full" << endl;
			return;
		}
		else if (this->is_empty)
		{
			this->is_empty = false;
		}
		if (tail == q.size() - 1)
		{
			q[tail] = a;
			tail = 0;
		}
		else
		{
			q[tail++] = a;
		}
		if (tail == head)
		{
			is_full = true;
		}
	}
	T dequeue()
	{
		T ret;
		if (this->is_empty)
		{
			cout << "ERROR : Queue is empty" << endl;
			return NULL;
		}
		else if (this->is_full)
		{
			this->is_full = false;
		}
		if (head == q.size() - 1)
		{
			ret = q[head];
			head = 0;
		}
		else
		{
			ret = q[head++];
		}
		if (tail == head)
		{
			this->is_empty = true;
		}
		return ret;
	}
};

int main()
{
	int n, q;
	cin >> n >> q;
	string name;
	int time;
	Queue<string> q_name(n);
	Queue<int> q_time(n);
	for (int i = 0; i < n; i++)
	{
		cin >> name >> time;
		q_name.enqueue(name);
		q_time.enqueue(time);
	}
 	int timestamp = 0;
	Queue<string> out_name(n);
	Queue<int> out_time(n);
	while (!q_name.isEmpty())
	{
		name = q_name.dequeue();
		time = q_time.dequeue();
		if (q >= time)
		{
			timestamp += time;
			out_name.enqueue(name);
			out_time.enqueue(timestamp);
		}
		else
		{
			timestamp += q;
			q_name.enqueue(name);
			q_time.enqueue(time - q);
		}
	}
	while (!out_name.isEmpty())
	{
		cout << out_name.dequeue() << " " << out_time.dequeue() << endl;
	}
    return 0;
}


Measured memory_bytes: 6296
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-6-3 21:04:40
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

const int MAX_SIZE = 1000010;
const long long MOD = 998244353;

long long inv[MAX_SIZE];
long long fact[MAX_SIZE];
long long factinv[MAX_SIZE];

typedef long long ll;

void init()
{
  inv[1] = 1;
  for (int i = 2; i < MAX_SIZE; i++)
  {
    inv[i] = ((MOD - inv[MOD % i]) * (MOD / i)) % MOD;
  }
  fact[0] = factinv[0] = 1;
  for (int i = 1; i < MAX_SIZE; i++)
  {
    fact[i] = (i * fact[i - 1]) % MOD;
    factinv[i] = (inv[i] * factinv[i - 1]) % MOD;
  }
}

long long C(int n, int k)
{
  if (n >= 0 && k >= 0 && n - k >= 0)
  {
    return ((fact[n] * factinv[k]) % MOD * factinv[n - k]) % MOD;
  }
  return 0;
}

long long power(long long x, long long n)
{
  if (n == 0)
  {
    return 1;
  }
  else if (n % 2 == 1)
  {
    return (x * power(x, n - 1)) % MOD;
  }
  else
  {
    long long half = power(x, n / 2);
    return (half * half) % MOD;
  }
}

long long gcm(long long a, long long b)
{
  if (a < b)
  {
    return gcm(b, a);
  }
  if (b == 0)
    return a;
  return gcm(b, a % b);
}

ll N, A, B, K;

ll calc(ll k, ll l)
{
  return (C(N, k) * C(N, l)) % MOD;
}

int main()
{
  init();
  cin >> N >> A >> B >> K;
  ll g = gcm(A, B);
  if (K % g != 0)
  {
    cout << 0 << endl;
    return 0;
  }
  A /= g;
  B /= g;
  K /= g;
  ll ans = 0;
  for (ll k = 0; k <= N; k++)
  {
    ll BL = K - A * k;
    if (BL % B == 0)
    {
      ll l = BL / B;
      if (0 <= l && l <= N)
      {
        ans += calc(k, l);
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 23680
#include<iostream>
int main() {
	int len;
	std::cin >> len;
	int * arr = new int[len];
	for (int i = 0; i < len; i++)
		std::cin >> arr[i];
	int max=arr[1]-arr[0], min=arr[0];
	for (int i = 0; i < len-1; i++) {
		min = arr[i] < min ? arr[i] : min;
		max = max > arr[i+1] - min ? max : arr[i+1] - min;

	}
	std::cout << max<<std::endl;
	return 0;
}


Measured memory_bytes: 3880
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] v = sc.nextIntArray(n);
    int[] c = sc.nextIntArray(n);

    int[] values = new int[n];
    for (int i = 0; i < n; i++) values[i] = v[i] - c[i];
    Set<Integer> dp = new HashSet<>();
    Set<Integer> ndp = new HashSet<>();
    dp.add(0);
    for (int i = 0; i < n; i++) {
      ndp.clear();
      for (int val : dp) {
        ndp.add(val);
        ndp.add(val + values[i]);
      }
      dp.clear();
      dp.addAll(ndp);
    }
    int max = Integer.MIN_VALUE;
    for (int val : dp) max = Math.max(max, val);
    System.out.println(max);
  }
}

Measured memory_bytes: 21332
#include<iostream>
using namespace std;
int main(){
	bool toN[200000];
	int fromW[200000];
	int N=0;
	int M=0;
	int count=0;
	cin>>N>>M;
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		if(a==1){
			fromW[count]=b;
			count++;
		}else if(b==N){
			toN[a]=true;
		}
	}
	for(int i=0;i<count;i++){
		if(toN[fromW[i]]){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;

  set<int> water;
  rep(i,31) {
    rep(j,31) {
      int weight = (i*a + j*b) * 100;
      if (weight > f) break;
      water.insert(weight);
    }
  }
  water.erase(0);

  set<int> sugar;
  rep(i,3001) {
    rep(j,3001) {
      int weight = i*c + j*d;
      if (weight > f) break;
      sugar.insert(weight);
    }
  }

  int mass = a*100, melt = 0;
  for (auto w : water) {
    for (auto s : sugar) {
      if (w + s > f || s > w/100 * e) break;

      if (s == w/100 * e) {
        cout << w + s << ' ' << s << endl;
        return 0;
      }

      if (s * mass > (w + s) * melt) {
        mass = w + s;
        melt = s;
      }
    }
  }

  cout << mass << ' ' << melt << endl;
  return 0;
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] ={ 1,0,-1,0 };
int dy[4] ={ 0,1,0,-1 };

//UnionFind木(サイズ有り)
struct UnionFind{
private:
	vector<int> par;
	vector<int> siz;
public:
	void init(int N){ //初期化する O(N)
		par.clear();
		siz.clear();
		for(int i=0; i<N; i++) par.push_back(i);
		for(int i=0; i<N; i++) siz.push_back(1);
	}
	int root(int a){ //親を返す O(α(N))
		if(par[a] == a) return a;
		return par[a] = root(par[a]);
	}
	void unite(int a, int b){ //木を併合する O(α(N))
		int rootA = root(a);
		int rootB = root(b);
		if(rootA == rootB) return;
		if(siz[rootA] < siz[rootB]) swap(rootA, rootB);
		par[rootB] = rootA;
		siz[rootA] += siz[rootB];
	}
	bool same(int a, int b){ //属する木が同じかを返す O(α(N))
		return root(a) == root(b);
	}
	int size(int a){ //その素集合の要素数を返す O(α(N))
		return siz[root(a)];
	}
};

int N;
const int M = 100000;
int x[100000], y[100000];
vector<int> zaatuX, zaatuY;
vector<int> X[100000], Y[100000];
UnionFind uf;
set<int> xx[100000], yy[100000];

signed main() {
	cin >> N;
	rep(i, N){
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
		zaatuX.pb(x[i]);
		zaatuY.pb(y[i]);
	}
	sort(zaatuX.begin(), zaatuX.end());
	zaatuX.erase(unique(zaatuX.begin(), zaatuX.end()), zaatuX.end());
	sort(zaatuY.begin(), zaatuY.end());
	zaatuY.erase(unique(zaatuY.begin(), zaatuY.end()), zaatuY.end());
	rep(i, N){
		x[i] = lower_bound(zaatuX.begin(), zaatuX.end(), x[i]) - zaatuX.begin();
		y[i] = lower_bound(zaatuY.begin(), zaatuY.end(), y[i]) - zaatuY.begin();
	}

	rep(i, N){
		X[x[i]].pb(i);
		Y[y[i]].pb(i);
	}
	uf.init(N);
	rep(i, M){
		rep(j, X[i].size()){
			if(j == 0) continue;
			uf.unite(X[i][j-1], X[i][j]);
		}
		rep(j, Y[i].size()){
			if(j == 0) continue;
			uf.unite(Y[i][j-1], Y[i][j]);
		}
	}

	rep(i, N){
		xx[uf.root(i)].insert(x[i]);
		yy[uf.root(i)].insert(y[i]);
	}
	ll ans = 0;
	rep(i, N){
		if(uf.root(i) != i) continue;
		ans += (ll)xx[i].size() * yy[i].size();
	}
	cout << ans - N << endl;
}


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

const int M = 1e5 + 100;
int n, a, b, c;
string s[M];
char ans[M];

void dfs(int i, int a, int b, int c) {
	if (i == n) {
		cout << "Yes" << "\n";
		for (int i = 0; i < n; i++) cout << ans[i] << "\n";
		exit(0);
	}
	if (s[i] == "AB") {
		if (a) ans[i] = 'B', dfs(i + 1, a - 1, b + 1, c);
		if (b) ans[i] = 'A', dfs(i + 1, a + 1, b - 1, c);
	}
	if (s[i] == "BC") {
		if (b) ans[i] = 'C', dfs(i + 1, a, b - 1, c + 1);
		if (c) ans[i] = 'B', dfs(i + 1, a, b + 1, c - 1);
	}
	if (s[i] == "AC"){
		if (a) ans[i] = 'C', dfs(i + 1, a - 1, b, c + 1);
		if (c) ans[i] = 'A', dfs(i + 1, a + 1, b, c - 1);
	}
}

int main() {
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) cin >> s[i];
	dfs(0, a, b, c);
	cout << "No";
}

Measured memory_bytes: 16240
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<unordered_map>
using namespace std;

int main()
{   
    long long N;
    long long K;
    cin >> N >> K;
    
    long long A[N];
    for(long long i=0; i<N; i++){
        cin >> A[i];
    }
    
    bool visit[N];
    for(long long i=0; i<N; i++){
        visit[i] = false;
    }
    long long M = 0;
    long long start = 1;
    while(!visit[start-1]){
        visit[start-1] = true;
        start = A[start-1];
        M++;
    }
    long long loop = start;
    
    // independent
    start = 1;
    long long m = 0;
    while(start != loop){
        start = A[start-1];
        m++;
    }
    
    if(K < M){
        start = 1;   
        for(long long i=0; i<K; i++){
            start = A[start-1];
        }
    }else{
        K = (K-m)%(M-m);

        start = 1;   
        for(long long i=0; i<m+K; i++){
            start = A[start-1];
        }
    }
    cout << start << endl;
}


Measured memory_bytes: 5408
h,w,a,b = (int(i) for i in input().split())
mod,n,ans = 10**9+7,h+w-2,0
fn,fk = [1]*n,[1]*n
for i in range(n-1): fn[i+1] = (fn[i]*(i+2))%mod
def power(n,k):
	if k==1: return n
	elif k%2==0: return power((n**2)%mod,k//2)
	else: return (n*power(n,k-1))%mod
def comb(n,k):
	if n==0 or k==0 or n==k: return 1
	else: return (((fn[n-1]*fk[n-k-1])%mod)*fk[k-1])%mod
fk[-1] = power(fn[-1],mod-2)
for i in range(2,n+1): fk[-i] = (fk[-i+1]*(n+2-i))%mod
for i in range(h-a): ans = (ans+comb(h+w-b-i-2,h-i-1)*comb(b+i-1,i))%mod
print(ans)

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

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int i, j, k;
	int si, ti, size, slen, tlen;
	vector< vector<int> > table(30);
	unsigned long ans = 0;

	slen = s.length();
	tlen = t.length();

	for (i = 0; i < tlen; i++) {
		if (s.find(t[i])==string::npos) {
			cout<<-1<<endl;
			return 0;
		}
	}

	for (i = 0; i < slen; i++) {
		table[s[i] - 'a'].push_back(i);
	}

	ti = 0;
	si = -1;
	vector<int>::iterator it;
	while (ti<tlen) {

		si++;

		size = table[t[ti] - 'a'].size();
		it = lower_bound(table[t[ti] - 'a'].begin(), table[t[ti] - 'a'].end(), si);
		if (it == table[t[ti] - 'a'].end()) {
			ans += (slen - si + 1) + (*table[t[ti] - 'a'].begin());
			si = (*table[t[ti] - 'a'].begin());
		}
		else {
			ans += (*it) - si + 1;
			si = (*it);
		}

//		cout << "si / ti / ans = " << si << " / " << ti << " / "<<ans<< endl;

		ti++;

		/*
		while (1) {
			si = (si + 1) % slen;
			ans = (unsigned long)ans + 1;
			if (t[ti] == s[si])break;
		}
		ti++;
		*/

	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1344
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n,m,ans,count;
    cin >> n >> m;
    ll a[n],b[n],c[m],d[m];
    rep(i, n)cin >> a[i] >> b[i];
    rep(i, m)cin >> c[i] >> d[i];
    rep(i, n){
        count = abs(a[i] - c[0]) + abs(b[i] - d[0]);
        ans = 1;
        rep(j, m){
            if ((abs(a[i] - c[j]) + abs(b[i] - d[j])) < count) {
                ans = j + 1;
                count = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k=0;
    cin>>n;
    for(i=105; i<=n; i+=2)
    {
        int c=0;
        for(j=1; j<=n; j++)
        {
            if(i%j==0)
            {
                c++;
            }
        }
        if(c>=8)
            k++;
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db 				double
#define ll 				long long int
//#define ld				long long double
//#define int 			long long int
#define ull 			unsigned long long
#define fi 				first
#define se 				second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl 			'\n'
#define mem(a,b) 		memset(a, b, sizeof a)
#define mkp 			make_pair
#define pb 				push_back
#define max3(a,b,c) 	max(a,max(b,c))
#define min3(a,b,c) 	min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)			a.begin(), a.end()
#define sz(a)           int((a).size())
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); it++)
using namespace std;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
const db PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =			0.000001;
ll mod       =			(1e9+7);   //998244353
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=200001;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}
//DSU Implementation
void init(int idx[], int sz[],int n){
	rep(i,0,n) idx[i]=-1, sz[i]=1;
}
int root(int index, int idx[]){
	while(index!=idx[index]){
		index=idx[index];
	}
	return index;
}
bool qfind(int p, int q, int idx[]){
	return root(p,idx)==root(q,idx);
}
void qunion(int p, int q, int idx[], ll sz[]){
	int rootp=root(p,idx), rootq=root(q,idx);
	if(rootp==rootq) return;
	idx[rootq]=rootp;
	sz[rootp]+=sz[rootq];
}


int main(){	
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	int d=n%10;
	if(d==2 || d==4 || d==5 || d==7 || d==9) cout<<"hon"<<endl;
	else if(d==0 || d==1 || d==6 || d==8) cout<<"pon"<<endl;
	else cout<<"bon"<<endl;
	return 0;
    }

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main(){
	int i,x[10000],j;
	for(i=1;i<=10000;i++){
	cin>>x[i];
	if(x[i]==0){
	break;
	}
	}
	for(j=1;j<i;j++){
	cout<<"Case "<<j<<": "<<x[j]<<endl;
	}
return 0;
}


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

using namespace std;

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

    vector<int> v(n);
    for(int i=0; i<n; i++){
        if(i) v[i] = v[i-1];
        if(s[i] == 'E') v[i]++;
    }

    int ans = 1e9;
    for(int i=0; i<n; i++){
        int tmp = 0;
        if(i) tmp += i - v[i-1];
        tmp += v[n-1] - v[i];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1796
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <queue>
#include <vector>

#define testin freopen("1.txt","r",stdin);
#define testout freopen("out.txt","w",stdout);
#define ll long long

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}


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

int main() {
    int n,k;
    cin >> n >> k;
    int x = 1;
    //operate n times, add k;
    for(int i = 0; i < n; i++){
        if(x < k) x *= 2;
        else x += k;
    }
    cout << x;
}


Measured memory_bytes: 256
import sys

INF = float('inf')

n, ma, mb = map(int, sys.stdin.readline().split())
abc = map(int, sys.stdin.read().split())
abc = list(zip(*[abc] * 3))

def main():
    sa = 0
    sb = 0
    for i in range(n):
        sa += abc[i][0]
        sb += abc[i][1]

    res = [[INF] * (sb + 1) for _ in range(sa + 1)]
    res[0][0] = 0

    for a, b, c in abc:

        for j in range(sa, -1, -1):
            for k in range(sb, -1, -1):
                if j >= a and k >= b:
                    res[j][k] = min(res[j][k], res[j-a][k-b] + c)

    ans = INF
    for i in range(1, min(sa//ma, sb//mb) + 1):
        ans = min(ans, res[ma*i][mb*i])

    if ans == INF:
        return -1
    else:
        return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, M, C;
int B[30], A[30][30];

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

    std::cin >> N >> M >> C;

    for(int i=0;i<M;++i){
        std::cin >> B[i];
    }
    
    int cnt = 0;

    for(int i=0;i<N;++i){
        int sum = C;

        for(int j=0;j<M;++j){
            std::cin >> A[i][j];

            sum += A[i][j] * B[j];
        }

        if(sum > 0){
            cnt += 1;
        }
    }

    std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
from math import sqrt

def cal_factors(num):
    factors = {}
    i = 0
    while True:
        d, q = divmod(num, 2)
        if q == 0:
            num = d
            i += 1
            factors[2] = i
        else:
            break

    maxmod = int(sqrt(num)) + 1
    for mod in range(3, maxmod, 2):
        i = 0
        while True:
            d, q = divmod(num, mod)
            if q == 0:
                num = d
                i += 1
                factors[mod] = i
            else:
                break

    if num > 1:
        factors[num] = 1

    return factors


def comb(n, r, mod):
    result = 1
    r = min(r, n-r)
    for i in range(n, n-r, -1):
        result *= i
    for i in range(2, r+1):
        result //= i
    result %= mod

    return result


n, m = [int(v) for v in input().split()]

mod = 1000000000 + 7
factors = cal_factors(m)
ans = 1
for v in factors.values():
    ans *= comb(v + n - 1, v, mod)
    ans %= mod

print(ans)

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

typedef long long ll;
typedef long double ld;

ld dp[3005];
ld dpp[3005];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin >> n;
    dpp[0] = dp[0] = 1;
    for(int i=1; i<=n; i++){
        ld x;
        cin >> x;
        for(int j=1; j<=i; j++){
            dp[j] = dpp[j-1]*x + dpp[j]*(1-x);
        }
        dp[0] = dpp[0]*(1-x);
        for(int j=0; j<=i; j++) dpp[j] = dp[j];
    }
    ld pr = 0;
    for(int i=n/2+1; i<=n; i++){
        pr += dp[i];
    }
    cout << pr;
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var sLine = Console.ReadLine().Split(' ');
			var T = int.Parse(sLine[0]);
			var A = int.Parse(sLine[1]);
			double result = double.MaxValue;
			int result2 = 0;
			var tLine = Console.ReadLine().Split(' ');
			for (int i = 0; i < N; i++)
			{
				var temp = int.Parse(tLine[i]);
				var tmp2 = T - temp * 0.006;
				if (result > Math.Abs(tmp2 - A))
				{
					result = Math.Abs(tmp2 - A);
					result2 = i;
				}
			}
			Console.Write((result2 + 1).ToString());


		}
	}
}


Measured memory_bytes: 13204
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

ll modadd(ll a,ll b,ll mod=MOD){
    return (a%mod+b%mod)%mod;
}

ll modsub(ll a,ll b,ll mod=MOD){
    a%=mod;
    b%=mod;
    if(a>=b) return a-b;
    else return mod-b+a;
}

ll modmul(ll a,ll b,ll mod=MOD){
    return ((a%mod)*(b%mod))%mod;
}

ll modpow(ll a, ll n,ll mod=MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll moddiv(ll a,ll b,ll mod=MOD) {
    return modmul(a, modpow(b, mod-2));
}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,K;
    cin>>N>>K;
    
    ll ans=0;
    for(ll i=K;i<=N+1;i++){
        ll a=moddiv(modmul(i,i-1),2);
        ll b=moddiv(modmul(modsub(modadd(modmul(2,N),1),i),i),2);
        //printf("i=%d,,,%d,%d\n",i,a,b);
        ans=modadd(ans,modsub(b,modsub(a,1)));
    }
    cout<<ans<<endl;
    
    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	int rate[9] = { 1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200 };
	int color[9] = {};
	for (int i = 0; i < N; i++) {
		int buf;
		cin >> buf;
		for (int j = 0; j < 8; j++) {
			if ((rate[j] <= buf) && (buf < rate[j + 1])) {
				color[j]++;
			}
		}
		if (rate[8] <= buf) {
			color[8]++;
		}
	}
	int min = 0;
	int max;
	for (int i = 0; i < 8; i++) {
		if (color[i] != 0) min++;
	}

	if (min == 0) {
		min = 1;
		max = color[8];
	} else {
		max = min + color[8];
	}
	cout << min << " " << max << endl;
        return 0;
}


Measured memory_bytes: 256
//*******************************By Harry Singh From Phillaur.
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000006
const ll mo=1000000007;
#define string_to_any_base(s,base) stoll(s, 0, base);
#define vc vector
// #define mp map<ll,ll> mp;
#define bt(M,value) bitset<M> b(value)
#define S set<ll> s;
#define pb push_back
#define ST set<string> s;
#define INF 1e15
using namespace std;
set<ll> primes;
vector<pair<ll,ll>> adj[MAX];
vector<ll> ad[MAX];
typedef pair<int,int> ip;
///******************************ALL important functions;
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);} 
ll lcm(ll a, ll b)  {  return (a*b)/gcd(a, b);  } 
void Sieve(){ bool prime[MAX+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=MAX; p++) { if (prime[p] == true) {for (int i=p*p; i<=MAX; i += p) prime[i] = false; } } for(int i=2;i<=MAX;i++)if(prime[i]==true)primes.insert(i);} 
ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;}
ll modpow(ll a, ll n=mo-2) {ll r=1;while(n)r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;return r;}
int visited[MAX]={0};
void dfs(int u)
{
	visited[u]=true;
	for(auto s:ad[u])
	if(!visited[s])dfs(s);
}

int main()
{
int n,k;;cin>>n>>k;
if(k>(((n-1)*(n-2))/2))
cout<<"-1\n";
else
{	vc<ip> v;
	for(int i=2;i<=n;i++)
	v.pb({1,i});
	int left=(((n-1)*(n-2))/2)-k;
	for(int i=2;i<=n-1;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(left==0)goto m;
			v.pb({i,j}),--left;
		}
	}
	m:
	cout<<v.size()<<"\n";
	for(auto s:v)cout<<s.first<<" "<<s.second<<"\n";
	
}
}


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

int main() {
    int N,K;
    string S;
    cin >> N;
    cin>> S;
    cin>> K;
    char tmp=S[K-1];
    for(int i=0;i<N;i++){
        if(S[i]!=tmp) S[i]='*';
    }
    cout << S <<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    s = input()
    ans = 'Yes'
    
    for i in range(len(s)):
        if i % 2 == 0 and bool(s[i] not in {'R', 'U', 'D'}):
            ans = 'No'
            break
        elif i % 2 == 1 and bool(s[i] not in {'L', 'U', 'D'}):
            ans = 'No'
            break
    
    print(ans)

main()


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int ans = (N + K - 3) / (K - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
"use strict";
 
var main = function main(input) {
  var N = parseInt(input.split("\n")[0], 10);
  var d = input.split("\n").slice(1, input.split("\n").length - 1).filter(function (elem, idx, self) {
    return self.indexOf(elem) === idx;
  });
  console.log(d.length);
};
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int func(int n){
  if( n%2 != 0 ){
    return 0;
  }
  return 1 + func(n/2);
}

int main() {
  int n;
  cin >> n;
  int ans=1,mx_cnt=0;
  for(int i=1;i<=n;i++){
    if( mx_cnt < func(i) ){ //func は２で割れる回数を返す
      mx_cnt = func(i);
      ans = i;
    }
  }
  
  cout << ans << endl;
    
      
    
  return 0;
  
}

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

using namespace std;
int n;
int main()
{
    cin>>n;
    int sum=0;
    int x=n;
    while(true)
    {
        if(x==0)break;
        sum+=x%10;
        x=x/10;

    }
    if(n%sum==0)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
#define NIL -1
typedef struct t {
    int p;
    int l;
    int r;
}tree;
void inorder(int);
void preorder(int);
void postorder(int);
tree T[MAX];
int main() {

    int n, k, i, j, id, root;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].p = -1;
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &id);
        scanf("%d", &T[id].l);
        T[T[id].l].p = id;
        scanf("%d", &T[id].r);
        T[T[id].r].p = id;
    }
    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) {
            root = i;
            break;
        }
    }
    printf("Preorder\n");
    preorder(root);
    printf("\n");
    printf("Inorder\n");
    inorder(root);
    printf("\n");
    printf("Postorder\n");
    postorder(root);
    printf("\n");
    return 0;
}

void inorder(int z) {
    if (z == NIL) return;
    if (T[z].l != NIL) {
        inorder(T[z].l);
    }
    printf(" %d", z);
    if (T[z].r != NIL) {
        inorder(T[z].r);
    }
}
void preorder(int z) {
    if (z == NIL) return;
    printf(" %d", z);
    if (T[z].l != NIL) {
        preorder(T[z].l);
    }
    if (T[z].r != NIL) {
        preorder(T[z].r);
    }
}
void postorder(int z) {
    if (z == NIL) return;
    if (T[z].l != NIL) {
        postorder(T[z].l);
    }
    if (T[z].r != NIL) {
        postorder(T[z].r);
    }
    printf(" %d", z);
}


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

long long int A, B, C, D, E, F, G;

int main(){
    scanf("%lld%lld%lld%lld%lld", &A, &B, &C, &D, &E);
    if(A + B < 2 * C){
        cout << D * A + E * B << endl;
        return 0;
    }
    G = min(D, E);
    F = 2 * C * G;
    D -= G;
    E -= G;
    F += min(D * A + E * B, 2 * C * (D + E));
    cout << F << endl;
    return 0;
}

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

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

    ll n;
    cin >> n;
    double p = 0;
    REP(i, n){
        if(i % 2 == 0) p += 1;
    }
    double res = double(p / n);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, a, b;
  cin >> x >> a >> b;
  vector<int> count(2);
  if (x < a) {
    count[0] = a - x;
  }
  else {
    count[0] = x - a;
  }
  if (x < b) {
    count[1] = b - x;
  }
  else {
    count[1] = x - b;
  }
  if (count[0] < count[1]) {
    cout << "A" << endl;
  }
  else {
    cout << "B" << endl;
  }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const ll p=1000000007;
int main(){
  int n;
  cin >> n;
  ll u[n][11];
  ll f[n][10];
  rep(i,n){
    rep(j,10){
      cin >> f[i][j];
    }
  }
  rep(i,n){
    rep(j,11){
      cin >> u[i][j];
    }
  }
  ll ans=-1000000000000000;
  rep(i,(1<<10)){
    if(i==0)continue;
    ll a=0;
    rep(j,n){
      int m=0;
      rep(l,10){
        if(i&(1<<l)){
          m+=f[j][l];
        }
      }
      a=a+u[j][m];
    }
    ans=max(ans,a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin>>N;
  VEC<int>P(N);
  REP(i,0,N)cin>>P[i];
  auto Q = P;
  sort(ALL(Q));
  // DUMP(P);
  // DUMP(Q);
  int diff = 0;
  REP(i,0,N){
    if(P[i]!=Q[i])diff++;
  }
  if(diff<=2){
    cout<<"YES"<<endl;
  }else cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{

 int A, B;

 scanf("%d %d", &A, &B);

 if (A==1 && B==2){
    printf("3");
 }
 else if (A==2 && B==3){
    printf("1");
 }
 else if (A==1 && B==3) {
    printf("2");
 }
 else if (A==3 && B==1) {
    printf("2");
 }
else if (A==3 && B==2){
    printf("1");
 }
 else {
    printf("3");
 }
  return 0;

}

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

using namespace std;

int main() {

    int n;
    cin >> n;

    long long ans = 0;

    for (long long i = 1; i <= n; ++i) {
        if(i % 3 == 0 or i % 5 == 0) {}
        else {
            ans += i;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	int N, i, ans = 0;
	char temp = 0;
	char *S;
	scanf("%d", &N);
	S = (char *)malloc(sizeof(char) * (N+1));
	scanf("%s", S);
	for(i = 0; i < N; i++)
		if(temp != S[i])
		{
			temp = S[i];
			ans++;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vector<double> A;
	double hei=0;
	for(int i=0;i<N;i++){
		double a;
		cin>>a;
		A.pb(a);
		hei+=a;
	}
	hei/=N;
	double a=INF,b=INF;
	for(int i=N-1;i>=0;i--){
		if(a>=abs(hei-A[i])){
			a=abs(hei-A[i]);
			b=i;
		}
	}
	cout<<b<<endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	char s[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}

	int num[26] = {};
	for (int i = 0; i < n; i++) {
		num[s[i] - 'A']++;
	}

	int count = 0;
	for (int i = 0; i < 26; i++) {
		if (0 < num[i]) {
			count++;
		}
	}
	string ans;
	if (3 == count) {
		ans = "Three";
	} else {
		ans = "Four";
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
	//入力
	int N, M, X;
	cin >> N >> M >> X;

	//料金所
	int A[100], i, cnt = 0;
	for (int i = 0; i < N+1; i++) A[i] = 0;

	while (cnt < M) {
		cin >> i;
		A[i] = 1;
		cnt++;
	}

	int sum1, sum2;
	sum1 = sum2 = 0;
	for (int j = X; j < N+1; j++) sum1 += A[j];
	for (int j = X; j > 0; j--) sum2 += A[j];

	if (sum1 > sum2) cout << sum2 << endl;
	else cout << sum1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1e9+7)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

vector<ll> dijkstra(ll s, vector<vector<pll>>& cost_map){
    vector<ll> d(cost_map.size(), MAXINF);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.push(pll(0, s));
    d[s] = 0;
    while(!q.empty()){
        pll f = q.top();q.pop();
        if(d[f.se] < f.fi) continue;
        for(auto&& v : cost_map[f.se]){
            ll value = f.fi + v.se;
            if(value < d[v.fi]) {
                d[v.fi] = value;
                q.push(pll(value, v.fi));
            }
        }
    }
    return d;
}

int main(void)
{
    ll n,m;
    cin >> n >> m;
    ll s,t;
    cin >> s >> t;
    s--;t--;

    vector<vector<pll>>Y(n);
    vector<vector<pll>>S(n);
    REP(i, m){
        ll u,v;
        cin >> u >> v;
        ll a,b;
        cin >> a >> b;
        u--;v--;
        Y[u].pb(make_pair(v, a));
        Y[v].pb(make_pair(u, a));
        S[u].pb(make_pair(v, b));
        S[v].pb(make_pair(u, b));
    }

    auto yen = dijkstra(s, Y);
    auto snk = dijkstra(t, S);

    vector<ll> ans(n+1,MAXINF);
    RREP(i, n){
        ans[i]=min(ans[i+1], yen[i] + snk[i]);
    }

    // DEBUG_VEC(yen);
    // DEBUG_VEC(snk);
    // DEBUG_VEC(ans);

    REP(i, n){
        pr(1'000'000'000'000'000 - ans[i]);
    }
}

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

int main(void)
{
	while (1) {
		int n, r;
		cin >> n >> r;
		if (n == 0) {
			break;
		}
		vector<int> dekki(n);
		for (int i = n; i >= 1; --i) {
			dekki[n - i] = i;
		}
		for (int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;
			vector<int> vec(p + c);
			for (int j = p - 1; j < p + c - 1; ++j) {
				vec[j - p + 1] = dekki[j];
			} 
			for (int j = 0; j < p - 1; ++j) {
				vec[c + j] = dekki[j];
			}

			for (int j = 0; j < p + c - 1; ++j) {
				dekki[j] = vec[j];
			}
		}

		cout << dekki[0] << endl;
	}

	return 0;
}


Measured memory_bytes: 3100