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

using namespace std;

using ll = long long;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, s;
	cin >> n >> s;
	if (n < s) {
		cout << -1 << endl;
		return 0;
	}
	for (ll b = 2; b * b <= n; b++) {
		ll t = n, sum = 0;
		while (t > 0) {
			sum += t % b;
			t /= b;
		}
		if (sum == s) {
			cout << b << endl;
			return 0;
		}
	}

	ll b = (n == s ? n + 1 : -1);
	for (ll p = 1; p * p < n; p++) {
		ll q = s - p;
		if (q < 0) break;
		if (q > n) continue;
		ll t;
		if ((n - q) % p == 0) t = (n - q) / p;
		if (t > q && t > 1 && n / t + n % t == s) b = t;
	}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
t = input()
len = len(t)

for i in range(len):
    if t[i] == "?":
        print("D", end = "")
    else:
        print(t[i], end = "")


Measured memory_bytes: 9268
s1 = input().split()
s2 = input().split()

N = int(s1[0])
M = int(s1[1])
list_of_A = s2
for i in range(0,len(list_of_A)):
    list_of_A[i] = int(list_of_A[i])

daysTotal = 0
for i in range(0,len(list_of_A)):
    daysTotal += list_of_A[i]

if daysTotal > N :
    print(-1)
else:
    print(N-daysTotal)


Measured memory_bytes: 9388
// https://atcoder.jp/contests/abc151/tasks/abc151_f
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

// https://kmjp.hatenablog.jp/entry/2020/01/13/1030
int N;
int X[51], Y[51];

double ret;

void hoge(double x, double y) {
    double r = 0;
    REP(i, N) r = max(r, hypot(X[i] - x, Y[i] - y));
    ret = min(ret, r);
}

void solve() {
    cin >> N;
    REP(i, N) cin >> X[i] >> Y[i];
    ret = 1e9;

    REP(z, N) REP(y, z) {
        // 2点間の中心からの距離最大値で更新
        double rx = (X[y] + X[z]) * 0.5;
        double ry = (Y[y] + Y[z]) * 0.5;
        hoge(rx, ry);

        // 3点を頂点とする三角形の外心からの距離最大値で更新
        REP(x, y) {
            double a = hypot(X[y] - X[z], Y[y] - Y[z]);
            double b = hypot(X[z] - X[x], Y[z] - Y[x]);
            double c = hypot(X[x] - X[y], Y[x] - Y[y]);

            if (abs(a + b - c) < 1e-9)
                continue;
            if (abs(a + c - b) < 1e-9)
                continue;
            if (abs(c + b - a) < 1e-9)
                continue;

            double rx = (a * a * (b * b + c * c - a * a) * X[x] +
                         b * b * (a * a + c * c - b * b) * X[y] +
                         c * c * (b * b + a * a - c * c) * X[z]) /
                        (a * a * (b * b + c * c - a * a) +
                         b * b * (a * a + c * c - b * b) +
                         c * c * (b * b + a * a - c * c));
            double ry = (a * a * (b * b + c * c - a * a) * Y[x] +
                         b * b * (a * a + c * c - b * b) * Y[y] +
                         c * c * (b * b + a * a - c * c) * Y[z]) /
                        (a * a * (b * b + c * c - a * a) +
                         b * b * (a * a + c * c - b * b) +
                         c * c * (b * b + a * a - c * c));
            hoge(rx, ry);
        }
    }
    cout << fixed << setprecision(12) << ret << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

using namespace std;

#define int long long

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

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int x, t;

signed main(){
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin>>x>>t;
  
  int r = x-t;
  if(r<0)r=0;
  
  cout<<r<<endl;
  
  
  return 0;
}


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

struct D {
  int i;
  int p;
  int y;
  int c;
};

constexpr int MAX_M = 100000;
D d[MAX_M];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i{}; i < M; ++i) {
    d[i].i = i + 1;
    cin >> d[i].p >> d[i].y;
  }
  sort(d, d + M, [](D l, D r) {
    if (l.p == r.p)
      return l.y < r.y;
    return l.p < r.p;
  });

  int p{};
  int counter{};
  for (int i{}; i < M; ++i) {
    if (p != d[i].p) {
      p = d[i].p;
      counter = 0;
    }
    d[i].c = ++counter;
  }
  sort(d, d + M, [](D l, D r) {
    return l.i < r.i;
  });

  cout << setfill('0');
  for (int i{}; i < M; ++i) {
    cout << setw(6) << d[i].p << setw(6) << d[i].c << endl;
  }

  return 0;
}


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

#define all(x) x.begin(),x.end()
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

template<typename T>
void chmin(T& a, T b){if(a>b)a=b;}

template<typename T>
void chmax(T& a, T b){if(b>a)a=b;}

int cnt[MAXN];

int main(){
    int n=read();
    for(int i=1;i<n;++i){
        int x=read();
        ++cnt[x];
    }

    for(int i=1;i<=n;++i)cout<<cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 4300
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define yes "Yes"
#define no  "No"

int main(){
    int n,m,k;
    std::cin >> n >> m >> k;

    rep(i,n+1) rep(j,m+1){
        if(i*j+(n-i)*(m-j)==k){
            std::cout << yes << "\n";
            return 0;
        }
    }

    std::cout << no << "\n";
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef pair<string,int> Pair;
int main(){

	int n; cin >> n;
	int q; cin >> q;
	queue<Pair> Q;
	int sum_time=0;

	for(int i=0; i<n; i++){
		string s; int time;
		cin >> s >> time;
		Q.push(Pair(s,time));
	}

	while(!Q.empty()){
		Pair p = Q.front();
		Q.pop();
		if(p.second<=q){
			sum_time += p.second;
			cout << p.first << " " << sum_time << endl;
		}
		else{
			sum_time += q;
			Q.push(Pair(p.first, p.second - q));
		}
	}
	return 0;
}

Measured memory_bytes: 6336
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;


int main() {
	int n, x;
	int sum = 0;
	int rem = 0;


	cin >> n >> x;
	vector<int>m(n);
	for (int i = 0; i < n; i++)cin >> m[i];

	for (int i = 0; i < n; i++) {
		sum += m[i];
	}
	sort(m.begin(), m.end());
	cout << n+(x - sum) / m[0];
	 
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			str = br.readLine();
			String[] a = str.split(" ", 0);
			long[] n = new long[N];
			long total = 0;
			for(int i = 0; i< N; i++) {
				n[i] = Long.parseLong(a[i]);
				total += n[i];
			}
			int i = 0;
			long sunuke = 0;
			long comp = 0;
			while(i < N - 1) {
				sunuke += n[i];
				total -= n[i];
				if(i == 0) {
					comp = Math.abs(total - sunuke);
				}else if(comp > Math.abs(total - sunuke)) {
					comp = Math.abs(total - sunuke);
				}
				i++;
			}
			System.out.println(comp);

		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 50040
from math import log2
n = int(input())
r,ans = int(log2(n)),[]
for i in range(1,r+1): ans.append([i,i+1,2**(i-1)])
for i in range(r,0,-1):
	if n-2**(i-1)>=2**r:
		ans.append([i,r+1,n-2**(i-1)])
		n-=2**(i-1)
print(r+1,len(ans)+r)
for i in range(1,r+1): print(i,i+1,0)
for i,j,k in ans: print(i,j,k)

Measured memory_bytes: 3064
n,k=map(int,input().split())
dlist=[[]for i in range(k+1)]
mod = 10**9+7
num=[0]*(k+1)
idx=0
for i in range(1,k+1):
    num[i]=pow(k//i,n,mod)
    for p in range(i*2,k+1,i):
        dlist[p].append(i)
for i in range(k,0,-1):
    for d in dlist[i]:
        num[d]=(num[d]-num[i])%mod
print(sum([i*x for i,x in enumerate(num)])%mod)

Measured memory_bytes: 101140
h, w = map(int, input().split())
min_diff = float('inf')
for i in range(1, h + 1):
    sa = i * w
    sb = (h - i) * (w // 2)
    sc = (h - i) * (w - (w // 2))
    min_diff = min(min_diff, max(sa, sb, sc) - min(sa, sb, sc))
    sb = (h - i) // 2 * w
    sc = (h - i - (h - i) // 2) * w
    min_diff = min(min_diff, max(sa, sb, sc) - min(sa, sb, sc))
h, w = w, h
for i in range(1, h + 1):
    sa = i * w
    sb = (h - i) * (w // 2)
    sc = (h - i) * (w - (w // 2))
    min_diff = min(min_diff, max(sa, sb, sc) - min(sa, sb, sc))
    sb = (h - i) // 2 * w
    sc = (h - i - (h - i) // 2) * w
    min_diff = min(min_diff, max(sa, sb, sc) - min(sa, sb, sc))
print(min_diff)

Measured memory_bytes: 42864
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<climits>
#include<complex>
#define sz(x) (int)((x).size())
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define clr(x) memset((x),0,sizeof(x))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
double rate=0.6214462166714;
double dp[111][111][111];
double ans[111];
int main()
{
	int i,j,k,n;
	n=80;
	memset(dp,0,sizeof(dp));
		dp[1][1][1]=1;
		for (i=1;i<=n;i++)
		{
			for (j=0;j<=n;j++)
			{
				for (k=1;k<=n;k++)
				{
					double p=pow(0.5,j*1.0);
					dp[i+1][j+1][k+1]+=dp[i][j][k]*p;
					dp[i+1][0][k]+=dp[i][j][k]*(1-p);
				}
			}
		}
		n=80;
		double a8=0;
		for (i=1;i<=n;i++)
			{
				double pp=0;
				for (j=0;j<=n;j++)
				{
					pp+=dp[n][j][i];
				}
				a8+=i*1.0*pp;
			}
			
	while (scanf("%d",&n)!=EOF,n)
	{
		double e=0;
		if (n<=80)
		{
			for (i=1;i<=n;i++)
			{
				double pp=0;
				for (j=0;j<=n;j++)
				{
					pp+=dp[n][j][i];
				}
				e+=i*1.0*pp;
			}
			printf("%.10lf\n",e);
		}
		else 
		{
			printf("%.10lf\n",(n-80)*1.0*rate+a8);
		}
	}
	//for (i=2;i<=80;i++)
	{
		//printf("%.18lf\n",ans[i]-ans[i-1]);
	}
	return 0;
}
/*
100
62.4160404584
99
61.7945942417
*/

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int a, b, c, d, e, f;
int sugar = 0;
double res = 0;
P ans;
int main(){
  cin >> a >> b >> c >> d >> e >> f;
  
  rep(i, 31){
    rep(j, 16){
      if((a*i+b*j)*100> f) break;
      for(int k = 0;k <= 3000; k++){
        for(int l = 0; l<=1500; l++){
          sugar = k*c + l*d;
          if(sugar > (a*i+b*j)*e) break;
          double p = sugar, q = (a*i+b*j);
          if(sugar <= (a*i+b*j)*e && 100*p/(100*q+p) > res && (a*i+b*j)*100+sugar <= f){
            ans = P((a*i+b*j)*100+sugar, sugar);
            res = 100*p/(100*q+p);
          }
        }
      }
    }
  }
  if(res==0){
    cout << a*100 << " " << 0 <<endl;
    return 0;
  }
  cout << ans.first <<" " << ans.second <<endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int K = sc.nextInt();
    char[] c = S.toCharArray();
    
    for (int i = 0; i < N; i++) {
      if (S.charAt(i) != S.charAt(K - 1)){
        c[i] = '*';
      }
    }
    for (int i = 0; i < N; i++){
      System.out.print(c[i]);
	}
  }
}

Measured memory_bytes: 35828
import numpy as np
N, X, Y = [int(_) for _ in input().split()]
X -= 1
Y -= 1
cnt = np.zeros(N, dtype=int)
for i in range(0, (X + Y) // 2):
    #t-i<=abs(i-X)+1+Y-t
    #2*t<=abs(i-X)+1+Y+i
    #t<= tmax = 0 - - (abs(i-X)+1+Y+i)//2
    #tmin=abs(i-X)+1
    tmin = abs(i - X) + 1
    tmax = 0 - -(abs(i - X) + 1 + Y + i) // 2
    cnt[1:tmax - i] += 1
    cnt[tmin:tmin + Y - tmax + 1] += 1
    cnt[tmin + 1:tmin + N - Y] += 1
for i in range((X + Y) // 2, N):
    cnt[1:N - i] += 1
print(*cnt[1:], sep='\n')


Measured memory_bytes: 27268
if __name__ == "__main__":
    s = input()

    ans = 0
    g_count = 0
    p_count = 0
    for i in range(len(s)):
        if g_count >= p_count + 1 and s[i] is 'g':
            p_count += 1
            ans += 1
        elif s[i] is 'g':
            g_count += 1
        elif g_count >= p_count + 1 and s[i] is 'p':
            p_count += 1
        else:
            g_count += 1
            ans -= 1

    print(ans)


Measured memory_bytes: 3316
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    string s;
    cin>>n;
    cin>>s;
    cin>>k;
    
    char m=s[k-1];
    for (int i=0; i<n; i++){
        if(s[i]!=m) s[i]='*';
    }
    
    cout<<s<<endl;
}

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

struct City {
  int index;
  int P;
  int Y;
  int id_suffix;
};

int main() {
  int N, M, i;
  cin >> N >> M;

  int P_i, Y_i;
  City cities[M];
  for (i = 0; i < M; i++) {
    cin >> cities[i].P >> cities[i].Y;
    cities[i].index = i;
  }
  sort(cities, cities + M, [](const City &x, const City &y) {
    return x.P == y.P ? x.Y < y.Y : x.P < y.P;
    // 同じ県が一箇所にまとまって、年度が早いものから並ぶ。
  });
  int prefP = -1, prefCount = 0;
  for (i = 0; i < M; i++) {
    if (prefP == cities[i].P)
      prefCount++;
    else {
      prefCount = 0;
      prefP = cities[i].P;
    }
    cities[i].id_suffix = prefCount;
  }
  sort(cities, cities + M,
       [](const City &x, const City &y) { return x.index < y.index; });
  for (auto i = 0; i < M; i++) {
    cout << setfill('0') << setw(6) << right << cities[i].P << setfill('0')
         << setw(6) << right << cities[i].id_suffix + 1 << endl;
  }
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int total[n], less[n];
    int h[n];
    for (auto &hi:h) cin >> hi;
    fill(total, total+n, 0);
    fill(less, less+n, 0);
    for (int i=0, ai, bi; i<m; i++) {
        cin >> ai >> bi;
        ai --; bi--;
        total[ai]++; total[bi]++;
        if (h[ai] > h[bi]) {
            less[ai]++;
        }
        if (h[ai] < h[bi]) {
            less[bi]++;
        }
    }
    int ans = 0;
    for (int i=0; i<n; i++) {
        if (less[i] == total[i]) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4812
import java.util.*;
 
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if((a*b) % 2 == 0)
      System.out.println("Even");
    else
      System.out.println("Odd");
  }
}

Measured memory_bytes: 23764
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[100010];
constexpr ll MOD = (ll)(1e9 + 7);
constexpr ll INF = 1145141919810;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0; i <= n; i++)
        dp[i] = INF;

    dp[0] = 1;
    for(int i = 0; i < m; i++){
        int k;
        scanf("%d",&k);
        dp[k] = 0;
    }
    for(int i = 1; i <= n; i++){
        if(dp[i] == 0)
        continue;
        dp[i] = dp[i - 1];
        if(i > 1)
        dp[i] = dp[i - 2] + dp[i - 1];
        dp[i] %= MOD;
    }
    printf("%lld\n",dp[n]);
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    bool flag[1001001]; // A_iの中に自分を割り切る数が存在すればfalse
    Fill(flag,true);
    int N; cin >> N;
    int A[200200];
    int cnt[1001001];
    Fill(cnt ,0);
    rep(i,N){
        cin >> A[i];
        cnt[A[i]]++;
    }
    rep(i,N){
        if(flag[A[i]] == false) continue;

        if(cnt[A[i]] > 1) flag[A[i]] = false; // 同じ数が2回以上登場すると割り切れるのでfalse
        for(int j=A[i]*2;j<=1000000;j+=A[i]) flag[j] = false; // A[i]のA[i]自身を除く倍数は全てfalse
    }

    int ans = 0;
    rep(i,N){
        if(flag[A[i]] == true) ans++;
    }
    cout << ans << enld;
    return 0;
}

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

using namespace std;

int dp[100100100][2]; 
int INF = 1001001001;
 
int main(int argc, char *argv[]) {
    string s;
    cin >> s;
    // 91 --> 19
    reverse(s.begin(), s.end()); 
    // 19 --> 190 (091 is the original value)
    //s += "0";

    //init
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<2; j++){
            dp[i][j] = INF;
        } 
    }
    dp[0][0] = 0;

    for(int i=0; i<s.size(); i++){
        //char no keisan.s
        int current_num = s[i]- '0';
        // kuriagaranai baai
        dp[i+1][0] = min( dp[i][0] + current_num, dp[i][1] + current_num + 1);
        // kuriagaruabai baai(oturi + atarasii sautno 1)
        dp[i+1][1] = min( dp[i][0]+ 10-current_num, dp[i][1]+ 10-(current_num+1) );
    }

    cout << min(dp[s.size()][0], dp[s.size()][1]+1) << endl;
 }

Measured memory_bytes: 9476
from collections import Counter
def main():
    N = int(input())
    S = []
    for n in range(N):
        S.append(input())
    cmc = Counter(S).most_common()
    nmax = cmc[0][1]
    mc_words = sorted([cmc[i][0] for i in range(len(cmc)) if cmc[i][1] == nmax])
    for w in mc_words:
        print(w)

main()

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

int main() {
  int n, sum = 0;
  cin >> n;
  char before = '0';
  
  for(int i = 0; i < n; i++) {
    char ch;
    cin >> ch;
    if(ch != before) {
      sum++;
      before = ch;
    }
  }
  
  cout << sum << endl;
}

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

int main() {
    int a, b;
    string s, t, u;
    
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    
    if(s == u) cout << a-1 << " " << b << endl;
    else if(t == u) cout << a << " " << b-1 << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
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++)
const int INF = 1<<28;

int main() {
	int N, W;
	cin >> N >> W;

	int dp[N+1][W+1];
	memset(dp, 0, sizeof(dp));

	FOR(i, 1, N+1) {
		pair<int, int> pii;
		cin >> pii.first >> pii.second;
		FOR(j, 1, W+1) {
			if(j >= pii.second)
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-pii.second] + pii.first);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
/*
	REP(i, N+1) {
		REP(j, W+1)
			cout << dp[i][j] << ' ';
		cout << endl;
	}
*/
	cout << dp[N][W] << endl;
	return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};
 int main(){
  ll n,m ;cin>>n>>m ;
  vector<ll> A(n) ;
  rep(i,n) {
    ll a ;
    cin>>A[i] ;
    A[i]-- ;
  }
  UnionFind uf(n) ;
  rep(i,m){
     ll a,b ;
     cin>>a>>b ;
     a--;b--;
     uf.unite(a,b) ;
  } 
   ll ans=0 ;
   rep(i,n){
      if(uf.same(A[i],i)) ans++ ;
   }
   cout<<ans<<endl ;
   return 0;
  }

Measured memory_bytes: 1408
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;
#define pb push_back
const int ha=1e9+7,maxn=305;
inline void ADD(int &x,int y){ x+=y; if(x>=ha) x-=ha;}
int f[maxn][maxn][maxn],n,m,k,L,R,ans;
vector<int> g[maxn][4];

inline void update(int p){
	for(int i=1;i<=3;i++)
	    for(int j=g[p][i].size()-1,l;j>=0;j--){
	    	l=g[p][i][j];
	    	
	    	for(int a=0;a<=p;a++)
	    	    for(int b=0;b<=p;b++)
	    	        for(int c=(a<p&&b<p)?p:0;c<=p;c++)
	    	            if((a>=l)+(b>=l)+(c>=l)!=i) f[a][b][c]=0;
		}
}

inline void dp(){
	f[0][0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<i;j++)
		    for(int l=0,now;l<i;l++)
		        for(int u=(j<i-1&&l<i-1)?i-1:0;u<i;u++){
		        	now=f[j][l][u];
		        	ADD(f[i][l][u],now);
		        	ADD(f[j][i][u],now);
		        	ADD(f[j][l][i],now);
				}
		
		update(i);
	}
	
	for(int j=0;j<=n;j++)
	    for(int l=0;l<=n;l++)
	        for(int u=(j<n&&l<n)?n:0;u<=n;u++) ADD(ans,f[j][l][u]);
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&L,&R,&k);
		g[R][k].pb(L);
	}
	
	dp();
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 110848
#include <iostream>
using namespace std;
void printArray(const int *A, int N){
    for(int i=0; i<N-1; i++){
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl;
}

void bubbleSort(int *A, int N){
  int flag = 1;
  int count = 0;
  while(flag == 1){
    flag = 0;
    for(int j=N-1; j>0; j--){
      if(A[j] < A[j-1]){
        int temp = A[j];
        A[j] = A[j-1];
        A[j-1] = temp;
        flag = 1;
        count ++;
      }
    }
  }
  printArray(A, N);
  cout << count << endl;
}

int main(){
    int x;
    cin >> x;
    int* A = new int[x];
    for(int i=0; i<x; i++){
        cin >> A[i];
    }
    bubbleSort(A, x);
    delete A;
}


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

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

ll lcm(ll a, ll b) {
    ll g = gcd(a,b);
    return a/g*b;
}

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

    ll ans=1LL, T;
    for (int i = 0; i < n; i++) {
        cin >> T;
        ans = lcm(ans, T);
    }

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

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

int main() {
    int a;
    cin >> a;
    string s;
    cin >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}

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

using namespace std;

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

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

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

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

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

	cout << (c <= a + b ? "Yes" : "No") << endl;
	return 0;
}


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

int main()
{
    string s,t;
    cin>>s>>t;
    int maxv,mins=1003,ind,flag=0;
    for(int i=0;i<s.size();i++)
    {
        maxv=0;
        ind=i;
        int gone=0;
        while(gone<t.size())
        {
            if(ind==s.size())
            {
                flag=1;
                break;
            }
            if(s[ind]!=t[gone])
            {
                maxv++;
            }
            gone++;
            ind++;
        }
        if(flag) break;
        mins=min(maxv,mins);
    }
    cout<<mins<<endl;
}



Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 500005
#define LL long long
using namespace std;
LL ans;
char s[maxn];
int n,a[maxn];
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	int i=1;
	while (i<=n){
		while (s[i]=='<') a[i+1]=a[i]+1,i++;
		int j=i;
		while (s[i]=='>') i++;
		for (int k=i-1;k>=j;k--) a[k]=max(a[k],a[k+1]+1);
	}
	for (int i=1;i<=n+1;i++) ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=200010;
const int P=1000000007;
using ll = long long;
vector<ll> prime;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	string s;
	s.size()
*/

/*
	char s[N];
	strlen(s)
*/
/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/


int main(){
	int n;
	cin>>n;
  set<string> S;
  rep(i, n){
    string s; 
    cin>>s;
    S.insert(s);
  }


	cout<<sz(S)        <<endl;


}


Measured memory_bytes: 19416
#include <atcoder/all>
#include <bits/stdc++.h>

#define rep(i,n)  for(int i = 0; i < (int)(n); i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
 std::cin.tie(0);  std::ios::sync_with_stdio(false);
 int n; std::cin >> n;
 atcoder::dsu uf(n);

 int Q; std::cin >> Q;
 rep(i,Q) {
   int t, u, v; std::cin >> t >> u >> v;
   if ( t == 0 ) uf.merge(u,v);
   else {
     if ( uf.same(u,v) ) std::cout << 1 << std::endl;
     else std::cout << 0 << std::endl;
   }
 }
  return 0;
}



Measured memory_bytes: 3992
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            HashMap<String, Integer> card = new HashMap<>();
            for (int i = 0; i < N; i++) {
                String s = in.next();
                Integer count = card.get(s);
                card.put(s, 1 + (count == null ? 0 : count.intValue()));
            }
            int M = in.nextInt();
            for (int i = 0; i < M; i++) {
                String s = in.next();
                Integer count = card.get(s);
                card.put(s, -1 + (count == null ? 0 : count.intValue()));
            }

            int max = 0;
            for (String s : card.keySet()) {
                max = Math.max(max, card.get(s).intValue());
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 21460
n,k=map(int,input().split())
b=list(map(int,input().split()))
a=0
for i in range(n):b[i]-=1
if k<n:
  for _ in range(k):a=b[a]
  print(a+1);exit()
c=[-1]*n
cc=0
se=set()
while a not in se:
  c[a]=cc
  cc+=1
  se.add(a)
  a=b[a]
for _ in range((k-c[a])%(cc-c[a])):a=b[a]
print(a+1)

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

string rR(string s) {
  swap(s[0],s[2]);
  swap(s[0],s[6]);
  swap(s[6],s[8]);
  swap(s[1],s[5]);
  swap(s[1],s[3]);
  swap(s[3],s[7]);
  return s;
}
string rL(string s) {
  swap(s[0],s[2]);
  swap(s[2],s[8]);
  swap(s[6],s[8]);
  swap(s[1],s[5]);
  swap(s[5],s[7]);
  swap(s[3],s[7]);
  return s;
}

vector<string> U(vector<string> s) {
  swap(s[0],s[4]);
  swap(s[0],s[5]);
  swap(s[2],s[5]);
  for(int i=0; i<4; i++) swap(s[2][i],s[2][8-i]);
  for(int i=0; i<4; i++) swap(s[5][i],s[5][8-i]);
  s[1]=rR(s[1]);
  s[3]=rL(s[3]);
  return s;
}
vector<string> D(vector<string> s) {
  swap(s[0],s[5]);
  swap(s[0],s[4]);
  swap(s[2],s[4]);
  for(int i=0; i<4; i++) swap(s[2][i],s[2][8-i]);
  for(int i=0; i<4; i++) swap(s[4][i],s[4][8-i]);
  s[1]=rL(s[1]);
  s[3]=rR(s[3]);
  return s;
}
vector<string> R(vector<string> s) {
  swap(s[1],s[4]);
  swap(s[3],s[4]);
  swap(s[3],s[5]);
  s[0]=rR(s[0]);
  s[1]=rR(s[1]);
  s[2]=rL(s[2]);
  s[3]=rR(s[3]);
  s[4]=rR(s[4]);
  s[5]=rR(s[5]);
  return s;
}
vector<string> L(vector<string> s) {
  swap(s[1],s[5]);
  swap(s[3],s[5]);
  swap(s[3],s[4]);
  s[0]=rL(s[0]);
  s[1]=rL(s[1]);
  s[2]=rR(s[2]);
  s[3]=rL(s[3]);
  s[4]=rL(s[4]);
  s[5]=rL(s[5]);
  return s;
}


int main() {
  string t;
  while(cin >> t&&t!="#") {
    vector<string> s;
    map<vector<string>, int> m;
    string r=t;
    for(int j=1; j<3; j++) {
      cin >> t;
      r+=t;
    }
    s.push_back(r);
    for(int i=1; i<6; i++) {
      r="";
      for(int j=0; j<3; j++) {
        cin >> t;
        r+=t;
      }
      s.push_back(r);
    }
    m[s]=0;
    queue<vector<string> > que;
    que.push(s);
    while(!que.empty()) {
      s=que.front();que.pop();
      bool f1=0,f2=0;
      for(int i=0; i<3; i++) {
        if(s[0][i+6]=='*') f1|=1;
        if(s[2][i+6]=='*') f2|=1;
      }
      int c=m[s];
      if(f1&&f2) {
        cout << c << endl;
        break;
      }
      vector<string> t=U(s);
      if(!m.count(t)) {
        m[t]=c+1;
        que.push(t);
      }
      t=D(s);
      if(!m.count(t)) {
        m[t]=c+1;
        que.push(t);
      }
      t=R(s);
      if(!m.count(t)) {
        m[t]=c+1;
        que.push(t);
      }
      t=L(s);
      if(!m.count(t)) {
        m[t]=c+1;
        que.push(t);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=1<<30;

int main(){
    
    int N,X;cin>>N>>X;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(all(A));
    
    ll dp[N+1][X+1];
    
    memset(dp,0,sizeof(dp));
    
    for(int j=0;j<X+1;j++) dp[0][j]=j;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<X+1;j++){
            dp[i+1][j]+=dp[i][j]*i;
            dp[i+1][j]%=mod;
        }
        
        for(int j=0;j<X+1;j++){
            dp[i+1][j]+=dp[i][j%A[i]];
            dp[i+1][j]%=mod;
        }
    }
    
    cout<<dp[N][X]<<endl;
}



Measured memory_bytes: 157312
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define M (100003)
s64 H[M];
int num[M];

s64 mysort(char *str)
{
    int temp[26];
    rep (i, 26) temp[i] = 0;
    rep (i, 10) temp[str[i] - 'a']++;
    u64 key = 0;
    for (int i = 0; i < 26; ++i)
    {
        if (temp[i])
        {
            while (temp[i])
            {
                key *= 27;
                key += i + 1;
                temp[i]--;
            }
        }
    }
    return key;
}

inline int h1(s64 key) { return key % M; }
inline int h2(s64 key) { return 1 + key % (M - 1); }
int myhash(s64 key, int i)
{
    return (h1(key) + i * h2(key)) % M;
}

int insert(char *str)
{
    s64 key = mysort(str);
    s64 idx;
    int ret;
    for (int i = 0; i < M; ++i)
    {
        idx = myhash(key, i);
        if (num[idx] == 0)
        {
            H[idx] = key;
            ret = num[idx];
            num[idx]++;
            return ret;
        }
        else if (H[idx] == key)
        {
            ret = num[idx];
            num[idx]++;
            return ret;
        }
    }
    return -1;
}

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

    int N;
    char str[11];

    cin >> N;

    u64 ret = 0;
    rep (i, N)
    {
        cin >> str;
        ret += insert(str);
    }

    cout << ret << "\n";

    return 0;
}



Measured memory_bytes: 1408
aaa = list(map(int, input().split())) + list(map(int, input().split()))+ list(map(int, input().split()))
#3行分list化一行へ変換
n = int(input())
for x in range(n):
  b = int(input()) #bの入力 
  try:
    i = aaa.index(b) #aaaで値bがあれば、そのindexをiへ入力
  except:
    continue # errorだとしても繰り返し
  if i >= 0: # iが数値になったら
    aaa[i] = -1 # aaa[i]にしるし(-1)を付与
for i, j, k in [(0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)]:
  if aaa[i] == -1 and aaa[j] == -1 and aaa[k] == -1:
    print('Yes')
    break
else:
  print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n%2==0) {
    int a= n/2;
    a=a-1;
    cout<<a<<endl;
  }
  else{
    int a = n/2;
    cout<<a<<endl;
  }
}

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

int main(){
    long long N,Y;
    cin >> N >> Y;
    long long y = Y/1000;
    vector<int>vec(2);
    int usi = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
        int X = y-i*10-j*5; 
            if(X == (N-i-j)*1 && X >= 0){
            vec[0] = i;
            vec[1] = j;
            vec[2] = N-i-j;
            usi++;
            }     
        }
    }
    if(usi == 0)cout << "-1 -1 -1" << endl;
    else cout <<vec[0]<<" "<<vec[1]<<" "<<vec[2]<<endl;
}


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


ll gcd(ll x, ll y){
  if(x<y) swap(x, y);
  
  if(x%y==0){
    return y;
  }else return gcd(x%y, y);
}

int main(){
  ll n, x; 
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll res = abs(a[0] - x);
  rep(i,n){
    res = gcd(res, abs(a[i]-x));
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

    n = int(input())
    a = list(map(int, input().split()))
    b = Counter(a)
    ans = 0

    for key, value in b.items():
        if value > key:
            ans += value - key
        elif value < key:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int a, b, c; cin >> a >> b >> c;
  int x; cin >> x;
  int ans = 0;
  rep(i,a+1) rep(j,b+1) rep(k,c+1) {
    if (x == 500*i + 100*j + 50*k) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <bitset>
#include <climits>

using namespace std;

int main(){
    int n;
    cin >> n;
    auto fs=vector<bitset<10>>(n, bitset<10>());
    for(int i=0; i<n; ++i){
        for(int j=0; j<10; ++j){
            int f;
            cin >> f;
            if(f==1) fs[i].set(j);
            else fs[i].reset(j);
        }
    }
    auto ps=vector<vector<int>>(n, vector<int>(11));
    for(int i=0; i<n; ++i){
        for(int j=0; j<11; ++j){
            cin >> ps[i][j];
        }
    }

    int res=INT_MIN;
    for(int mask=1; mask<1024; ++mask){
        bitset<10> b(mask);
        int t=0;
        for(int i=0; i<n; ++i){
            int c=(b & fs[i]).count();
            t+=ps[i][c];
        }
        res=max(t, res);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, S: str):
    if S[:N//2] == S[N//2:]:
        print(YES)
    else:
        print(NO)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , m , sz[N], p[N] , comp ;

int Par(int i){ return p[i]=( i==p[i] )?i:Par(p[i]); }
bool same(int i,int j){ return Par(i)==Par(j); }

void mrg(int i,int j){
if(same(i,j))return;
i=Par(i);j=Par(j);
if( rand()&1 )swap(i,j);
sz[p[j]] += sz[p[i]];
p[i]=p[j];
comp --;
}

vector < ll > out ;
vector < ii > edge ;

ll calc ( int x ){
return 1LL*sz[x]*(sz[x]-1)/2LL ;
}
int main ( ){
  scanf("%d %d",&n,&m);
  for  (int i = 1 ; i <= n; i++ ) sz[i] = 1, p[i]=i;
  for ( int i = 1; i <= m ;i++){
    int x, y;
    scanf("%d %d",&x,&y);
    edge.push_back({x,y});
  }
  ll ANS = 1LL*n*(n-1)/2LL  , all = 0 ;
  for  (int i = m-1 ; i >= 0 ; --i ){
    out.push_back(ANS-all);
    if ( !same(edge[i].F,edge[i].S)){
        all -= calc(Par(edge[i].F));
        all -= calc(Par(edge[i].S));
        mrg(edge[i].F,edge[i].S);
        all += calc(Par(edge[i].F));
    }
  }
  reverse(out.begin(),out.end());
  for ( auto x: out )
    printf("%lld\n",x);
return 0 ;
}


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vp = vector<pii>;
using vs = vector<string>;
using qi = queue<int>;
using qp = queue<pii>;
using pqi = priority_queue<int>;
using pqim = priority_queue<pii, vector<pii>, greater<pii> >;
using ppp = pair<int, pair<int, int>>;
#define all(vec) vec.begin(), vec.end()
#define rall(vec) vec.rbegin(), vec.rend()
#define pb push_back
const ll mod = 998244353;
int a, b; 
void input() {
	cin >> a >> b;


}
void solve() {
	cout << a * b;


	return;
}

int main() {
	cin.tie(NULL); ios_base::sync_with_stdio(false);

	//int tc; cin >> tc;
	//while (tc--) {
		input();
		solve();
	//}
}

Measured memory_bytes: 3224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define rep(i,x,y) for(ll i=(x); i<(y); i++)

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> PLL;

const ll V = 1000000; // 片方の頂点の最大数
vector<ll> to[2 * V]; // xあるいはyからつながっている先。y側はVの下駄を履かせる
bool visited[2 * V];
vector<ll> cnt;

void dfs(int v) {
  if (visited[v])
    return;
  visited[v] = true;
  cnt[v/V]++;
  for (ll u : to[v]) {
    dfs(u);
  }
}

signed main(void) {
  // (x,y)座標を二部グラフにする
  ll N;
  cin>>N;
  rep(i,0,N) {
    ll x, y;
    cin>>x>>y;
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }

  ll ans = 0;
  rep(i,0,2*V){
    if (visited[i])
      continue;
    cnt = vector<ll>(2);
    dfs(i);
    ans += cnt[0]*cnt[1];
  } 
  ans -= N;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 54144
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	int num_minus = 0;
	int N, K;
	cin >> N >> K;
	vector<llong> A(N);
	for(int i=0; i<N; ++i){
		cin >> A[i];
		if(A[i]<0) ++num_minus;
	}
	sort(A.rbegin(), A.rend());
	int q = K/2;
	int r = K%2;
	int init = 0;
	int fin = N-1;
	llong ans = 1;
	if(r==0){
		for(int i=0; i<q; ++i){
			llong plus = A[init]*A[init+1];
			llong minus = A[fin]*A[fin-1];
			if(plus > minus){
				ans *= A[init] % MOD;
				ans %= MOD;
				ans *= A[init+1] % MOD;
				ans %= MOD;
				init += 2;
			}else{
				ans *= A[fin] % MOD;
				ans %= MOD;
				ans *= A[fin-1] % MOD;
				ans %= MOD;
				fin -= 2;
			}
		}
	}
	else if(r==1){
		if(num_minus == N){
			for(int i=0; i<K; ++i){
				ans *= A[i] % MOD;
				ans %= MOD;
			}
		}else{
			for(int i=0; i<q; ++i){
				llong plus = A[init]*A[init+1];
				llong minus = A[fin]*A[fin-1];
				if(plus > minus){
					ans *= A[init] % MOD;
					ans %= MOD;
					ans *= A[init+1] % MOD;
					ans %= MOD;
					init += 2;
				}else{
					ans *= A[fin] % MOD;
					ans %= MOD;
					ans *= A[fin-1] % MOD;
					ans %= MOD;
					fin -= 2;
				}
			}
			ans *= max(A[init], A[fin]) % MOD;
			ans %= MOD;
		}
	}
	ans %= MOD;
	if(ans < 0) ans += MOD;
	cout << ans << endl;
}

Measured memory_bytes: 4848
#リストに入力して整数に
n=gets.to_i
lst=gets.chomp.split(" ").map(&:to_i)
flag=1
dd=0
i=1
while(n>i)
  d=lst[i-1]-lst[i]
  if(d>1)
    flag=0
    break
  elsif(dd==1 and d==1)
    flag=0
    break
  end
  if(d!=0)
    dd=d
  end
  i=i+1
end
if (flag==1)
  print("Yes")
else
  print("No")
end
        


Measured memory_bytes: 9604
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<functional>
#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
using namespace std;
#define ull unsigned long long
int memo[150];
int  dp[1000002];
int  dp2[1000002];
void inset(){
	dp[0]=0;
	fill(dp,dp+1000001,10000);
	fill(dp2,dp2+1000001,10000);
	dp[0]=0;
	dp2[0]=0;
	rep(i,1,200){
		memo[i]=i*(i+1)*(i+2),memo[i]/=6;
		rep(j,1,1000001)
			if(j-memo[i]>=0){
		if(dp[j]>dp[j-memo[i]]+1)dp[j]=dp[j-memo[i]]+1;
		if(memo[i]&1)if(dp2[j]>dp2[j-memo[i]]+1)dp2[j]=dp2[j-memo[i]]+1;
		}
	}
	//rep(i,1,1000001){
	//	if(dp2[i]==0){
	//	printf("[%d]%d\n",i,dp2[i]);
	//	break;
	//	}
	//}
}


int main(void){
	inset();
	int x;
	while(true){
		cin>>x;if(x==0)return(0);
		cout<<dp[x]<<" "<<dp2[x]<<endl;
	}

}

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

int main(){
  int n; cin >> n;
  long long k; cin >> k;
  vector<int> a(n);
  for(int i = 0 ; i<n ; i++){
    cin >> a[i];
  }
  vector<bool> visit(n+1,false);
  int now = 1;
  long long leng = 0;
  while(true){
    if(visit[now]) break;
    visit[now] = true;
    now = a[now-1];
    leng++;
  }
  
  int p = now;
  long long loop = 0;
  while(true){
    p = a[p-1];
    loop++;
    if(p == now) break;
  }
  long long d = leng - loop;
  long long cnt = 0;
  if(k <= d){
    cnt = k;
  }else{
    cnt = (k-d)%loop + d;
  }
  now = 1;
  for(long long i = 0 ; i < cnt; i++){
    now = a[now-1];
  }
  cout << now << endl;
}
  
  
  


Measured memory_bytes: 4048
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  int n;
  cin >> n;

  cout << n + n * n + n * n * n;

  return 0;
}

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

int n, m;
vector<int> edge[100005];
int num[100005] = {0};
int dp[100005] = {0};

int solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    edge[x - 1].push_back(y - 1);
    ++num[y - 1];
  }
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 0;
  queue<int> qu;
  for(int i = 0; i < n; ++i)
    if(num[i] == 0) qu.push(i);
  while(qu.size() > 0) {
    int now = qu.front();
    qu.pop();
    for(int i = 0; i < edge[now].size(); ++i) {
      int to = edge[now][i];
      if(--num[to] == 0) {
        dp[to] = dp[now] + 1;
        ans = max(ans, dp[to]);
        qu.push(to);
      }
    }
  }
  return ans;
}

Measured memory_bytes: 6528
#include<stdio.h>
#include<stdlib.h>

int max(int a, int b){
  if(a > b) return a;
  else return b;
}

int min(int a, int b){
  if(a < b) return a;
  else return b;
}

  int n,m;
  int seen[9];
  int graph[9][9];
  int count = 0;


void dfs(int x, int y){

  if(seen[y] == 1) return;
  if(graph[x][y] != 1) return;

  seen[y] = 1;

  int flag = 0;
  for(int i = 1; i <= n; ++i){
    if(seen[i] == 0) flag = 1;
  }
  if(flag == 0) count ++;

  for(int i = 1; i <= n; ++i){
    if(seen[i] == 0 && graph[y][i] == 1){
      dfs(y,i);
      seen [i] = 0;
    }
  }


  return;
}


int main(){

  scanf("%d %d",&n,&m);

  int a,b;
  for(int i = 0; i < m; ++i){
    scanf("%d %d",&a,&b);
    graph[a][b] = 1;
    graph[b][a] = 1;
  }

  for(int i = 2; i <= n; ++i){
    seen[1] = 1;
    dfs(1,i);
    seen[i] = 0;
  }

  printf("%d",count);

  return 0;

}


Measured memory_bytes: 128