akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll minthis(ll a, ll b){return a<b?a:b;}
ll maxthis(ll a, ll b){return a>b?a:b;}
bool sortbysec(const pair<int, int>& a,const pair<int, int>& b){return (a.second < b.second);} 
 
 
void solve(){
    int n;
    cin >> n;
    int count = 0;
    for(int i = 0 ; i < n ; i++){
        int a,b;
        cin >> a >> b;
        if(a == b){
            count++;
        }
        else{
            count = 0;
        }
        if(count == 3) {
            cout << "Yes" << "\n";
            return;
        }
    }
    cout << "No" << "\n";
}
 
 
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
  return 0; 
}

Measured memory_bytes: 3648
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <stdio.h>
#define   FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
int int_sort(const void*a,const void *b) {
	return *(  int *) b - *(int *) a;
	//qsort(b, a, sizeof(long long int), int_sort);
}

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

	if((N+1)/2<K){
		cout<<"NO";
		return 0;
	}
	else{
		cout<<"YES";
		return 0;
}



}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append((i, n//i))

    divisors.sort()
    return divisors

from math import log10
N = int(input())
div = make_divisors(N)

def F(A, B):
    return max(log10(A)+1, log10(B)+1)
ans = 10**9
for a, b in div:
    ans = min(ans, F(a, b))
print(int(ans))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
long long presum,a,res;
map<long long,int> cnt;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	cnt[0]=1;
	for(int i=1;i<=n;i++){
		cin>>a;
		presum+=a;
		res+=(long long)(cnt[presum]);
		cnt[presum]++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 12800
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

x, y = nl()

g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]

if (x in g1 and y in g1) or (x in g2 and y in g2):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,j;
    char ar[120];
    while(gets(ar))
    {
        a=strlen(ar);
        for(i=a-1;i>=0;i--)
        {
            printf("%c",ar[i]);
        }
        printf("\n");
    }
    return 0;
}

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

int main(){
	char letra[2];
	scanf("%s", letra);
	if(letra[0]=='a' || letra[0]=='b'|| letra[0]=='c'|| letra[0]=='d'|| letra[0]=='e'|| letra[0]=='f'|| letra[0]=='g'|| letra[0]=='h'|| letra[0]=='i'|| letra[0]=='j'|| letra[0]=='k'|| letra[0]=='l'|| letra[0]=='m'|| letra[0]=='n'|| letra[0]=='o'|| letra[0]=='p'|| letra[0]=='q'|| letra[0]=='r'|| letra[0]=='s'|| letra[0]=='t'|| letra[0]=='u'|| letra[0]=='v'|| letra[0]=='w'|| letra[0]=='x'|| letra[0]=='y'|| letra[0]=='z')
		printf("a");
	else
		printf("A");
	printf("\n");
	return 0;	
}

Measured memory_bytes: 1664
a,b = map(int,input().split())
tmp_list = [0]*1000
tmp_list[0] = 1
for i in range(1,len(tmp_list)-1):
    tmp_list[i] = tmp_list[i-1]+i+1
tmp_list.pop(-1)
res_w = tmp_list[b-a-2]
res_e = tmp_list[b-a-1]
print(res_w-a)

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

int main() {
    string S;
    cin >> S;
    if(S.at(0)==S.at(1) && S.at(1)==S.at(2)){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}


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

int N;
int W[105], SW[105];
int main(void){
  cin>>N;
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>W[i];
    sum+=W[i];
    SW[i]=sum;
  }
  int min=999999;
  for(int i=0;i<N;i++){
    if(abs(2*SW[i]-sum)<min) min=abs(2*SW[i]-sum);
  }
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)
array = Array.new(n+1, 0)
wa = 0
ac = 0

m.times do
  a, b = gets.chomp.split(" ")
  a = a.to_i
  if b == "WA" && array[a] != -1
    array[a] += 1
  elsif b == "AC" && array[a] != -1
    ac += 1
    wa += array[a]
    array[a] = -1
  end
end

print ac
print " "
puts wa


Measured memory_bytes: 2556
//テンプレ
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> a(N);
  rep(i,K){
    int d;
    cin>>d;
    rep(j,d){
      int x;
      cin>>x;
      a.at(x-1)++;  
    }
  }
  int ans=0;
  rep(i,N){
    if(a.at(i)==0){
      ans++;
    }
  }
  cout<<ans<<endl;
  
  
}

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

const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n;
    cin >> n;
    double t, a;
    cin >> t >> a;
    vector<double> h(n);
    rep(i, 0, n) cin >> h[i];
    int ans = INF;
    double mn = INF;
    rep(i, 0, n){
        if(abs(t - h[i]*0.006 - a) < mn){
            mn = abs(t - h[i]*0.006 - a);
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/algorithm/find.hpp>

using namespace std;
using boost::multiprecision::int128_t;
using boost::find;

int main() {
    int128_t ans = 1;
    int n;
    cin >> n;
    vector<long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    if (find(a, 0) != a.end()) {
        cout << 0 << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        ans *= a[i];
        if (ans > (long)1e18) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += (r - l + 1);
  }
  
  cout << sum << endl;
}

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

int main() 
{
  int N;
  cin >> N;
  
  int sum = 0; //各桁の合計
  int t = N; //N%10の商
  int c = 0; //N%10のあまり
  
  while (t > 0)
  {
    c = t % 10;
    t = t / 10;
    sum += c;
  }
  
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n,A[50];
int solve(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}
int main(){
  int q,M,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
 
int main()
{
	int n, cnt=0;
	cin >> n;
  vector<int> p(n);
  rep(i, n) {cin >> p[i]; --p[i];}
  rep(i, n) if(p[i] != i) cnt++;

  if(cnt == 2 || cnt == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
prime = [3, 5, 7, 11, 13, 17, 19]
A = {a**7 for a in prime if a**7<200}
B = {a*b**3 for a, b in permutations(prime, 2) if a*b**3<200}
C = {a*b*c for a, b, c in permutations(prime, 3) if a*b*c<200}
D = A | B | C
ans = 0
for i in range(n+1):
    if i % 2 == 1 and i in D:
        ans += 1
print(ans)


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

int main(){
  int rumah1,rumah2,rumah3;
  cin >> rumah1>>rumah2>>rumah3;
  if(rumah1 > rumah2){
  	int temp;
  	temp = rumah1;
  	rumah1 = rumah2;
  	rumah2 = temp;
  }
  if(rumah3 >= rumah1 && rumah3 <= rumah2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main() {
  int i; double d[10000]={};
  for(i=0;cin>>d[i];i++);
  sort(d,d+i,greater<int>());
  cout<<d[0]-d[i-1]<<endl;
  return 0;
}

Measured memory_bytes: 1360
using System;
using System.Collections.Generic;
using System.Linq;

class Program{

  static int d, n;
  static int ans;

  static int Main() {

    string[] nyu = Console.ReadLine().Split(' ');
    d = int.Parse(nyu[0]);
    n = int.Parse(nyu[1]);

    if (n == 100) n++;

    if (d < 1) {
      ans = n;
    } else {
      ans = n * (int)Math.Pow(100, d);
    }

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13268
import queue
import itertools
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
G = [[] for _ in range(H * W)]

for i in range(H * W):
    u = i // W
    v = i % W
    
    if s[u][v] == '#':
        continue
    if u-1 >= 0 :
        if s[u-1][v] == '.':
            G[i].append(i-W)
    if v-1 >= 0:
        if s[u][v-1] == '.':
            G[i].append(i-1)
    if v+1 < W:
        if s[u][v+1] == '.':
            G[i].append(i+1)
    if u+1 < H:
        if s[u+1][v] == '.':
            G[i].append(i+W)

def dfs(Graph, N, start):
    q = queue.Queue()
    dist = [-1] * N
    dist[start] = 0
    q.put(start)

    while not q.empty():
        v = q.get()
        for u in G[v]:
            if dist[u] != -1:
                continue
            dist[u] = dist[v] + 1
            q.put(u)

    return dist
dist = dfs(G, H*W, 0)

if dist[-1] == -1:
    print(-1)
    exit()
count = list(itertools.chain.from_iterable(s)).count('#')
print(H*W - (dist[-1] + 1) - count)

Measured memory_bytes: 4464
#include<stdio.h>
int a[200010];
int flag[200010];
int main(){
	long long n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	
	int pos=1,cnt=0;
	while(k){
		pos=a[pos];
		k--;
		cnt++;
		if(flag[pos])k%=cnt-flag[pos];
		else flag[pos]=cnt;
	}
	printf("%d\n",pos);
}

Measured memory_bytes: 3296
n,m=map(int,input().split())
if m==0:
  if n ==1:
    print(0)
  else:
    print(10**(n-1))
else:
  sc= [list(map(int,input().split())) for i in range(m)]
  ans = -1
  for j in range(10**(n-1)-1,10**n):
    k=str(j)
    s=[[0 for i in range(2)] for i in range(len(k))]
    for l in range(len(k)):
      s[l][0]=l+1
      s[l][1]=int(k[l])
      if all(elm in s for elm in sc) == 1:
        ans=j
        break
    if ans==j:
      break
  print(ans)

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


int main(){
	int n;    
	cin>>n;
	
	int arr[n+1] = {};
	int temp;
	for(int i=0;i<n-1;i++){
		cin>>temp;
		arr[temp]++;
	}
	for(int i=1;i<=n;i++)
		cout<<arr[i]<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

ll mo = 1000000007;
int N;
ll dp[100];

int main(){
  cin >> N;
  string s1, s2;
  cin >> s1;
  cin >> s2;
  int i = 0;
  int x = 0;
  if(s1[i] == s2[i])  dp[i++] = 3;
  else{
    dp[i++] = 6;
    dp[i++] = 6;
    x = 1;
  }
  for(; i < N;){
    if(s1[i] == s2[i]){
      if(x == 0){
        dp[i] = (2 * dp[i-1]) % mo;
      }
      else{
        dp[i] = dp[i-1];
      }
      i++;
      x = 0;
    }
    else{
      if(x == 0){
        dp[i] = (2 * dp[i-1]) % mo;
        dp[i+1] = dp[i];
      }
      else{
        dp[i] = (3 * dp[i-1]) % mo;
        dp[i+1] = dp[i];
      }
      i += 2;
      x = 1;
    }
  }
  cout << dp[N-1] << endl;


  return 0;
}


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

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, s;

            string[] word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            int m = a;
            if (b > m) m = b;
            if (c > m) m = c;
            s = a + b + c - m;

            Console.WriteLine(s);

            //Console.ReadKey();
        }
    }
}

Measured memory_bytes: 27408
n = gets.to_i

sum = 0
counter = Hash.new { |h, k| h[k] = 0 }
gets.split.map(&:to_i).each do |a|
  sum += a
  counter[a] += 1
end

q = gets.to_i
q.times do
  b, c = gets.split.map(&:to_i)

  sum += counter[b] * (c - b)
  puts sum
  
  counter[c] += counter[b]
  counter[b] = 0
end


Measured memory_bytes: 25732
#include<iostream>
#define maxn 100006
#define ll long long
using namespace std;

ll DP[maxn][110];
int N,W;
ll w[maxn], v[maxn];

ll max(ll a, ll b) {
	if (a >= b) return a;
	return b;
}

ll cal(int wgt, int pos) {
	if (pos == N) {
		return 0LL;
	}
	if (wgt == 0)
		return 0LL;

	ll &res = DP[wgt][pos];
	if (res != -1) {
		return res;
	}

	res = cal(wgt, pos+1);
	if (w[pos] <= wgt)
		res = max(res, cal(wgt - w[pos], pos + 1) + v[pos]);
	
	return res;
}

int main() {

	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}

	
		for (int k = 0; k < maxn; k++) {
			for (int i = 0; i < 110; i++) {
				DP[k][i] = -1;
			}
		}



		cout << cal(W, 0) << endl;


	return 0;
}

Measured memory_bytes: 86144
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll fun(ll x,ll k){
	while(x%k==0){
		x=x/k;
	}
	return x%k==1;
}
int main(){
	ll n;cin>>n;
	ll x=n,cnt=0;
	set<ll> s;
	for(ll i=1;i*i<=n;i++){
		if(x%i==0){
			s.insert(i);
			if(i!=x/i){
				s.insert(x/i);
			}
		}
	}
	x=n-1;
	for(ll i=1;i*i<=n-1;i++){
		if(x%i==0){
			s.insert(i);
			if(i!=x/i){
				s.insert(x/i);
			}
		}
	}
	for(auto u: s){
		if(u!=1)cnt+=fun(n,u);
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U; 
    // int a,b;
    cin>>n>>m;
    map<int,int> dig,occ;
    while(m--)
    {
        cin>>s>>t;
        if(occ[s])
        {
            if(dig[s]!=t)
            {
                cout<<"-1";
                return;
            }
        }
        dig[s]=t;
        occ[s]++;
    }
    rep(i,0,1000)
    {
        t=i;
        vi num;
        count=0;
        while(t)
        {
            num.pb(t%10);
            t/=10;
            count++;
        }
        if(!i)
        {
            count=1;
            num.pb(0);
        }
        if(count!=n) continue;
        reverse(all(num));
        flag=0;
        rep(j,0,sz(num))
        {
            if(occ[j+1])
            {
                if(dig[j+1]!=num[j])
                {
                    flag=1;
                    break;
                }
            }
        }
        if(flag) continue;
        cout<<i;
        return;
    }
    cout<<"-1";
}
 
 
signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3672
#include<bits//stdc++.h>
using namespace std;
int main() {
    int A[2], B[2];
    cin >> A[0] >> A[1]; 
    for (int i = 0; i < 2; i++) {
        if (((A[i] % 2) == 1) && (A[i] < 9)) B[i] = 1;
        else if (((A[i] % 2) == 1) && (A[i] >= 9)) B[i] = 2;
        if (((A[i] % 2) == 0) && (A[i] == 2)) B[i] = 3;
        else if (((A[i] % 2) == 0) && (A[i] <= 6)) B[i] = 2;
        else if (((A[i] % 2) == 0) && (A[i] >= 8)) B[i] = 1;
    }
    if (B[0] == B[1]) cout << "Yes" << endl;
    else  cout << "No" << endl;
}

Measured memory_bytes: 256
# coding: utf-8
N = int(input())
l = {}
ans = 0
for i in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    if tmp in l.keys():
        l[tmp] += 1
        ans += l[tmp]
    else: 
        l[tmp] = 0
print(ans)

Measured memory_bytes: 17808
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

int main()
{
  char s[100001], t[100001];
  scanf("%s %s", s, t);
  
  std::vector<long long> v[26];
  for (char *p = s; *p; ++p)
  {
    v[*p - 'a'].emplace_back(p - s);
  }
  long long ans = 0;
  long long pos = -1;
  long long count = 0;
  for (char *p = t; *p; ++p)
  {
    auto& ve = v[*p - 'a'];
    if (ve.size() == 0)
    {
      puts("-1");
      return 0;
    }
    auto it = std::upper_bound(ve.begin(), ve.end(), pos);
    if (it == ve.end())
    {
      ++count;
      pos = ve[0];
    }
    else
    {
      pos = *it;
    }
  }
  printf("%lld\n", count * strlen(s) + pos + 1);
  return 0;
}


Measured memory_bytes: 1568
#include <iostream>
using namespace std;
int main(){
  int N=0;
  cin >> N;
  for(int i=0;i<N;i++){
    int k,p;
    cin >>k>>p;
     int ans= k%p;
     if(ans ==0){
       ans = p;
     }
     cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline

def main():
    n,y = map(int,read().split())
    for i in range(n+1):
        for j in range(n-i+1):
            if i*1000 + j*5000 + (n-i-j)*10000 == y:
                print("{} {} {}".format(n-i-j,j,i))
                return
    print("-1 -1 -1")
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    const ll mod = 998244353;

    ll N;
    cin >> N;
    vector<ll> D(N), V(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> D.at(i);
        if ((i == 0 && D.at(i) != 0) || (i != 0 && D.at(i) == 0)) {
            cout << 0 << endl;
            exit(0);
        }
        V.at(D.at(i))++;
    }

    ll ans = 1;
    for (int i = 1; i < N; ++i) {
        ans = ans * V.at(D.at(i) - 1) % mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
// inputに入力データ全体が入る
function Main(input) {
  var t = input.split(" ")[0];
  var x = input.split(" ")[1];
  console.log("%d",t/x)
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1300005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int power(int x, unsigned int y, unsigned int m)
{
    if (y == 0)
        return 1;
    int p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n,k;
        cin>>n>>k;
        int a[n+1];
        rep(i,1,n+1) cin>>a[i];
        int dp[n+1];
        dp[1] = 0;
        rep(i,2,n+1) dp[i] = INF;
        rep(i,2,n+1){
            rep(j,1,k+1){
                if(i-j>=1) dp[i] = min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
            }
        }
        cout<<dp[n];
    }       
}     

Measured memory_bytes: 1792
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> ans;
	ans.resize(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		ans[a - 1]++;
		ans[b - 1]++;
	}
	for (int i = 0; i < n; i++)
		cout << ans[i] << endl;
//	cin >> n;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

int main()
{
    int n;
    double d,sum;
    cin >> n;
    REP(n){ cin >> d; sum+= d;}

    cout << (int)(sum/n) << endl;

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;

    t=" "+t;

    vvl dp(n+1,vl(3));

    repa(i,1,n+1){
        if(i>k){
            if(t[i]=='r'){
                dp[i][0]=max(dp[i-k][1],dp[i-k][2]);
                dp[i][1]=max(dp[i-k][0],dp[i-k][2]);
                dp[i][2]=p+max(dp[i-k][0],dp[i-k][1]);
            }else if(t[i]=='s'){
                dp[i][0]=r+max(dp[i-k][1],dp[i-k][2]);
                dp[i][1]=max(dp[i-k][0],dp[i-k][2]);
                dp[i][2]=max(dp[i-k][0],dp[i-k][1]);
            }else{
                dp[i][0]=max(dp[i-k][1],dp[i-k][2]);
                dp[i][1]=s+max(dp[i-k][0],dp[i-k][2]);
                dp[i][2]=max(dp[i-k][0],dp[i-k][1]);
            }
        }else{
            if(t[i]=='r')dp[i][2]=p;
            else if(t[i]=='s')dp[i][0]=r;
            else dp[i][1]=s;
        }
        // cerr<<i<<"  "<<dp[i][0]<<" , "<<dp[i][1]<<" , "<<dp[i][2]<<"\n";
    }

    ll ans=0;

    rep(i,k){
        ans+=max(dp[n-i][0],max(dp[n-i][1],dp[n-i][2]));
    }

    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 5756
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  string s; cin >> s;
  int l = s.size();
  int t = 0;
  for (int i = l - 1, j = 0; i > j; i--) {
    char ci = s[i];
    if (ci == 'R') {
      for (; j < i; j++) {
        char cj = s[j];
        if (cj == 'W') {
          swap(s[i], s[j]);
          t++;
          break;
        }
      }
    }
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <iomanip>

using namespace std;


int main(){
    int n,count = 0;
    long double sum = 0;

    cin >> n;

    vector<pair<int,int>>v(n);
    vector<int>perm(n);

    for(int i = 0;i < n;i++){
        cin >> v[i].first >> v[i].second;
        perm[i] = i+1;
    }

    do{
        for(int i = 0;i < n-1;i++){
            long double x = v[perm[i]-1].first - v[perm[i+1]-1].first;
            long double y = v[perm[i]-1].second - v[perm[i+1]-1].second;
            sum += sqrt(x*x+y*y);
        }
        count++;

    }while(next_permutation(perm.begin(),perm.end()));

    cout << setprecision(16) <<sum / count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 int main(){
  int a,
      b,
      d[2];
  char c,  
       suuti[2][20];
  b = 0;
  while(b < 2){

   for(a = 0;a < 19 && (c = getchar()) != ' ';a++){
    suuti[b][a] = c;
   }
   suuti[b][a] = 0;

   d[b] = atoi(suuti[b]);
   b++;
  }suuti[b][a] = 0;

  printf("%ld %ld\n",d[0]*d[1],d[0]*2+d[1]*2);

  return 0;
}
  

Measured memory_bytes: 524
#include <iostream>
#include <math.h>
#include <string>

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

using namespace std;

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

	int box[27] = {};

	for(int i = 0; i < s.length(); ++i){
		box[s[i] - 'a']++;
	}

	for(int i = 0; i < 28; ++i){
		//cout << i << " " << (char)('a' + i) << " " << box[i] << endl;
		if(i == 26){
			cout << "None" << endl;
			break;
		} else if(box[i] == 0){
			cout << (char)('a' + i) << endl;
			break;
		}
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,d[100000];
  cin >> n;
  if(n%2==1) {
    cout << 0 << endl;
    return 0;
  }
  for(int i=0; i<n; i++) {
    cin >> d[i];
  }
  sort(d,d+n);
  cout << d[(n-1)/2+1]-d[(n-1)/2] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

void _139() {
    string s, t;
    cin >> s;
    cin >> t;

    int count = 0;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == t[i])
            count++;
    }
    cout << count << endl;
}

void _138() {
    int a;
    string s;
    cin >> a;
    cin >> s;

    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
}

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

    int add = a + b;
    int mult = a * b;
    int sub = a - b;

    cout << max(add, max(mult, sub)) << endl;
}

void _136() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}

void _135() {
    long long a, b;
    cin >> a >> b;

    if (abs(a - b) % 2 != 0)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << (a + b) / 2 << endl;
}

void _134() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}

void _133() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
}

void _132() {
    string s;
    cin >> s;

    char    c[2];
    memset(c, 0, sizeof(c));
    int count[2];
    memset(count, 0, sizeof(count));
    c[0] = s[0];
    count[0] = 1;
    for (int i = 1; i < 4; ++i) {
        if (s[i] == c[0])
            count[0]++;
        else {
            if (c[1] == 0) {
                c[1] = s[i];
                count[1] = 1;
            }
            else {
                if (s[i] == c[1]){
                    count[1]++;
                }
                else {
                    cout << "No" << endl;
                    return;
                }
            }
        }
    }

    if (count[0] == 2 && count[1] == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    _132();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N, C, K;
    ll t;
    cin>>N>>C>>K;
    vector<ll> T;
    rep(i, N){
        cin>>t;
        T.push_back(t);
    }
    sort(all(T));
    ll count=1, mem=1;
    ll thc=T[0];
    rep1(i, N-1){
        if(T[i]>thc+K || mem>=C){
            mem=0;
            thc=T[i];
            count++;
        }
        mem++;
        //cout<<mem<<sp<<thc<<endl;
    }
    cout<<count<<endl;
    return 0;
}


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

int main(){

  //入力受付
  long N;
  cin >> N;
  vector<pair<long,long> > A(N);//それぞれにactivenessとindexを入れる
  for(long i=0;i<N;i++){
    cin >> A[i].first;
    A[i].second = i;
    //cout << A[i].first << "," << A[i].second << endl;
  }

  //sort
  sort(A.rbegin(),A.rend());

  //cout << endl;
  for(long i=0;i<N;i++){
    //cout << A[i].first << "," << A[i].second << endl;
  }

  //int dp[N+1][N+1] = {0};
  vector<vector<long>> dp(N+1, vector<long>(N+1));
  //vector<vector<int>> dp(N+1,0);

  for(long l=0;l<N;l++){
    //初期値dp[0][0]を0に初期化
    dp[0][0] = 0;
    for(long r=0;r<N;r++){
      long index = A[l+r].second;
      long agressive = A[l+r].first;
      if(l+r>=N) {
      continue;
      }
      dp[l+1][r] = max(dp[l+1][r],dp[l][r] + agressive*abs(index - l));//左に入れる
      //cout << "dp[][]:" << l << ":" << r << " " << dp[l+1][r] << endl;
      dp[l][r+1] = max(dp[l][r+1],dp[l][r] + agressive*abs((N-1)- r - index));//右に入れる
      //cout << "dp[][]:" << l << ":" << r << " " << dp[l][r+1] << endl;
    }
    //cout << "ループ終わり" << endl;
  }
  long ans = 0;
  for(long i=0;i<N;i++){
    //cout << "dp[][]:" << dp[i][N-i] << endl;
    ans = max(ans,dp[i][N-i]);
  }

  //cout << "ans:" << ans << endl;
  cout<< ans << endl;
}

Measured memory_bytes: 34604
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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;
}

map<int, int> prime_factor(int n) {
    map<int, int> ret;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

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

    int n;
    cin >> n;

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

    vector <ll> fac(1000001), inv(1000001), fiv(1000001);
    fac[0] = inv[0] = fiv[0] = fac[1] = inv[1] = fiv[1] = 1;
    for (ll i = 2; i <= 1000000; i++) {
        fac[i] = fac[i - 1] * i % MOD; // n!
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
        fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
    }

    map<int, int> mp;
    for (int i = 1; i < n; i++) {
        ll g = gcd(A[0], A[i]);
        ll tmp = A[i] / g; // 最終的にtmp倍する必要がある。

        auto primes = prime_factor(tmp);
        for (auto itr = primes.begin(); itr != primes.end(); itr++) {
            mp[itr->first] = max(mp[itr->first], itr->second);
        }
    }

    ll l = 1;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        for (int i = 0; i < itr->second; i++) {
            l = l * itr->first % MOD;
        }
    }

    ll ans = l;
    for (int i = 1; i < n; i++) {
        ll tmp = A[0] * l % MOD * inv[A[i]] % MOD;
        ans = (ans + tmp) % MOD;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8696
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>


int main()
{
    int N;
    std::cin >> N;
    std::vector<int> s(N, 0);
    int ans = 0;
    for (int i = 0; i<s.size(); i++)
    {
        std::cin >> s[i];
        ans += s[i];
    }
    if (ans % 10 != 0)
    {
        std::cout << ans << std::endl;
        return 0;
    }
    std::sort(s.begin(), s.end());
    
    int m = 0; bool is_all_ten_time = true;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] % 10 != 0)
        {
            is_all_ten_time = false;
            m = s[i];
            break;
        }
    }
    if (is_all_ten_time)
    {
        std::cout << 0 << std::endl;
    } else {
        std::cout << ans - m << std::endl;
    }

    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	ll ans = min(n, k) * x + max(0, n - k) * y;
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	vector<int> b( N, N );
	vector<int> B( N );
	while( 1 ) {
		for( int i = 0; i < N; i++ ) {
			int l = max( 0, i - A[i] );
			int r = min( N - 1, i + A[i] );
			B[l]++;
			if( r + 1 < N ) B[r + 1]--;
		}
		for( int i = 1; i < N; i++ ) {
			B[i] += B[i - 1];
		}
		K--;
		if( K <= 0 || B == b ) break;
		A = B;
		B = vector<int>( N );
	}

	for( int i = 0; i < N; i++ ) {
		if( i ) cout << " ";
		cout << B[i];
	}
	cout << endl;
}


Measured memory_bytes: 6428
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    string s,ans;
    int w;
    cin>>s>>w;
    int  now=0;
    while(now<(int)s.size()){
        ans.push_back(s[now]);
        now+=w;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int A,B,X;
  scanf("%d %d %d",&A,&B,&X);
  if(X - A < 0 || X > A + B)
    printf("NO\n");
  else
    printf("YES\n");
  
  return 0;
}

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

int main()
{
	std::vector<int> num_vec;
	int input_count;
	long int sum = 0;

	std::cin >> input_count;
	for (int i = 0; i < input_count; i++)
	{
		int input_num;
		std::cin >> input_num;
		num_vec.push_back(input_num);
	}

	int max = num_vec[0];
	int min = num_vec[0];
	for (unsigned int i = 0; i < num_vec.size(); i++)
	{
		if (max < num_vec[i])
			max = num_vec[i];
		if (min > num_vec[i])
			min = num_vec[i];
		sum += num_vec[i];
	}

	std::cout << min << ' ' << max << ' ' << sum << '\n';

}


Measured memory_bytes: 3244
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  string aun[n+10];
  int cnt=0;
  bool flag=true;
  for(int i=0;i<n;i++){
    cin>>aun[i];
    if(aun[i]=="A")cnt++;
    else cnt--;
    if(cnt<0)flag=false;
  }
  if(cnt!=0)flag=false;
  if(flag)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}



Measured memory_bytes: 3128
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const LL MOD = (LL)1e9 + 7;
const int MAXN = 1234;
LL fac[MAXN], invfac[MAXN];
LL dp[MAXN][MAXN];

LL add(LL a, LL b) {
    LL res = (a + b);
    if (res >= MOD) res -= MOD;
    return res;
}

LL sub(LL a, LL b) {
    return (a - b + MOD) % MOD;
}

LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

LL qpow(LL n, LL p) {
    LL res = 1, base = n;
    while (p) {
        if (p & 1) res = mul(res, base);
        base = mul(base, base);
        p >>= 1;
    }
    return res;
}

void init() {
    fac[0] = invfac[0] = 1;
    for (int i = 1; i < MAXN; i++)
        fac[i] = mul(fac[i - 1], i);
    invfac[MAXN - 1] = qpow(fac[MAXN - 1], MOD - 2);
    for (int i = MAXN - 2; i >= 1; i--)
        invfac[i] = mul(invfac[i + 1], i + 1);
}

LL C(LL n, LL m) {
    if (m > n) return 0;
    LL res = mul(fac[n], invfac[m]);
    return mul(res, invfac[n - m]);
}

int main() {
    init();
    int N, K;
    scanf("%d %d", &N, &K);
    dp[0][0] = 1;
    for (int i = 1; i <= K; i++) {
        int a;
        scanf("%d", &a);
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= min(j, a); k++) {
                LL coef = C(N - k, a - k);
                coef = mul(coef, invfac[k]);
                dp[i][j] = add(dp[i][j], mul(dp[i - 1][j - k], coef));
            }
            //printf("i = %d j = %d dp = %lld\n", i, j, dp[i][j]);
        }
    }
    printf("%lld\n", mul(dp[K][N], fac[N]));
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


Measured memory_bytes: 3940
# -*- coding: utf-8 -*-
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
bai_2 = 0
bai_4 = 0
bai_1 = 0

for i in range(n):
    if a[i] % 4 == 0:
        bai_4 += 1
    elif a[i] % 2 == 0:
        bai_2 += 1
    else:
        bai_1 += 1
        
if bai_2 == 0:
    if bai_4 >= bai_1 - 1:
        print("Yes")
    else:
        print("No")
else:
    if bai_4 >= bai_1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int n;cin>>n;
    vector<string>V(n);
    int countb=0;int counta=0;int countab=0;
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>V[i];
        int s=V[i].size();
        if(V[i][0]=='B'&&V[i][s-1]!='A')countb++;
        if(V[i][0]!='B'&&V[i][s-1]=='A')counta++;
        if(V[i][0]=='B'&&V[i][s-1]=='A')countab++;
        for(int j=0;j<s-2;j++){
            if(V[i][j]=='A'&&V[i][j+1]=='B')ans++;
        }
    }
    if(counta==0&&countb==0&&countab==0)cout<<ans<<endl;
    else if(counta==0&&countb==0&&countab>0)cout<<countab-1+ans<<endl;
    else cout<<countab+min(counta,countb)+ans<<endl;
}

Measured memory_bytes: 768
import heapq as h
q_num=int(input())
bsum=0
high=[]
low=[]
asum=0
for iii in range(q_num):
  q=[int(_) for _ in input().split()]
  if q[0]==1:
    bsum+=q[2]
    if len(low)==0:
      h.heappush(low,-q[1])
    else:
      asum+=abs(q[1]+low[0])
      if -low[0]>=q[1]:
        h.heappush(low,-q[1])
      else:
        h.heappush(high,q[1])
      
    if len(low)>=len(high)+2:
      ltoh=h.heappop(low)
      h.heappush(high, -ltoh)
    elif len(high)>=len(low)+1:
      ltoh=h.heappop(high)
      asum+=-low[0]-ltoh
      h.heappush(low, -ltoh)
  else:
    print(-low[0],asum+bsum)

Measured memory_bytes: 11124
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();
    println!("{}", s.replace(",", " "));
}


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

using namespace std;
using ll = long long;

const int N = 2005;

int n, a[N];
int id[N];

ll dp[N][N];

ll f(int l, int r) {
	int i = n - (r - l + 1);
	int p = id[i];
	if(l == r) return 1LL * a[p] * abs(p - l);
	ll &ans = dp[l][r];
	if(~ans) return ans;
	ans = -1e18;
	ans = max(ans, f(l + 1, r) + 1LL * a[p] * abs(p - l));
	ans = max(ans, f(l, r - 1) + 1LL * a[p] * abs(p - r));
	return ans;
}

int main() {
	memset(dp, -1, sizeof dp);
	scanf("%d", &n);

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

	sort(id, id + n, [](int i, int j) {
		return a[i] > a[j];
	});

	printf("%lld\n", f(0, n - 1));
}


Measured memory_bytes: 35336
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
a=int(input())
b=int(input())
c=int(input())
x=int(input())

m=0
cnt=0
for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			m=i*500+j*100+k*50
			if m==x:
				cnt+=1
				
print(cnt)

Measured memory_bytes: 3064
n = int(input())
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n):
    if dp[i] == float("Inf"):
        pass
    else:
        for j in range(1,n//6+1):
            if i + 6**j > n:
                break
            dp[i+6**j] = min(dp[i+6**j], dp[i] + 1)
        for j in range(1,n//9+1):
            if i + 9**j > n:
                break
            dp[i+9**j] = min(dp[i+9**j], dp[i] + 1)
ans = n
for i in range(max(0, n-5), n+1):
    ans = min(ans, dp[i]+n-i)
print(ans)

Measured memory_bytes: 9716
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
  int i, n, m, x, sum, count;
  vector<int> data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(i=0; i<n; ++i){
      cin >> x;
      data.push_back(x);
    }
    sort(data.begin(), data.end(), greater<int>());

    for(i=0, sum=0, count=1; i<data.size(); ++i, ++count){
      if(count == m) count = 0;
      else sum += data[i];
    }

    cout << sum << endl;
    data.clear();
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
 ll k,a,b;
  cin >> k >> a >> b;
  
 ll x=k; 
 while(x<a) x+=k; 
 
  cout << ((x<=b)?"OK":"NG") << endl;
  
}

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

Measured memory_bytes: 3632