akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn lower_bound<F>(l: usize, r: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criterion(mid) {
            r = mid;
        } else {
            l = mid;
        }
    }
    l
}

fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize,
        a: [usize;n],
        b: [usize;m],
    }

    let mut sumsa = vec![0; n + 1];
    let mut sumsb = vec![0; m + 1];

    for i in 0..n {
        sumsa[i + 1] = sumsa[i] + a[i];
    }
    for i in 0..m {
        sumsb[i + 1] = sumsb[i] + b[i];
    }

    let mut mx = 0;
    for i in 0..n + 1 {
        if sumsa[i] > k {
            break;
        }
        let crit = |j: usize| sumsa[i] + sumsb[j] > k;
        let j = lower_bound(0, m + 1, crit);
        mx = std::cmp::max(mx, i + j);
    }
    println!("{}", mx);
}


Measured memory_bytes: 12480
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vs s(n);
  vll t(n);
  rep(i, n){
    cin >> s[i] >> t[i];
  }
  string x;
  cin >> x;
  bool f = 0;
  ll ans = 0;
  rep(i, n){
    if(f) ans += t[i];
    if(s[i] == x){
      f = 1;
    }
  }
  print(ans);
}


Measured memory_bytes: 764
def range(a, b, c):
    if a < b < c :
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    param = input()
    param = param.split(" ")
    a = int(param[0])
    b = int(param[1])
    c = int(param[2])

    range(a, b, c)


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

int main() {
  int N,X,ans;
  string S;
  cin>>S;
  X=0;
  ans=0;
  N=S.length();
  for(int i=0;i<N;i++){
if(S[i]=='A'||S[i]=='T'||S[i]=='G'||S[i]=='C'){
X++;
}
    else{
      ans=max(ans,X);
      X=0;
}
  }
  cout <<max(ans,X)<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+10;
const int INF=1e9+10;
int n;
int a[MAX],b[MAX],c[MAX];
int dpa[MAX],dpb[MAX],dpc[MAX];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	dpa[0]=a[0];
	dpb[0]=b[0];
	dpc[0]=c[0];
	for(int i=1;i<n;i++){
		dpa[i]=max(dpb[i-1],dpc[i-1])+a[i];
		dpb[i]=max(dpa[i-1],dpc[i-1])+b[i];
		dpc[i]=max(dpa[i-1],dpb[i-1])+c[i];
	}
	cout<<max(dpa[n-1],max(dpb[n-1],dpc[n-1]))<<"\n";
	return 0;
}

Measured memory_bytes: 2688
# 5000**2、5000**3
# 5文字以下だよ。辛いよ。
s = input()
k = int(input())
sbst = set()
for i in range(1, k+1):
    for j in range(len(s)-i+1):
        sbst.add(s[j:j+i])
sbstl = sorted(list(sbst))
print(sbstl[k-1])


Measured memory_bytes: 4592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    int tmp = 0;
    for (int i = 0; i < N; i++)
    {
        int tmp2;
        cin >> tmp2;
        if (tmp <= tmp2)
        {
            ans++;
            tmp = tmp2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import Data.List
main = mapM_ (putStrLn . solve) . lines =<< getContents
solve t = intercalate " " . map show $ f 1 t
f i (a:b:ts)
  |a==b = [i,i+1]
f i (a:b:c:ts)
  |a==c = [i,i+2]
  |otherwise = f (i+1) (b:c:ts)
f _ _ = [-1,-1]

Measured memory_bytes: 6524
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators 
//do not forget to change the sizes of arrays and value of contants and other things after debugging  
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)
 
#define SZ(x)  (ll)(x.size())
 
//comment the below if not required
 
/*
 
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/
 
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{

    IOS;

    ll n,k,i,j,i1,ans=INT_MIN,temp,t,cyc,rem,q;

    cin>>n>>k;

    ll a[n+1];
    ll c[n+1];
    ll ind[n+1];
    ll p[n+1]={0};

    rep(i,1,n+1)
        cin>>a[i];

    rep(i,1,n+1)
        cin>>c[i];


    for(i=1;i<=n;++i)
    {

        for(j=1;j<=n;++j)
            ind[j]=0;

        j = i;
        t = 1;

        temp = 0;

        while(t<=k && (!ind[j]))
        {
            temp += c[a[j]];
            p[t] =p[t-1]+c[a[j]];
            ind[j]=t;
            j = a[j];
            ++t;
            ans = max(ans,temp);


        }

    

        i1 = ind[j];
        cyc = t-i1;

        --t;

        q = (k-t)/cyc;
        rem = (k-t)%cyc;


        if(q!=0)
            temp += (q-1)*(p[t]-p[i1-1]);

        if(q!=0)
        {
            for(j=i1;j<=t;++j)
                ans = max(ans,temp+p[j]-p[i1-1]);
        }

        if(q!=0)
            temp += p[t]-p[i1-1];

        for(j=i1;j<(i1+rem);++j)
            ans = max(ans,temp+p[j]-p[i1-1]);


    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 3792
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a  >> b >> c;
	if(b-a==c-b)
		cout << "YES" << endl;
	else 
		cout << "NO" << endl;






}

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

const int maxN = 105;
const int MOD = 10000;

char a[maxN];
char b[maxN];
int dp[maxN][maxN];
int n,m;
int main()
{
	cin>>n>>m;
	int ans = max(n+m,max(2*n-1,2*m-1));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

vector<pair<char, int> > runlength(string str) {
    vector<pair<char, int> > ret;
    int cnt = 1;
    int n = sz(str);
    rep3(i, 1, n) {
        if (str[i] == str[i - 1]) {
            cnt++;
        } else {
            ret.eb(make_pair(str[i - 1], cnt));
            cnt = 1;
        }
    }
    ret.eb(make_pair(str[n - 1], cnt));
    return ret;
}

int main() {
    
    
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ans = 0;
    rep(i, n - 1) if (s[i] == s[i + 1]) ans++;
    cout << min(n - 1, 2 * k + ans) << '\n';
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
string str;
int main() {
	while (cin >> str) {
		if (str[0] == str[2]) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>

const int maxn = 1e5 + 5;
long long pre[maxn], suf[maxn];
long long seq[maxn];

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main() {
    int t;
    std::cin >> t;
    for(int i = 1; i <= t; ++i) std::cin >> seq[i];
    pre[1] = seq[1];
    suf[t] = seq[t];
    for(int i = 2; i <= t; ++i) pre[i] = gcd(seq[i],pre[i - 1]);
    for(int i = t - 1; i >= 1; -- i) suf[i] = gcd(seq[i],suf[i + 1]);
    long long ret = 0;
    auto max = [](long long x ,long long y) ->long long {return x < y ? y : x;};
    for(int i = 1; i <= t; ++ i){
        if (i != t && i != 1) ret = max(ret,gcd(suf[i + 1],pre[i - 1]));
        else if (i == 1){
            ret = max(ret,suf[i + 1]);
        }else ret = max(ret, pre[i - 1]);
    }
    std::cout << ret << std::endl;
}

Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val (n, m, k) = readLine()!!.split(" ").map { m -> m.toInt() }
    val uf = UnionFindTree(n)
    val friends = Array<MutableSet<Int>>(n) { mutableSetOf() }
    val blocks = Array<MutableSet<Int>>(n) { mutableSetOf() }
    
    
    
    for (i in 0 until m) {
        val (a, b) = readLine()!!.split(" ").map { m -> m.toInt() }
        uf.unite(a - 1, b - 1)
        friends[a - 1].add(b - 1)
        friends[b - 1].add(a - 1)
    }
    
    for (i in 0 until k) {
        val (c, d) = readLine()!!.split(" ").map { m -> m.toInt() }
        blocks[c - 1].add(d - 1)
        blocks[d - 1].add(c - 1)
    }
    
    val ans = Array(n) { 0 }
    
    for (i in 0 until n) {
        val s = uf.size(i)
        val f = friends[i].filter { j -> uf.same(i, j) }.size
        val b = blocks[i].filter { j -> uf.same(i, j) }.size
        ans[i] = (s - f - b - 1).toInt()
    }
    
    println(ans.joinToString(" "))
}

class UnionFindTree(size: Int) {
    private val par = Array(size) { i -> i }
    private val sizeArray = Array(size) { 1L }
    
    fun root(x: Int): Int {
        if (par[x] == x) {
            return x
        } else {
            par[x] = root(par[x])
            return par[x]
        }
    }
    
    fun size(x: Int): Long {
        return sizeArray[root(x)]
    }
    
    fun same(x: Int, y: Int): Boolean {
        return root(x) == root(y)
    }
    
    fun unite(x: Int, y: Int) {
        val (xx, yy) = Pair(root(x), root(y))
        if (!same(x, y)) {
            if (sizeArray[xx] > sizeArray[yy]) {
                par[yy] = xx
                sizeArray[xx] += sizeArray[yy]
            } else {
                par[xx] = yy
                sizeArray[yy] += sizeArray[xx]
            }
        }
        
    }
    
    fun isParent(x: Int): Boolean = x == par[x]
    
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b) {
        cout << c << endl;
    } else if (b == c) {
        cout << a << endl;
    } else {
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int l,r,d;
  scanf("%d %d %d",&l,&r,&d);
  
  int ans=0;
  
  for(int i=l;i<=r;i++){
    if(i%d==0)ans+=1;
  }
  
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 2128
#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll  n,a,b;
//vector<ll> s;
ll s[200000];
bool f(ll x){
    ll tmp=0;
    for(ll i=0;i<n;i++){
        if(s[i]-b*x>0)tmp+=((s[i]-b*x)-1)/(a-b)+1;//((s[i]-b*x)+a-b-1)/(a-b);//((s[i]-b*x)-1)/(a-b)+1;
    }
    return tmp<=x;
}    
signed main(void){
    // Your code here!
    cin>>n>>a>>b;
    //s.resize(n);
    for(ll i=0;i<n;i++){
        cin>>s[i];
    }
    ll ng=0;
    ll ok=1e9;
    while(ng+1<ok){
        ll mid=(ng+ok)/2;
        if(f(mid))ok=mid;
        else ng=mid;
    }
    cout<<ok<<endl;
}


Measured memory_bytes: 1024
A, B, C, D, E, F = map(int, input().split())

w = set()
for i in range(F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        a = (A * i + B * j) * 100
        if a < F:
            w.add(a)
w.remove(0)

s = set()
for i in range(F // C + 1):
    for j in range(F // D + 1):
        b = C * i + D * j
        if b < F:
            s.add(b)
s = list(s)
s.sort()

best_concentration = -1
best_a = -1
best_b = -1
for a in w:
    for b in s:
        if a + b > F:
            continue
        if b > E * a // 100:
            continue
        concentration = 100 * b / (a + b)
        if concentration > best_concentration:
            best_concentration = concentration
            best_a = a
            best_b = b
print(best_a + best_b, best_b)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int X[22],ans;
vector<int> v;
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>X[i];
	for(int i=1;i<N-1;i++)
		if(X[i]<=max(X[i-1],X[i+1])&&X[i]>=min(X[i-1],X[i+1]))
			ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
const int N=105,mod=998244353; 
inline void add(int &x,ri y){
	x=(x+=y)>=mod?x-mod:x;
}
string s;
map<string,int> f,g;
inline int F(string s);
inline int G(string s); 
inline int F(string s){
	if(f[s]) return f[s];
	if(s.empty()) return 1;
	ri i,ans=0;
	for(i=1;i<=s.size();++i)
		ans=(ans+(ll)G(s.substr(0,i))*F(s.substr(i)))%mod;
	return f[s]=ans;
}
inline int G(string s){
	if(g[s]) return g[s];
	if(s.size()==1) return s[0]=='0'?1:2;
	ri i,j,k,c,ans=0;
	for(i=1;i<s.size();++i)
		if(s.size()%i==0){
			string t;
			for(j=0;j<i;++j){
				c=1;
				for(k=j;c&&k<s.size();k+=i)
					c&=s[k]&15;
				t+=char(c+'0');
			}
			add(ans,F(t));
		}
	return g[s]=ans;
}
int main(){
	cin>>s;
	printf("%d\n",F(s));
	return 0;
}

Measured memory_bytes: 12928
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c){
  sort(c.rbegin(), c.rend());
  vector<ll> ans(N);
  map<ll, vector<ll>> m;
  for(ll i=0; i<N-1; i++) {
    m[a[i]].push_back(b[i]);
    m[b[i]].push_back(a[i]);
  }
  ll r = -1;
  ll e = -1;
  for(auto x : m) {
    // std::cout << x.second.size() << std::endl;
    // std::cout << e << std::endl;
    ll size = x.second.size();
    if(e < size) {
      e = size;
      r = x.first;
    }
  }
  auto it = c.begin();
  ans[r-1] = *(it++);
  queue<ll> q;
  q.push(r);
  set<ll> s;
  while(!q.empty()) {
    ll x = q.front();
    q.pop();
    s.insert(x);
    for(auto y : m[x]) {
      if(s.find(y) != s.end()) continue;
      q.push(y);
      ans[y-1] = *(it++);
    }
  }
  sort(c.begin(), c.end());
  ll sum = 0;
  for(ll i=0; i+1<N; i++)
    sum+=c[i];
  std::cout << sum << std::endl;
  for(ll i=0; i<N; i++) {
    if(i+1 < N) 
      std::cout << ans[i] << " ";
    else
      std::cout << ans[i];
  }
  std::cout << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N-1);
  std::vector<long long> b(N-1);
  for(int i = 0 ; i < N-1 ; i++){
    scanf("%lld",&a[i]);
    scanf("%lld",&b[i]);
  }
  std::vector<long long> c(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&c[i]);
  }
  solve(N, std::move(a), std::move(b), std::move(c));
  return 0;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

int n;
vvi to;

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

    int m;
    cin>>n>>m;
    to = vvi(n, vi(n));
    rep(i, m) {
        int v1, v2;
        cin>>v1>>v2; v1--; v2--;
        to[v1][v2] = 1;
        to[v2][v1] = 1;
    }
    vi perm;
    rep(i, n) perm.push_back(i);
    ll cnt = 0;
    do {
        bool f = true;
        rep(i, n - 1) {
            if (!to[perm[i]][perm[i + 1]]) f = false;
        }
        if (f) cnt++;
    } while(next_permutation(rng(perm)) && perm[0] == 0);

    cout<<cnt<<endl;
}

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

#define pb push_back
#define sz size() 
#define ll long long

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

int main() {
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    
    int n;
    string s;
    cin>>n;
    cin>>s;

    n = s.size();

    int i;
    int nuli = 0;
    for (i=0;i<n;i++)
    if (s[i] == '1') {
        nuli++;
    }

    int n1 = nuli - 1;
    int n2 = nuli + 1;

    ll presm1 = 0;
    ll presm2 = 0;

    for (i=0;i<n;i++)
    if (s[i] == '1') {
        if (n1>0) presm1 += binpow(2, n-i-1, n1);
        presm2 += binpow(2, n-i-1, n2);
    }

    if (n1>0) presm1 %= n1;
    if (n2>0) presm2 %= n2;

    int powBuck[200001];
    memset(powBuck, -1, sizeof(powBuck));

    for (i=0;i<n;i++) {

        int curr=0;

        if (s[i] == '1') {
            
            if (nuli == 1) {
                cout<<"0\n";
                continue;
            }
            if (n1>0) {    
                curr = presm1;
                ll kolku = binpow(2, n-i-1, n1);
                curr = (curr + n1 - kolku) % n1;   
            }
        } else {
            curr = presm2;
            ll kolku = binpow(2, n-i-1, n2);
            curr = (curr + kolku) % n2;
        }

        int br=1;
        while (curr) {

            if (powBuck[curr] == -1)
                powBuck[curr] = __builtin_popcount(curr);

            curr = curr % powBuck[curr];
            br++;
        }
        cout<<br<<"\n";
    }

    return 0;
}

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

int min(int x,int y){
    if(x<y) return x;
    else return y;
}
int main(){
    int n,x,y;
    cin >> n >> x >> y;
    vector<int> answer(n+1,0);
    for(int i=1; i<n; i++){
        for(int j=i+1; j<=n; j++){
            if(i<x&&j<x) answer.at(j-i)++;
            else if(i>y&&j>y) answer.at(j-i)++;
            else if(i<x&&j>y) answer.at(j-y+x-i+1)++;
            else if(i<x&&x<=j&&j<=y) answer.at(min(j-i,y-j+x-i+1))++;
            else if(x<=i&&i<=y&&y<j) answer.at(min(j-i,j-y+i-x+1))++;
            else answer.at(min(j-i,y-j+i-x+1))++;
        }
    }
    for(int i=1;i<n; i++)
    cout << answer.at(i) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
    int A , B , C ,D;
    cin >> A >> B >> C >> D;
    if (A > C) {
        swap(A, C);
        swap(B, D);
    }
    int res = min(B, D) - C;
    if (res <= 0) cout << "0" << endl;
    else cout << res << endl;
    return 0;
}

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

void solve(long long N){
    ll dp[10][10] = {};
    for(int A=1;A<=N;A++){
        string AS = to_string(A);
        // cerr << AS <<"last=" <<AS[AS.size()-1]<< "first=" << AS[0]<<  endl;
        dp[AS[AS.size()-1]-'0'][AS[0]-'0']++;
    }
    // for(int i=0;i<10;i++){
    //     for(int j=0;j<10;j++){
    //         cerr << "i=" <<i<<"j="<<j <<"val=" << dp[i][j] << endl;
    //     }
    // }
    ll ans =0;
    for(int A=1;A<=N;A++){
        if(A%10==0){
            continue;
        }
        string AS = to_string(A);
        ans += dp[AS[0]-'0'][AS[AS.size() -1]-'0'];
        // cerr <<"A=" << A <<"val=" << dp[AS[AS.size()-1]-'0'][AS[0]-'0'] << endl;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int x;
    int y;
    int ans;
    cin >> x >> y;
    ans = x+y/2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <deque>
#include <map>

using namespace std;

const int CMax = 100002;
const int CInf = 2000000001;
const long long CMod = 1000000007;

int n, m;

int gcd(int a, int b)
{
    if (b != 0) return gcd(b, a % b);
    else return a;
}

string baseConverter(int base, int num) {
    string tNum = "";
    while (num > 0) {
        tNum = (char)('0' + num%base) + tNum;
        num /= base;
    }
}

bool isPalindrom(string tS) {
    int sn = (int)tS.length();
    for (int i = 0; i < sn / 2; i++) {
        if (tS[i] != tS[sn - i - 1]) return false;
    }
    return true;
}

int dist(int i, int j) {
    return  (j < i ? n + j : j) - i;
}

long long greatestDivisor(long long a) {
    for (int i = 2; i <= (long long)sqrt(a); i++) {
        if (a % i == 0) return a / i;
    }
    return a;
}

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

    int res = 1, sum = 0, tmp;

    for (int i = 0; i < n; i++) {
        scanf("%d", &tmp);
        sum += tmp;
        if (sum <= m) res++;
    }

    cout << res << endl;
    return 0;
}


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

map<long long int, vector<pair<int, int> > > solns;

int main()
{
	int X;
	scanf("%d", &X);
	
	for(long long int i = -128; i <= 128; i++)
	{
		for(long long int j = -128; j <= 128; j++)
		{
			solns[i * i * i * i * i - j * j * j * j * j].push_back(make_pair(i, j));
		}
	}
	
	pair<int, int> ans = solns[(long long int)X][0];
	printf("%d %d", ans.first, ans.second);
}


Measured memory_bytes: 7452
#include <stdio.h>

int main() {
	int N;
	scanf("%d",&N);
	int A[N], ans[N+1];
	for (int i = 0; i < N; i++) {
		scanf("%d",&A[i]);
		ans[i] = -1;
	}
	ans[N] = -1;
	for (int i = 0; i < N; i++) {
		int point = 0;
		while (1) {
			if (ans[point] < A[i]) {
				ans[point] = A[i];
				break;
			}
			else point++;
		}
	}
	int cnt = 0;
	for (int i = 0; ans[i] != -1; i++) {
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n

for i in range(1, n):
    for j in range(1, k + 1):
        if j == 1:
            dp[i] = dp[i - j] + abs(h[i] - h[i - j])
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[n - 1])

Measured memory_bytes: 52704
#include <stdio.h>

int main() {
	
	int r, g, b, result;
	scanf("%d%d%d", &r, &g, &b);
	
	result = (r*100 + g*10 + b)%4;
	
	if (result == 0) printf("YES");
	else printf("NO");
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#include<math.h>

int main (){
   double a, b, c, d;
   cin >> a >> b >> c;
   d = (a * b *(sqrt(1-((a*a + b*b - c*c)/(2*a*b))*((a*a + b*b - c*c)/(2*a*b)))))/2;
   cout << d << endl;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i,j,N,n=1,d[100];
	
	scanf("%d",&N);
	scanf("%d",&d[0]);
	for(i=1;i<=N-1;i++){
		scanf("%d",&d[i]);
		for(j=0;j<i;j++){
			if(d[i]==d[j]) break;
			if(j==i-1) n++;
		}
	}
	printf("%d",n);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main() {
int N;
std::cin >> N;

for (int i = 0; i < N; i++) {
int a, b, c;
std::cin >> a >> b >> c;
int aa = a * a;
int bb = b * b;
int cc = c * c;
if (aa + bb == cc) std::cout << "YES" << std::endl;
else
if (aa + cc == bb) std::cout << "YES" << std::endl;
else
if (bb + cc == aa) std::cout << "YES" << std::endl;
else
std::cout << "NO" << std::endl;

}


return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)
 
typedef vector<int> vi;
 
int main()
{
    double x1, y1, x2, y2, x3, y3, xp, yp;
    while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF){
        double a1 = (xp-x1)*(y2-y1)-(yp-y1)*(x2-x1);
        bool parity = a1 > 0.0;
 
        double a2 = (xp-x2)*(y3-y2)-(yp-y2)*(x3-x2);
        if(parity ^ (a2 > 0.0)){
            puts("NO");
            continue;
        }
 
        double a3 = (xp-x3)*(y1-y3)-(yp-y3)*(x1-x3);
        puts(parity^(a3>0.0) ? "NO" : "YES");
    }
    return 0;
}

Measured memory_bytes: 1040
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
h, a  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()
if h%a==0:
	print(int(h/a))
else:
  	print(h//a+1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   998244353 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
   string s ;
   cin >> s ;
   if(s[2]==s[3] && s[4]==s[5]){
    cout << "Yes";
   }
   else
        cout << "No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t ;
    t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}
// number of subset having xor in 2ki ow


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
int K;
vector<ll> ans;
void dfs(string s){
    if(s.size() > 10)return;
    ans.push_back(stoll(s));
    int x = s.back() - '0';
    for(int d = -1;d <= 1; d++){
        if(0<=x+d && x+d <= 9){
            s.push_back(char(x + d + '0'));
            dfs(s);
            s.pop_back();
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> K;
    for(int i = 1;i <= 9;i++)dfs(to_string(i));
    sort(all(ans));
    rep(i,10){
    }
    cout << ans[K-1] << endl;
}

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

signed main(){
  
  int n;
  cin>>n;
  
  int x=(n/1000)+1;
  x=x*1000;
  
  if(n%1000==0)
  cout<<0;
  else
  cout<<x-n;
}

Measured memory_bytes: 3620
#include <stdio.h>
int main(int argc, char *argv[])
{
	int n;
	int t;int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&t);
		sum+=t-1;
	}
	printf("%d\n",sum);
		
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

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

    vector<LL> val((1<<N), 0);
    for(int bit=0; bit<(1<<N); bit++)
        for(int i=0; i<N; i++)
            for(int j=0; j<N; j++) {
                if( (bit & (1<<i)) && (bit & (1<<j))  )
                    val[bit] += A[i][j];
            }
            /*
    for(int i=0; i<(1<<N); i++) {
        cout << i << " " << val[i] << endl;

    }*/

    vector<LL> dp((1<<N), 0);
    for(int bit=1; bit<(1<<N); bit++) {
        for(int i=bit; i; i = bit&(i-1))
            dp[bit] = max(dp[bit], dp[bit-i] + val[i]/2);

    }
    cout << dp[(1<<N)-1] << endl;



    return 0;
}

Measured memory_bytes: 1280
A, B, K = list(map(int, input().split()))

i=1
n=100

while i<=K:
  #print(i,n)
  if A%n == 0 and B%n ==0:
    if i==K:
      break
    else:
      i+=1
      n-=1
  else:
    n-=1
print(n)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    int n, h, w;
    cin >> n >> h >> w;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    int ans = 0;
    rep(i, n)
    {
        if (a[i] >= h && b[i] >= w)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  stack<char>c;
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == '0' || s[i] == '1') c.push(s[i]);
    else if(!c.empty()) c.pop();
  }

  string ans;
  while(!c.empty()) {
    ans += c.top(); c.pop();
  }
  reverse(ans.begin(), ans.end());

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


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

#define rep(i,n) for(int i=0, 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;

using namespace std;

int main(void){
    string S;
    cin >> S;
    if(S == "Sunny"){
        cout << "Cloudy" << endl;
    } else if(S == "Cloudy"){
        cout << "Rainy"  <<endl;
    } else cout << "Sunny" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    // 頂点番号，各頂点から出る複数のエッジ
    static List<Edge>[] graph;

    // 最短コスト
    static long mindist[];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int[] dist = new int[N];
        for (int i = 0; i < N; i++) {
            dist[i] = scanner.nextInt();
        }

        graph = new List[N];
        for (int i = 0; i < N; i++) {
            graph[i] = new ArrayList<>();
            if (i <= N - 2) {
                graph[i].add(new Edge(i + 1, Math.abs(dist[i] - dist[i + 1])));
            }
            if (i <= N - 3) {
                graph[i].add(new Edge(i + 2, Math.abs(dist[i] - dist[i + 2])));
            }
        }

//        debug();

        mindist = new long[N];
        solve(0);
        System.out.println(mindist[N - 1]);
    }

    static void solve(int v) {
        Arrays.fill(mindist, Long.MAX_VALUE);
        mindist[v] = 0;

        PriorityQueue<Vertex> pq = new PriorityQueue<>(
                ((v1, v2) -> v1.dist < v2.dist ? -1 : 1)
        );

        pq.add(new Vertex(v, mindist[v]));
        while (!pq.isEmpty()) {
            Vertex now = pq.poll();

            if (now.dist > mindist[now.id]) {
                continue;
            }

            for (Edge edge : graph[now.id]) {
                if (mindist[edge.to] > mindist[now.id] + edge.cost) {
                    mindist[edge.to] = mindist[now.id] + edge.cost;
                    pq.add(new Vertex(edge.to, mindist[edge.to]));
                }
            }
        }

    }

    static void debug() {
        for (int i = 0; i < graph.length; i++) {
            for (Edge edge : graph[i]) {
                System.out.println(i + " -> " + edge.to + ": " + edge.cost);
            }
            System.out.println();
        }
    }
}

// エッジに関するクラス
class Edge {
    int to, cost;

    public Edge(int to, int cost) {
        this.to = to;
        this.cost = cost;
    }
}

// 頂点に関するクラス
class Vertex {
    int id;
    long dist;

    public Vertex(int id, long dist) {
        this.id = id;
        this.dist = dist;
    }
}

Measured memory_bytes: 73268
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int answer = 0;
  rep(i,n-1){
    if(s.at(i) != s.at(i+1)) answer++;
  }
  cout << answer << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    int x; cin >> x;
    for(int i = x ; i <= 100003; i++){
        bool flag = true;
        for(int j = 2; j <= i / 2; j++){
            if(i % j == 0) flag = false;
        }
        if(flag){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

int main(){
while(true){
int i,j,k,n,m,x;
scanf("%d",&n);
scanf("%d",&m);

if(n == 0 && m == 0){
   break;
}

x = 0;
for(i=1;i<n-1;i++){
    for(j=i+1;j<n;j++){
       for(k=j+1;k<n+1;k++){
           if(i+j+k == m){
              x += 1;
          }
        }
      }
   }
printf("%d\n",x);
}
return 0;
}

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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i=0;i<m/2;++i)
        printf("%d %d\n", i+1, m-i);
    for (int i=0;i<(m+1)/2;++i)
        printf("%d %d\n", m+i+1, m+m-i+1);
}


Measured memory_bytes: 3824
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::{max, min};
use std::collections::HashMap;
fn main(){
    input!{
        n:usize,
        an:[i64;n],
    }
    let mut v = vec![];
    for j in 0..n {
        let diff = (an[j] - (j as i64+1));
        v.push(diff);
    }
    v.sort();
    let b = if n % 2 == 0 {
        v[n/2-1]
    } else {
        v[(n+1)/2-1]
    };
    let ans = v.iter().fold(0,|y,x| {
        y + (x-b).abs()
    });
    println!("{}",ans);
}

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

int main() {
	// your code goes here
	int A,B,C;
	cin>>A>>B>>C;
	bool can = false;
	int sum = A;
	for(int i=0;i<B;i++){
		if(sum%B == C){
			printf("YES\n");
			can = true;
			return 0;
		}
		sum+=A;
	}
	if(!can) printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<map>
#define ll long long
#define mod 998244353
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
ll cnt[30],base[30],now[30];
int a[30],mx[30],v[1010];
ll mp[15][15];
int n;
std::map<ll,int>mark;
int vis[maxn];
int dfs(int S,int now,int dep,int n,ll dis)
{
	if(dep==n&&now>S){
		if(mark[dis])return 0;
		mark[dis]=1;
		return 1;
	}
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			vis[i]=1;
			if(!dfs(S,i,dep+1,n,dis+mp[now][i]))return 0;
			vis[i]=0;
		}
	return 1;
}
ll calc(int n)
{
	mark.clear();
	mark[0]=1;
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++){
		vis[i]=1;
		dfs(i,i,1,n,0);
		vis[i]=0;
	}
	return (*(--mark.end())).first;
}
int check()
{
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i==j&&mp[i][j])return 0;
			else if(i!=j&&(mp[i][j]<1||mp[i][j]>1e11))return 0;
	int flag=1;
	mark.clear();
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++){
		vis[i]=1;
		flag&=dfs(i,i,1,n,0);
		vis[i]=0;
	}
	return flag&&calc(n)<=1e11;
}
int main()
{
	n=read();
	int k=1;
	a[0]=0;
	for(int i=1;i<=n;i++){
		while(1){
			int flag=1;
			for(int j=0;j<i;j++)
				if(v[k+a[j]])flag=0;
			if(flag)break;
			++k;
		}
		a[i]=k;
		for(int j=0;j<i;j++)
			v[a[i]+a[j]]=1;
	}
//	 for(int i=1;i<=n;i++)
//	 	printf("%d %d ***\n",i,a[i]);
	for(int i=2;i<=n;i++){
		ll mx=calc(i-1)+1;
		for(int j=1;j<i;j++)
			mp[i][j]=mp[j][i]=mx*a[j];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			writesp(mp[i][j]);
		putchar('\n');
	}
//	puts(check()?"AC":"WA");
	return 0;
}

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

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

  string s(n, '.');
  for(char &c : s) cin >> c;

  vector<vector<int>> G(n);
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  for(int v = 0; v < n; ++v) {
    if(s[v] != '?') continue;

    vector<bool> used(26, false);

    for(const auto &to : G[v]) {
      if(s[to] != '?') {
	used[s[to] - 'a'] = true;
      }
    }

    for(int i = 0; i < 26; ++i) {
      if(!used[i]) {
	s[v] = 'a' + i;
	break;
      }
    }
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 7860
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
 
const int maxN = 1 << 11;
const int mod = 998244353;

template <class T1, class T2> inline void addMod(T1& a, T2 b)	{   a = (a + b) % mod;  }
template <class T1, class T2> inline void multMod(T1& a, T2 b)	{   a = a * b % mod;    }

long long qpow(long long a, long long b)
{
    long long res0 = 1;
    for (; b!=0; b>>=1)
    {
        if (b & 1)  multMod(res0, a);
        multMod(a, a);
    }
    return res0;
}

vector <int> vs[maxN][maxN];
char in[maxN][maxN];
bool can[maxN][maxN], canot[maxN][maxN], meet[maxN][maxN], vis[maxN];
int state[maxN], xr;
vector <int> G[maxN];

void ans(long long a)
{
	printf("%lld\n", a);
	exit(0);
}

void dfs(int v)
{
	xr ^= state[v];
	vis[v] = true;
	for (int u : G[v])
		if (!vis[u])
			dfs(u);
}

long long f(int v, int n, int m)
{
	if (n % 2 == 0)
		return qpow(2, m);
	int comps = 0;
	for (; v<n*2; v+=2) if (!vis[v])
	{
		xr = 0;
		dfs(v);
		if (xr != 0)
			return 0;
		comps++;
	}
	return qpow(2, m - n + comps);
}

void solve()
{
	int n;
	scanf ("%d", &n);
	n++;
	FOR(i, 1, n-1)
		scanf ("%s", &in[i][1]);
		
	FOR(i, 1, n-1)
		vs[i][i].pb(0), vs[i][n-1-i].pb(n-1);
	FOR(v, 1, n-1)
	{
		int j0 = v, j1 = v, d0 = -1, d1 = 1;
		
		FOR(i, 1, n-1)
		{
			j0 += d0, j1 += d1;
			for (int j : {j0, j1})
				vs[i][j].pb(v);
			if (j0 == 0)
				d0 = 1;
			if (j1 == n-1)
				d1 = -1;
		}
	}
	
	FOR(i, 1, n-1) FOR(j, 1, n-1)
	{
		assert(vs[i][j].size() == 2);
		int u = vs[i][j][0], v = vs[i][j][1];
		if (in[i][j] != '?')
			in[i][j] == 'o' ? can[u][v] = can[v][u] = true : canot[u][v] = canot[v][u] = true;
		meet[v][u] = meet[u][v] = true;			
	}
	
	int m0 = 0, m1 = 0;
	FOR(v, 0, n) FOR(u, 0, v)
	{
		if (can[v][u] and canot[v][u])
			ans(0);
		if (!can[v][u] and !canot[v][u] and meet[v][u])
		{
			G[u].pb(v), G[v].pb(u);
			u % 2 ? m1++ : m0++;
		}
		if (can[v][u])
			state[v] ^= 1, state[u] ^= 1;
	}
	
	long long res = f(0, (n+1)/2, m0);
	multMod(res, f(1, n/2, m1));	
	ans(res);
}
 
int main()
{
	int t;
	t = 1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}



Measured memory_bytes: 187520
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
priority_queue<double> pq;
long long n, m, p, ans;
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p; pq.push(p);
	}
	for (int i = 0; i < m; i++) {
		p = pq.top(); pq.pop(); pq.push(p / 2);
	}
	for (int i = 0; i < n; i++) {
		ans += pq.top(); pq.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

void solve() {

}

int main()
{
    IO;
    int n;
    cin>>n;
    unordered_set<string> s;
    for(int i=0;i<n;i++){
        string dr;
        cin>>dr;
        s.insert(dr);
    }
    cout<<s.size()<<endl;
}

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

int main(void){
    int d;
    cin >> d;
    vector<int> c(26);
    for (int i = 0; i < 26; i++) cin >> c.at(i);
    
    vector<vector<int>> s (d, vector<int> (26));
    for(int j = 0; j < d; j++) for(int i = 0; i < 26; i++) cin >> s.at(j).at(i);
    
    int score = 0;
    vector<int> last(26,-1);
    
    for(int i = 0; i < d; i++) {
        int mx = 0;
        for(int j = 0; j < 26; j++) {
         mx = max(mx,s.at(i).at(j));
        }
        score += mx;
        
        int select = 0;
        for(int j = 0; j < 26; j++) {
         if (mx == s.at(i).at(j)) select = j;
        }  
        last.at(select) = i;
        for(int j = 0; j < 26; j++) {
         score -= c.at(j) * (i - last.at(j));
        }
        cout << select+1 << endl;
    }
}


Measured memory_bytes: 3692