akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    while (n > 0) {
        int t = n % 10;
        if (t == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 3668
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		long ans = -a[N-1];
		for (int i = 0; i < N; i++) {
			ans += a[N - i / 2 - 1];
		}
		System.out.println(ans);
	}
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int a,b,c,d,e,f;

int main() {
    cin>>a>>b>>c>>d>>e>>f;
    vector<P> X;
    vector<P> Y;
    for (int i=0; i<f; ++i) {
        for (int j=0; j<f; ++j) {
            int x = 100 * a * i + 100 * b * j;
            if (x <= f) {
                X.push_back({i, j});
            }
        }
    }
    for (int i=0; i<f; ++i) {
        for (int j=0; j<f; ++j) {
            int y = c * i + d * j;
            if (y <= f) {
                Y.push_back({i, j});
            }
        }
    }

    int ans1=0, ans2=0;
    double best=-1;
    for (int i=0; i<X.size(); ++i) {
        for (int j=0; j<Y.size(); ++j) {
            int ai = X[i].first;
            int bi = X[i].second;
            int ci = Y[j].first;
            int di = Y[j].second;
            int x = 100 * a * ai + 100 * b * bi;
            int y = c * ci + d * di;
            int ei = x / 100;
            if (e * ei >= y and x+y <= f) {
                double tmp = (100 * 1.0 * y) / (x + y) * 100;
                if (tmp > best) {
                    best = tmp;
                    ans1 = x + y;
                    ans2 = y;
                }
            }
        }
    }
    cout << ans1 << ' ' << ans2 << endl;
}


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

typedef long long ll;

#define INF 100100100100
#define MODSIZE 1000000007


int main(){
  long long dp[100007];
  long long a[100007];
  int flag[100007];
  int i,j,k,n,m;

  scanf("%d %d", &n, &m);
  for(i = 0;i <= n;i++){
    dp[i] = 0;
    flag[i] = 0;
  }

  for(i = 0;i < m;i++){
    scanf("%lld", &a[i]);
    flag[a[i]] = 1;
  }

  dp[0] = 1;
  dp[1] = 1;

  for(i = 2;i <= n;i++){
    if(flag[i - 1] == 0) dp[i] = (dp[i - 1] + dp[i]) % MODSIZE;
    if(flag[i - 2] == 0) dp[i] = (dp[i - 2] + dp[i]) % MODSIZE;
  }

  printf("%lld\n", dp[n] % MODSIZE);
  return 0;
}

Measured memory_bytes: 2176
h = Array.new(4){ Array.new(3){ Array.new(10,0) } }          #最後の１０，０は値をすべてまずゼロにする
n = gets.to_i
n.times do
  a,b,c,d = gets.split.map(&:to_i)
  h[a-1][b-1][c-1] += d                                      #arrayは０からはじまるから？？
end

for i in 0...4                                          #４棟のことあらわすため
  puts "#"*20 if i>0
  for j in 0...3
    puts " "+h[i][j].join(" ")     
  end
end



Measured memory_bytes: 6904
//直接答えを求めるのは難しいが, 値の範囲(X以上か～）なら分かる(2分探索)
//2分探索にすると…01だけのピラミッドになる。最後まで残るのは…より真ん中にある00,11を取る。真ん中にある方が00なら0が残り,11なら1が残る。
//最も下の段が0101…になった場合は0が残り, 1010…になった場合は1が残る。
//と思うので, O(NlogN)で簡単に解ける？

#include <iostream>
#define int long long
using namespace std;

int n;
int a[200000];

bool check(int mid) {
	static int t[200000];
	int i;
	
	for (i = 0; i < 2 * n - 1; i++) { t[i] = (a[i] >= mid); }
	
	int score[2] = {1145141919, 1145141919};
	for (i = 0; i < 2 * n - 2; i++) {
		if (t[i] == 0 && t[i+1] == 0) {
			score[0] = min(score[0], min(abs(n - 1 - i), abs(n - 1 - (i+1))));
		}
		if (t[i] == 1 && t[i+1] == 1) {
			score[1] = min(score[1], min(abs(n - 1 - i), abs(n - 1 - (i+1))));
		}
	}
	
	if (score[0] == 1145141919 && score[1] == 1145141919) {
		return (t[0] == 1);
	}
	return score[1] < score[0];
}

void input() {
	cin >> n;
	for (int i = 0; i < 2 * n - 1; i++) cin >> a[i];
}

signed main() {
	input();
	
	int st = 1, ed = 2 * n - 1, mid;	//oooooxxx…, [st, ed)
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) {
			st = mid;	//[mid, ed)
		}
		else {
			ed = mid;	//[st, mid)
		}
	}
	cout << st << endl;
	return 0;
}

Measured memory_bytes: 3456
N,K = map(int, input().split())
div_cnt = 0
if K % 2 == 1:
    div_cnt = (N // K) ** 3
else:
    div_cnt1 = N // K
    div_cnt2 = 0
    for i in range(1,N+1):
        if i % K == K//2:
            div_cnt2 += 1
    div_cnt = div_cnt1 **3 + div_cnt2 ** 3
print(div_cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int h, n; cin >> h >> n;
  int i, j, z, x, s = 0;
  for (i = 0; i < n; i++) cin >> x, s += x;
  if (s >= h) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    
    d=a/b;
    r=a%b;
    f=1.0*a/b;
    
    printf("%d %d %f",d,r,f);
    return 0;
}

Measured memory_bytes: 632
// atcoder/abc044/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k, x, y;
  while (cin >> n >> k >> x >> y) {
    cout << min(k, n) * x + max(0, n - k) * y << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
h, w = gets.chomp.split(" ").map(&:to_i)
if h == 1 || w == 1
    puts 1
    exit
end

odd = (h / 2) + (h % 2)
even = h % 2 == 0 ? odd : odd - 1
ans = (odd + even) * (w / 2)
ans += odd if w % 2 != 0
puts ans

Measured memory_bytes: 3836
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 100010
using namespace std;

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n;
int g[MAXN],nume;
int dep[MAXN],pre[MAXN];
int vs[MAXN][2];
int w[MAXN],numw,pt[MAXN];
int b[MAXN],ans[MAXN];

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void dfs(int x,int p){
	pt[w[x]=++numw]=x;
	pre[x]=p;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			dep[e[i].to]=dep[x]+1;
			dfs(e[i].to,x);
		}
}

bool gao(){
	for(int i=1;i<=n;i++)
		if(b[i]!=-1){
			if((b[i]&1)^(dep[i]&1))
				for(int j=1;j<=n;j++) dep[j]++;
			for(int j=1;j<=n;j++)
				if(b[j]!=-1 && (b[j]&1)!=(dep[j]&1))
					return 0;
			break;
		}
	for(int i=1;i<=n;i++){
		vs[i][0]=-10000000+(dep[i]&1);
		vs[i][1]=10000000-(dep[i]&1);
	}
	for(int i=n;i>=1;i--){
		int x=pt[i];
		if(vs[x][0]>vs[x][1]) return 0;
		if(b[x]!=-1){
			if(b[x]<vs[x][0] || b[x]>vs[x][1]) return 0;
			vs[x][0]=vs[x][1]=b[x];
		}
		if(i>1){
			int y=pre[x];

			vs[y][0]=max(vs[y][0],vs[x][0]-1);
			vs[y][1]=min(vs[y][1],vs[x][1]+1);
		}
	}
	ans[1]=vs[1][0];
	for(int i=2;i<=n;i++){
		int x=pt[i],y=pre[pt[i]];
		if(ans[y]+1>=vs[x][0] && ans[y]+1<=vs[x][1])
			ans[x]=ans[y]+1;
		else
			ans[x]=ans[y]-1;
	}
	return 1;
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	dfs(1,0);
	int m;
	memset(b,-1,sizeof b);
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		b[x]=y;
	}
	if(!gao()){
		puts("No");
		return 0;
	}
	puts("Yes");
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
}


Measured memory_bytes: 10624
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a, b;
	scanf("%*d%d%*d%d", &a, &b);
	if (a + 1 == b) {
		printf("0\n");
	}
	else {
		printf("1\n");
	}

	Please AC;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y;
    scanf("%d",&n);
    long long ans=0;
    for(int i=1;i<=n;i++)
        ans+=1ll*(1+(n-i+1))*(n-i+1)/2;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        ans-=1ll*x*(n-y+1);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)   _for (__VA_ARGS__)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;

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

  set <ll> s;

  size_t n;
  cin >> n;

  rep (i, n)
  {
    ll x;
    cin >> x;
    s.insert (x);
  }

  auto ans = s.size () == n;
  cout << array <string, 2> {"NO", "YES"} [ans] << endl;
}


Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        boolean flag = false;
        while (N > 0) {
            int temp = N % 10;
            N /= 10;
            if (temp == 7)
                flag = true;
        }
        if (flag)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35776
#include<iostream>

using namespace std;

int main()
{
	int H;
	int W;

	// ???????????????
	while (1)
	{
		// ??\???
		cin >> H >> W;

		if (H == 0 && W == 0)
		{ // ??\?????±???0?????´??????????????????
			break;
		}

		// ????????????
		for (int cnth = 0; cnth < H; cnth++)
		{
			// #??????
			for (int cntw = 0; cntw < W; cntw++)
			{
				cout << "#";
			}

			cout << endl;
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;


int main(){
  string s;cin>>s;
  ll ans=0;
  if(s=="RRR")ans=3;
  else if(s=="RRS"||s=="SRR")ans=2;
  else if(s=="SSS")ans=0;
  else ans=1;
  cout<<ans<<endl;

}





Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1000000007
#define ll long long int
#define fio ios_base::sync_with_stdio(0);cin.tie(0)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define slld(t) scanf("%lld",&t)
#define plld(t) printf("%lld\n",t)
#define sc(t) scanf("%c",&t)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define clr(x) memset(x,0,sizeof(x))
#define rep(i,begin,end) for(__typeof(end) i=begin-(begin>end);i!=end-(begin>end);i+=1-2*(begin>end))
using namespace std;

int main()
{
	int n,ans=0; sd(n);
	int a[2*n];
	rep(i,0,2*n) sd(a[i]);
	sort(a,a+2*n);
	for(int i=0; i<2*n; i+=2) ans+=a[i];
	pd(ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
#include <stdio.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)
#pragma GCC optimize("Ofast")



int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll aa, bb, cc, dd;
	aa = a * c;
	bb = b * c;
	cc = a * d;
	dd = b * d;
	cout << max(aa, max(bb, max(cc, dd))) << endl;
	return 0;
}


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

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

using namespace std;

int main(){
	int a,b; cin>>a>>b;
	set<int> S={1,2,3};
	S.erase(a);
	S.erase(b);
	cout<<*S.begin()<<'\n';
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
Ans = []
for p in P:
    Ans.append((p, 1))
for q in Q:
    Ans.append((q, 2))
for r in R:
    Ans.append((r, 3))
Ans.sort(reverse=True)

x = 0
y = 0
num = 0
ans = 0

for i, j in Ans:
    if j == 1:
        if x == X:
            continue
        else:
            x += 1
            num += 1
            ans += i
    elif j == 2:
        if y == Y:
            continue
        else:
            y += 1
            num += 1
            ans += i
    else:
        num += 1
        ans += i
    if num == X+Y:
        break
print(ans)


Measured memory_bytes: 81224
#include <bits/stdc++.h>
//#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PR pair<int, int>
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int N,M;
  cin >> N >> M;
  vector<int> P(M);
  vector<int> Y(M);
  vector<vector<int>> prefs(N + 1);
  rep(i,M)
  {
    cin >> P[i] >> Y[i];
    prefs[P[i]].push_back(Y[i]);
  }
  rep(i,N+1)
  {
    sort(ALL(prefs[i]));
  }
  rep(i,M)
  {
    int num = lower_bound(ALL(prefs[P[i]]),Y[i]) - prefs[P[i]].begin()+1;
    printf("%06d%06d\n",P[i],num);
  }
  
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

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

    int m = n.length();

    string s = "0";
    s += n;

    for (int i = m; i > 0; i--) {
        int d = s[i] - '0';
        if (d > 5 || (d == 5 && (s[i - 1] - '0' > 4))) {
            s[i] = '0';
            if (s[i - 1] == '9') continue;
            s[i - 1] = (s[i - 1] - '0') + 1 + '0';
        }
    }

    int ans = 0;
    rep(i, 0, s.length()) ans += (s[i] - '0');

    rep(i, 0, m) {
        int a = n[i] - '0', b = s[i + 1] - '0';
        if (a > b) ans += 9 - a;
        else if (b > a) ans += b - a;
    }

    ans += s[0] - '0';
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2308
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	cal = collections.Counter(al)
	q = int(input())
	s = sum(al)
	for _ in range(q):
		b, c = tin()
		if b in cal:
			s += (c-b)*cal[b]
			if c in cal:
				cal[c] += cal[b]
			else:
				cal[c] = cal[b]
			cal[b]=0
			
		else:
			pass
		
		print(s)
		
		
		
		
		
		
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 94316
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  cout<<(n+1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  ll N, K; cin >> N >> K;
  if(K > (N-1)*(N-2)/2){
    cout << -1 << endl;
    return 0;
  }

  vector<pair<ll, ll> > edge;
  bool flg2 = false;
  ll cnt = 0;
  if(K>0){
  FOR(i, 1, N-1){
    FOR(j, i+1, N){
      edge.push_back({i, j});
      cnt++;
      if(cnt == K) flg2 = true;
      if(flg2) break;
    }
    if(flg2) break;
  }}

  cout << N*(N-1)/2 -K << endl;
  FOR(i, 1, N) {
    FOR(j, i+1, N+1){
      bool flg = false;
      REP(k, edge.size()){
        if(edge[k].first == i && edge[k].second == j){
          flg = true; 
          break;
        }
      }
      if(flg) continue;
      printf("%lld %lld\n", i, j);
    }
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c, n;
    int ans = 0;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            ans += v[i]*v[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
#define fs first
#define sc second
typedef pair<ll, ll> P;

const ll INF = 1LL << 50;

P unite(P a, P b){
    return P(max(a.fs, b.fs), min(a.sc, b.sc));
}

int main(){
    int N;
    cin >> N;
    P p[N];
    ll lmax = 0;
    int ind = -1;
    for(int i = 0; i < N; i++){
        cin >> p[i].fs >> p[i].sc;
        if(lmax < p[i].sc - p[i].fs + 1){
            lmax = p[i].sc - p[i].fs + 1;
            ind = i;
        }
    }

    P tmp = P(-INF, INF);
    for(int i = 0; i < N; i++){
        if(i != ind){
            tmp = unite(tmp, p[i]);
        }
    }

    sort(p, p + N);

    P a[N];
    a[0] = P(p[0].fs, p[0].sc);
    for(int i = 1; i < N; i++){
        a[i].fs = p[i].fs;
        a[i].sc = min(a[i - 1].sc, p[i].sc);
    }

    P b[N];
    b[N - 1] = P(p[N - 1].fs, p[N - 1].sc);
    for(int i = N - 2; i >= 0; i--){
        b[i].fs = b[i + 1].fs;
        b[i].sc = min(b[i + 1].sc, p[i].sc);
    }

    ll ans = lmax + max(0LL, tmp.sc - tmp.fs + 1);
    for(int i = 1; i < N; i++){
        ll lena = max(0LL, a[i - 1].sc - a[i - 1].fs + 1);
        ll lenb = max(0LL, b[i].sc - b[i].fs + 1);

        ans = max(ans, lena + lenb);
    }

    //debug
    /*
    cout << "a" << endl;
    for(int i = 0; i < N; i++){
        cout << a[i].fs << " " << a[i].sc << endl;
    }

    cout << "b" << endl;
    for(int i = 0; i < N; i++){
        cout << b[i].fs << " " << b[i].sc << endl;
    }
    */

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

Measured memory_bytes: 5504
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>

using namespace std;

int main() {

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

	a = n / 100;
	b = n / 10-a*10;

	c = n % 10;

	if (a == 7 || b == 7 || c == 7) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=505;
int a[MAXN][MAXN],n;
LL f[MAXN][MAXN],g[MAXN],s1[MAXN][MAXN],s2[MAXN][MAXN];
int s[MAXN];
int main()
{
//	freopen("d.in","r",stdin);
//	freopen("d.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i!=j)a[i][j]=read();
	
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)s1[i][j]=s1[i][j-1]+a[i][j];
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)s2[j][i]=s2[j][i-1]+a[i][j];
	memset(f,63,sizeof(f));LL INF=f[0][0];
	for(int i=1;i<n;i++)
	{
		f[i][0]=0;
		for(int j=1;j<=i;j++)f[i][0]+=s1[j][i]-s1[j][j];
	}
	for(int i=1;i<n;i++)for(int j=0;j<i;j++)if(f[i][j]!=INF)
	{
		LL sum=0;
		for(int k=i+1;k<=n;k++)
		{
			sum+=s2[k][k]-s2[k][i]+s1[k][j];
			f[k][i]=min(f[k][i],f[i][j]+sum);
		}
	}
	LL ans=(1LL<<63-1);
	for(int i=0;i<n;i++)ans=min(ans,f[n][i]);
	pr2(ans);
	return 0;
}


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

long long On[55][55],Off[55][55],Con[55][55];
int R,C,M;
char G[55][55];
long long T[55][55],res,cT;
int move[4][2]={-1,0,0,1,1,0,0,-1};
bool vst[55][55];
pair <int,int> Task[1005];

bool in(int r,int c)
{
	if(r<0||c<0||r>=R||c>=C)
		return false;
	return true;
}

void update(int x,int y,long long t)
{
	if(!T[x][y]) res+=On[x][y];
	else res+=min(On[x][y]+Off[x][y],Con[x][y]*(t-T[x][y]));
	T[x][y]=t;
}

bool dfs(int cX,int cY,int eX,int eY,long long t)
{
	vst[cX][cY]=true;
	if(cX==eX&&cY==eY)
	{
		cT=t;
		return true;
	}
	for(int i=0;i<4;i++)
	{
		int nX=cX+move[i][0],nY=cY+move[i][1];
		if(!in(nX,nY)) continue;
		if(G[nX][nY]=='#') continue;
		if(vst[nX][nY]) continue;
		if(dfs(nX,nY,eX,eY,t+1))
		{
			update(cX,cY,t);
			return true;
		}
	}
	return false;
}

void solve()
{
	memset(T,0,sizeof(T));
	cT=1,res=0;
	for(int i=0;i<M-1;i++)
	{
		memset(vst,0,sizeof(vst));
		dfs(Task[i].first,Task[i].second,Task[i+1].first,Task[i+1].second,cT);
	}
	update(Task[M-1].first,Task[M-1].second,cT);
	for(int i=0;i<R;i++)
		for(int j=0;j<C;j++)
			if(T[i][j]>0) res+=Off[i][j];
}

int main()
{
	while(scanf("%d%d%d",&R,&C,&M)!=EOF)
	{
		for(int i=0;i<R;i++) scanf("%s",G[i]);
		for(int i=0;i<R;i++)
			for(int j=0;j<C;j++)
				scanf("%lld",&Con[i][j]);
		for(int i=0;i<R;i++)
			for(int j=0;j<C;j++)
				scanf("%lld",&On[i][j]);
		for(int i=0;i<R;i++)
			for(int j=0;j<C;j++)
				scanf("%lld",&Off[i][j]);
		for(int i=0;i<M;i++) scanf("%d%d",&Task[i].first,&Task[i].second);
		solve();
		printf("%lld\n",res);
	}
	return 0;
}

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

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

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

    int N;
    cin >> N;
    vector<int> A(N);
    ll tot = 1;
    ll odd = 1;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        tot *= 3;
        if (A[i] % 2 == 0) {
            odd *= 2;
        }
    }
    cout << tot - odd << endl;


    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //diverta2019c
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int a = 0, b = 0, c = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            char[] s = in.ns().toCharArray();
            if(s[0]=='B'&&s[s.length-1]=='A') c++;
            else if(s[0]=='B') b++;
            else if(s[s.length-1]=='A') a++;
            for (int j = 1; j < s.length; j++) {
                if(s[j]=='B'&&s[j-1]=='A') ans++;
            }
        }
        if(c>0){
            ans += c-1;
            if(a>0||b>0){
                ans += 1;
                ans += Math.min(a, b);
            }
        }else{
            ans += Math.min(a,b);
        }
        out.println(ans);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

int main()
{
  int N;
  cin>> N;
  string S;
  int a=0,b=0,c=0,d=0;
  for( int i=0;i<N;i++)
  {
    cin>>S;
    
  	if(S == "P")
    { a=1;
    }
    if(S == "W")
    { b=1;
    }
    if(S == "G")
    { c=1;
    }
    if(S == "Y")
    { d=1;
    }
  }
  if( a == b && b== c && c == d)
    {cout<< "Four" <<endl;}
  else
  {cout<< "Three"<<endl;}
}


Measured memory_bytes: 3604
from collections import defaultdict
import sys
n=int(input())
a=list(map(int,sys.stdin.read().split()))
a.sort()
curc=0
cntc=0
ans=0
for aa in a:
  if aa == curc:
    cntc+=1
  else:
    curc=aa
    ans+=cntc%2
    cntc=1
ans+=cntc%2
print(ans)


Measured memory_bytes: 20664
#include <stdio.h>
#include <stdlib.h>
#define N 8
#define FREE 0
#define NOT_FREE 1

int row[N],col[N],dpos[N*3],dneg[N*3]; //すべてFREEの状態
int row2[N];

int putQueen(int );
void printBord(void );

int main(){
  int i,j;
  int k,r,c;

  scanf("%d",&k);

  for(i=0;i<N;i++) row2[i] = -1;
  for(i=0;i<k;i++){
    scanf("%d%d" ,&r ,&c );
  row[r]  = c;
  col[c] = NOT_FREE;
  dpos[r+c] = NOT_FREE;
  dneg[r-c+N-1] = NOT_FREE;
  row2[r] = c;
  }

  putQueen(0);
  //printBord();
  
  return 0;
}

int putQueen(int i){

  int j;
  // printBord();
  // printf("\n");
  if( i == N ){
    printBord();
    return 0;
    //exit(3);
  }




    if(row2[i] != -1 ){
      putQueen(i+1);
      return 0;     
    }
  
  for(j=0;j<=N-1;j++){
    // printf("i=%d j=%d, row2[%d] = %d\n", i, j, i, row2[i]);
    //	printf("%d %d %d\n", col[j], dpos[i+j], dneg[i-j+N-1]);
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      continue;
    }





    

    /*
    if(row2[i] == 1 ){
      if(putQueen(i+1))return 1;
      return 2;
    }
    */

    
    //put a queen at(i,j)
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;

    //try the next row 
    putQueen(i+1);
    
    //remove the queen at (i,j) for backtracking
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }  

  return 0;
}

void printBord(){

  //チェス板を出力
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(j == row[i])printf("Q");
      else printf(".");
    }
    printf("\n");
  }

}



Measured memory_bytes: 2104
//おまじない
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int n,m;
  cin>>n>>m;
  
  vector<long int> v(m);
  
  for(int i=0; i<n; i++){
    
    int f=0;
    cin>>f;
    
    for(int j=0; j<f; j++){
      int a=0;
      cin>>a;
      v.at(a-1)+=1;}
  }
  int s=0;
  for(int i=0;i<m;i++){
    if(v.at(i)==n){
      s++;}}
  
  cout<<s<<endl;
}
  

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

int main(){
	int n,q,s[10000];

	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> s[i];
		for(int j = 0; j < i; j++){
			if(s[i] == s[j]) s[i] = -1;
		}
	}

	cin >> q;

	int ret, count = 0;
	for(int i = 0; i < q; i++){
		cin >> ret;
		for(int j = 0; j < n; j++){
			if(ret == s[j]){	count++; break;	}
		}
	}

	cout << count;
	cout << endl;
}

Measured memory_bytes: 1196
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	int mn = min({ A,B,C,D,E });
	int ans = (N + mn - 1) / mn + 4;
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
 
struct Data{
  int num,id;
  char ch;
};
 
int Partition(Data A[],int p,int r){
  Data x = A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j].num<=x.num){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}
 
void Quicksort(Data A[],int p,int r){
  if(p<r){
    int q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}
 
void check(Data A[],int n){
  for(int i=1;i<n;i++){
    if(A[i-1].num<A[i].num)continue;
    if(A[i-1].id<A[i].id)continue;
    cout<<"Not stable"<<endl;
    return;
  }
  cout<<"Stable"<<endl;
}
 
int main(){
  int n;
  Data A[100000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i].ch>>A[i].num;
    A[i].id=i;
  }
   
  Quicksort(A,0,n-1);
  check(A,n); 
  for(int i=0;i<n;i++){
    cout<<A[i].ch<<' '<<A[i].num<<endl;
  }
   
  return 0;
}


Measured memory_bytes: 4208
#pragma GCC optimize ("O2") // "Ofast" for REAL FAST
// #pragma GCC optimization ("unroll-loops")

// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#include <bits/stdc++.h>
#define DEBUG 1

using namespace std;

#define rep(i, a, b) for (i = (a); i < (b); i++)
#define trav(a, x) for (auto & a : x)
#define all(x) (x).begin (), (x).end ()
#define rall(x) (x).rbegin (), (x).rend ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair <int, int> pii;
#define f first
#define s second
#define mp(x, y) make_pair (x, y)

typedef vector <int> vi;
#define pb(x) push_back (x)

#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x3f3f3f3f3f3f3f3f;
const int  INFi  =  0x3f3f3f3f;
const ll   MAXN  =  1e+6+7; // UPDATE

int main ()
{
    FASTIO;
    int i, j;
    int N, a;
    scanf ("%d", &N);
    for (i = j = 0; i < N; i++)
    {
        scanf ("%d", &a);
        if (a == j + 1)
            j++;
    }
    if (j == 0)
        printf ("-1\n");
    else
        printf ("%d\n", i - j);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	scanf("%d",&N);
	{
		double T,A;
		double t;
		scanf("%lf%lf",&T,&A);
		int ans = 0;
		double MIN = 1e6+10;
		int pos;
		for(int i = 0 ; i < N ; i++)
		{
			scanf("%lf",&t);
			t = T - t * 0.006;
			if(abs(A-t) < MIN)
			{
				pos = i+1;
				MIN = abs(A-t);
			}
		}
		cout<<pos<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd(int x, int y){
    return y ? gcd(y, x % y) : x;
}

int main(){
    int N, X, D;
    int x[100000] = {};

    cin >> N >> X;
    for(int i = 0; i < N; i++){
        cin >> x[i];
        x[i] -= X;
    }

    D = x[0];

    for(int i = 0; i < N; i++){
        D = gcd(D, x[i]);
    }

    if(D < 0)
        D *= -1;

    cout << D;

    return 0;
}








Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const int MOD = 1e9 + 7;
class Modint {
public:
	long long val;

	Modint (long long _val = 0)
		: val((_val + MOD) % MOD) {}

	Modint operator+ (Modint other) {
		return Modint(val + other.val);
	}

	void operator+= (Modint other) {
		val += other.val;
		val %= MOD;
	}

	Modint operator- () {
		return Modint(MOD - val);
	}

	Modint operator- (Modint other) {
		return Modint(val + MOD - other.val);
	}

	void operator-= (Modint other) {
		val += MOD - other.val;
		val %= MOD;
	}

	Modint operator* (Modint other) {
		return Modint(val * other.val);
	}

	void operator*= (Modint other) {
		val *= other.val;
		val %= MOD;
	}

	bool operator== (Modint other) {
		return val == other.val;
	}

	bool operator!= (Modint other) {
		return val != other.val;
	}
};

Modint exp (Modint a, int k) {
	if (k == 0) {
		return Modint(1);
	} else if (k % 2 == 0) {
		Modint half = exp(a, k / 2);
		return half * half;
	} else {
		return a * exp(a, k - 1);
	}
}

Modint inv (Modint a) {
	return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
	out << p.val;
	return out;
}


int main() {

	int n, m; cin >> n >> m;
	vector<bool> broken(n + 1, false);
	for (int i = 1; i <= m; i++) {
		int a; cin >> a;
		broken[a] = true;
	}

	vector<Modint> dp(n + 1, 0);
	dp[0] = 1, dp[1] = (broken[1] == false);

	for (int i = 2; i <= n; i++) {
		if (broken[i]) continue;
		dp[i] = dp[i - 1] + dp[i - 2];
	}

	cout << dp[n];


	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  char b;
  cin >> b;

  if(b == 'A'){
    cout << 'T' << endl;
  }
  else if(b == 'T'){
    cout << 'A' << endl;
  }
  else if(b == 'G'){
    cout << 'C' << endl;
  }
  else{
    cout << 'G' << endl;
  }

  return 0;
}


Measured memory_bytes: 632
class Vertex:
    _id = -1
    _children = []
    _visited = False
    _visited_time = 0
    _all_visited_time = 0

    def __init__(self, i, c):
        self._id = i
        self._children = c

    def getId(self):
        return self._id

    def getChildren(self):
        return self._children

    def isVisited(self):
        return self._visited

    def getVisitedTime(self):
        return self._visited_time

    def setVisitedTime(self, t):
        self._visited_time = t
        self._visited = True

    def getAllVisitedTime(self):
        return self._all_visited_time

    def setAllVisitedTime(self, t):
        self._all_visited_time = t

    def print(self):
        print("{} {} {}".format(self._id, self._visited_time, self._all_visited_time))


n = int(input())
graph = [0 for i in range(n)]
time = 0

# 頂点登録
for i in range(n):
    u = list(map(int, input().split(' ')))
    adj = []
    if u[1] > 0:
        adj = u[2:u[1]+2]
    graph[u[0]-1] = Vertex(u[0], adj)

# DFS
def dfs(v):
    global time
    time += 1
    v.setVisitedTime(time)
    for child in v.getChildren():
        if not graph[child-1].isVisited():
            dfs(graph[child-1])
    time += 1
    v.setAllVisitedTime(time)

# DFS実行
for v in graph:
    if not v.isVisited():
        dfs(v)

# 回答を出力
for v in graph:
    v.print()


Measured memory_bytes: 5708
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

bool isp[11111];

int main(){
    int N=11111;
    for(int i=0;i<N;i++)isp[i]=true;
    isp[0]=isp[1]=false;
    for(int i=2;i<N;i++){
        if(!isp[i])continue;
        for(int j=i+i;j<N;j+=i)isp[j]=false;
    }

    int n;
    while(cin>>n && n){
        int c=0;
        for(int i=1;i<=n;i++)if(isp[i]&&isp[n-i+1])c++;
        cout << c << endl;
    }
}

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

using namespace std;
using ll = long long;

int main() {
	int n;
	ll d;
	scanf("%d %lld", &n, &d);
	d *= d;

	int ans = 0;
	while(n--) {
		ll x, y;
		scanf("%lld %lld", &x, &y);
		ans += x * x + y * y <= d;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 200100

ll n;
string s;
ll dp[MAX][4];

ll f(ll index,ll prev){
	if(n==index) return 0;
	if(n-index==1){
		if(prev!=1) return 1;
		else{
			if(s[n-1]==s[n-2]) return -1e18;
			else return 1;
		}
	}

	if(prev!=-1 && dp[index][prev]!=-1) return dp[index][prev];

	string c = "";
	ll i = index-prev;
	For(count,0,prev){
		if(i<0) continue;
		c.pb(s[i++]);
	}

	ll t1 = 0 , t2 = 0;
	string current = "";
	current.pb(s[index]);
	if(current!=c) t1 = f(index+1,1)+1;
	current.pb(s[index+1]);
	if(current!=c) t2 = f(index+2,2)+1;

	if(prev!=-1) dp[index][prev]=max(t1,t2);

	return max(t1,t2);

}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin>>s;
	n = s.size();	
	
	cout<<f(0,-1)<<endl;






























	
}

Measured memory_bytes: 48916
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> a(n), b(n);
        for(auto& i: a) cin >> i;
        for(auto& i: b) cin >> i;
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
//         for(auto& i: a) cout<<" "<<i;cout<<endl;
//         for(auto& i: b) cout<<" "<<i;cout<<endl;

        int answer = -1;
        for(int i = 1; i < n; ++i) {
            int lowest = a[n - i];
            auto it = upper_bound(b.end() - i, b.end(), lowest - 1);
            int d = it - b.begin() - (n - i);
//             cout << d << endl;
//             cout << n-i<<endl;
//             cout<<"+"<<*it<<endl;
            if(it - (b.end() - i) > i / 2) {
                answer = i;
                break;
            }
        }
        if(answer == -1) cout << "NA" << endl;
        else cout << answer << endl;
    }
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  ll K, N, max_distance = 0;
  cin >> K >> N;
  vector<int> A(N);
  REP(i, N) { cin >> A[i]; }
  sort(ALL(A));
  REP(i, N - 1) {
    if (max_distance < A[i + 1] - A[i]) {
      max_distance = A[i + 1] - A[i];
    }
  }
  if (max_distance < K - A[N - 1] + A[0]) {
    max_distance = K - A[N - 1] + A[0];
  }
  cout << K - max_distance << endl;
}

signed main() {
  solve();

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A + B > C + D){
    cout << "Left" <<endl;
}
  else if(A + B == C + D ){
    cout << "Balanced" <<endl;
  }
  else{
    cout<< "Right" <<endl;
  }
}

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

int main() {
    int n;cin>>n;
    string s;cin>>s;
    int ans=1;
    for (int i=1;i<n;i++)
        if (s[i]!=s[i-1])
            ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512