akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(Math.abs(x-a)>Math.abs(x-b)){
            System.out.println("B");
        }else{
            System.out.println("A");
        }
        }
        
        
    }


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

#define REP(i,n) for(ll i=0;i<(n);i++)
#define REAP(i,a,n) for(ll i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

    ll a,v;
    cin >> a >> v;
    ll b, w;
    cin >> b >> w;

    ll t;
    cin >> t;

    if(a < b){
        ll d = b-a;
        if(d+w*t <= v*t)cout<<"YES\n";
        else cout << "NO\n";
    }else{
        ll d = a-b;
        if(d+w*t <= v*t) cout << "YES\n";
        else cout << "NO\n";
    }
}


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

int main(){

	int a,b,c,k;

	scanf("%d %d %d %d", &a,&b,&c,&k);

	if(abs(a-b) > 1e18){
		printf("Unfair");
		return 0;
	}
	if(k%2)printf("%d", b-a);
	else printf("%d", a-b);

	return 0;
}

Measured memory_bytes: 128
from operator import itemgetter
N=int(input())
jobs=[]
for _ in range(N):
    temp=list(map(lambda x:int(x),input().split()))
    jobs.append((temp[0],temp[1]))

jobs_temp=sorted(jobs,key=itemgetter(0))
jobs_sorted=sorted(jobs,key=itemgetter(1))
now=0
result="No"
for job in jobs_sorted:
    now+=job[0]
    if now>job[1]:
        break
else:
    result="Yes"

print(result)


Measured memory_bytes: 34856
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn print_vec<T: std::string::ToString>(v: &[T]) {
    println!("{}",
        v.iter().map(|e| e.to_string())
         .collect::<Vec<_>>().join(" "));
}

fn main() {
    input! {
        n: usize,
        a: [u32;n]
    }
    print_vec(&a);
    let mut a = a;
    for i in 1..(n as i32) {
        let v = a[i as usize];
        let mut j: i32 = i-1;
        while j >= 0 && a[j as usize] > v {
            a[(j+1) as usize] = a[j as usize];
            j -= 1;
        }
        a[(j+1) as usize] = v;
        print_vec(&a);
    }
}
/* vim:set foldmethod=marker: */



Measured memory_bytes: 5052
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    char moji1[1000], moji2[1000], moji3[1000];
     
    scanf("%s%s", moji1, moji2);
     
    strcpy(moji3, moji1);
    strcat(moji1, moji3);
     
    if(strstr(moji1, moji2) != NULL) printf("Yes\n");
    else printf("No\n");
     
    return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  
	bool app[26];
	for (int i = 0; i < 26; ++i) {
		app[i] = false;
	}
	for (int i = 0; s[i] != '\0'; ++i) {
		app[s[i] - 'a'] = true;
	}
	for (int i = 0; i < 26; ++i) {
		if (!app[i]) {
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,k,q,all=0;
    cin>>n>>k>>q;

    vector<ll> p(n,0);


    rep(i,q){
        ll a; cin>>a;
        p[a-1]++;
        all++;
    }

    rep(i,n){
        if(k+p[i]-all>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3988
def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      cd.append(i)
      if i != n//i:
        cd.append(n//i)
    i += 1
  return cd

N, M = map(int, input().split())
cd = divisor(M)
cd.sort(reverse=True)
for c in cd:
  if M//c>=N:
    print(c)
    break

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;
	int a, b;
	cin>> a>> b;

	b+=b;
	if(b>= a) cout << 0<< endl;
	else cout<< a-b<< endl;
	return 0;
}


Measured memory_bytes: 3656
use std::io::*;
use std::str::FromStr;
use std::cmp::*;

fn main() {
    let n: usize = read();
    let h: Vec<(i64, i64, i64)> = (0..n).map(|_| (read(), read(), read())).collect();

    // 0:a, 1:b, 2:c
    let mut dp: Vec<Vec<i64>> = vec![vec![0; 3]; n+1];
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for i in 0..n {
        for j in 0..3 {
            let po = [h[i].0, h[i].1, h[i].2];
            for k in 0..3 {
                if j == k { continue;}
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + po[j]);
            }
        }
    }
    println!("{}", max(max(dp[n][0], dp[n][1]), dp[n][2]));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 14588
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;
ll N = 1000000;

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cout.setf(ios::fixed); 
	cout.precision(20);

	string s;
	cin >> s;
	if (s.size() % 2 == 1) {
		if (s[0] == s[s.size() - 1])
			cout << "Second" << endl;
		else cout << "First" << endl;
	}
	else {
		if (s[0] == s[s.size() - 1])
			cout << "First" << endl;
		else cout << "Second" << endl;
	}
	return 0;
}

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

int N;
vector<int> H;

int main() {
  cin>>N;
  H.resize(N);
  rep(i,N) cin>>H[i];
  int ans = 0;
  int ans_tmp = 0;

  int bef = -1;
  rep(i,N) {
    if (H[i] > bef) {
      if (ans_tmp > ans) ans = ans_tmp;
      ans_tmp = 0;
    } else {
      ans_tmp++;
    }
    bef = H[i];
  }
  if (ans_tmp > ans) ans = ans_tmp;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string.h>
#include <bits/stdc++.h> 
using namespace std;
// main() is where program execution begins.

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

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

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < 26; i++){
        for (int j = 0; j < 15; j++){
            int sum = 4*i + 7*j;
            if (sum == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


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

using namespace std;

const int MX = 200005;

typedef long long ll;
typedef pair<int, int> pii;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct NODE
{
	int pre, nxt, wl, wr;

	NODE () {pre = nxt = wl = wr = 0;}
};

ll ans;
NODE chn[MX];
int n, m;
priority_queue<pii, vector<pii>, greater<pii> > que;

void link(int a, int b)
{
	chn[a].nxt = b;
	chn[b].pre = a;
}

bool near(int a, int b)
{
	return (chn[a].nxt == b);
}

void input()
{
	read(n), read(m);
	for(int i=1; i<=n; i++)
	{
		int x;
		read(x);
		chn[i].wl = chn[i].wr = 1;
		link(i, i+1);
		que.push(make_pair(x, i));
	}
}

void calc(int x, vector<int> pos)
{
	int suml = 0;
	for(int i=0; i<pos.size(); i++)
	{
		if(i-m+1 >= 0) suml += chn[pos[i-m+1]].wl;
		ans += 1ll*suml*chn[pos[i]].wr;
	}
	if(pos.size() / m)
	{
		vector<NODE> new_node(pos.size() / m);
		for(int i=0; i<pos.size(); i++)
		{
			if(i >= m-1) new_node[(i+1)/m-1].wr += chn[pos[i]].wr;
			if(pos.size()-i >= m) new_node[new_node.size()-(pos.size()-i)/m].wl += chn[pos[i]].wl;
		}
		suml = 0;
		for(int i=0; i<new_node.size(); i++)
		{
			if(i-m+1 >= 0) suml += new_node[i-m+1].wl;
			ans -= 1ll*suml*new_node[i].wr;
		}
		for(int i=0; i<new_node.size(); i++)
		{
			chn[pos[i]].wl = new_node[i].wl;
			chn[pos[i]].wr = new_node[i].wr;
			que.push(make_pair(x+1, pos[i]));
		}
		link(pos[new_node.size()-1], chn[pos.back()].nxt);
	}
	else link(chn[*pos.begin()].pre, n+1), link(0, chn[pos.back()].nxt);
}

void work()
{
	while(!que.empty())
	{
		int curx = que.top().first;
		vector<int> pos, subpos;
		while(!que.empty() && que.top().first==curx) pos.push_back(que.top().second), que.pop();
		for(auto i : pos)
		{
			if(subpos.empty() || near(subpos.back(), i)) subpos.push_back(i);
			else calc(curx, subpos), subpos.clear(), subpos.push_back(i);
		}
		calc(curx, subpos);
	}
	printf("%lld\n", ans+n);
}

int main()
{
	input();
	work();
	return 0;
}


Measured memory_bytes: 7920
import math 
A, B, H, M = map(int,input().split())

timeHr = H + (M / 60)
angVelA = (1/6) * 180
angVelB = (2) * 180

degA = (angVelA * timeHr)
degB = (angVelB * timeHr) 

degDiff = math.radians(abs(degB - degA))

disX_2 = math.pow(B, 2) + math.pow(A, 2) - (2 * A * B * math.cos(degDiff))
disX = math.sqrt(disX_2)

print(disX)

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

const int MAX = 200000;

int main(){
    int n, a[MAX];
    cin >> n;
    rep(i,n) cin >> a[i];
    int broken_brick = 0;
    int brick_index = 1;
    for(int i = 0; i < n; i++){
        if(a[i] == brick_index){
            brick_index++;
        }else{
            broken_brick++;
        }
    }

    if(broken_brick == n){
        cout << -1 << endl;
    }else{
        cout << broken_brick << endl;
    }
}

Measured memory_bytes: 1024
import math

class SegmentTree:
    def __init__(self, n, max=float('inf')):
        self.N = 1 << math.ceil(math.log(n, 2))
        self.MAX_VAL = max
        self.tree = [self.MAX_VAL] * (self.N << 1)

    def update(self, idx, val):
        idx += self.N
        self.tree[idx] = val
        while idx > 1:
            self.tree[idx >> 1] = val = min(val, self.tree[idx ^ 1])
            idx >>= 1

    def find_min(self, frm, to, k=0, left=0, right=0):
        if right <= frm or to <= left:
            return self.MAX_VAL
        if frm <= left and right <= to:
            return self.tree[k]
        mid = (left + right) / 2
        return min(self.find_min(frm, to, k*2, left, mid),
                   self.find_min(frm, to, k*2+1, mid, right))

n, q = map(int, input().split())
st = SegmentTree(n, (1 << 31) - 1)
for _ in range(q):
    com, n1, n2 = map(int, input().split())
    if com == 0:
        st.update(n1, n2)
    else:
        print(st.find_min(n1, n2+1, 1, 0, st.N))



Measured memory_bytes: 8768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll mod=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
struct mint {
  ll x; // typedef long long ll;
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x*=2;
  return x;
}
mint choose (int n,int a) {
  mint x = 1,y =1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x /y;
}
int main(void){
    // Your code here!
    int a,b; cin >> a >> b;
  	if (a != 1 && b!=1) cout << 1 << endl;
    if (a != 2 && b!=2) cout << 2 << endl;
  	if (a != 3 && b!=3) cout << 3 << endl;
}



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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

struct Edge {
    int from, to, cost;
    Edge(int from = 0, int to = 0, int cost = 0) : from(from), to(to), cost(cost) {}
};

int solve(const vector<Edge>& E, int n, int s, int t) {
    vll cost(n, LLONG_MIN);
    cost[s] = 0;

    rep(i, 0, 2 * n) {
        for (Edge e : E) {
            if (cost[e.from] != LLONG_MIN && cost[e.to] < cost[e.from] + e.cost) {
                cost[e.to] = cost[e.from] + e.cost;
                if (i >= n - 1) { cost[e.to] = LLONG_MAX / 100; }
            }
        }
    }
    if (cost[t] == LLONG_MAX / 100) { return -1; }
    return max((ll)0, cost[t]);
}

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

    int n, m, p;
    cin >> n >> m >> p;

    vector<Edge> E;
    rep(_, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        E.emplace_back(a - 1, b - 1, c - p);
    }

    cout << solve(E, n, 0, n - 1) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int
main ()
{
  int a, b;
  while (true)
    {
      cin >> a >> b;
      if (a == 0 && b == 0)
	break;
      if (a > b)
	swap (a, b);
      cout << a << " " << b << endl;
    }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a, b, n;
    cin >> a >> b >> n;
    if (n < b){
        cout << a*n/b-a*(n/b) << endl;
    }else{
        cout << a*(b-1)/b-a*((b-1)/b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    long long N,x;
    cin >> N >> x;
    int a[100] = {};
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a,a+N);
    int ans = 0;
    for(int i=0;i<N;i++){
        x = x-a[i];
        if(x>=0){
            ans++;
        }
    }
    if(x>0){
        ans--;
    }
    cout << ans << endl;
    
    return 0;
}



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

using namespace std;

struct Node{
    int l, r, idx;
};

int N, M;
Node seg[400005];
int dp[100005], par[100005];

void build(int l, int r, int idx){
    seg[idx].l = l, seg[idx].r = r;
    if(l == r){
        seg[idx].idx = l;
        return;
    }
    int mid = l+r>>1;
    build(l, mid, 2*idx);
    build(mid+1, r, 2*idx+1);
    seg[idx].idx = seg[2*idx].idx;
}

void upd(int p, int idx){
    if(seg[idx].l == seg[idx].r){
        return;
    }
    int mid = seg[idx].l + seg[idx].r >> 1;
    if(p <= mid){
        upd(p, 2*idx);
    }
    else{
        upd(p, 2*idx+1);
    }
    if(dp[seg[2*idx].idx] <= dp[seg[2*idx+1].idx]){
        seg[idx].idx = seg[2*idx].idx;
    }
    else{
        seg[idx].idx = seg[2*idx+1].idx;
    }
}

int query(int l, int r, int idx){
    if(seg[idx].l == l && seg[idx].r == r){
        return seg[idx].idx;
    }
    int mid = seg[idx].l + seg[idx].r >> 1;
    if(r <= mid){
        return query(l, r, 2*idx);
    }
    else if(l > mid){
        return query(l, r, 2*idx+1);
    }
    else{
        int p = query(l, mid, 2*idx), q = query(mid+1, r, 2*idx+1);
        return (dp[p] <= dp[q] ? p : q);
    }
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;
    build(0, N, 1);
    char x;
    cin >> x;
    for(int i = 1; i<=N; i++){
        char c;
        cin >> c;
        if(c == '0'){
            int k = query(max(0, i-M), i-1, 1);
            dp[i] = dp[k] + 1;
            par[i] = k;
        }
        else{
            dp[i] = INT_MAX/2;
        }
        upd(i, 1);
    }
    if(dp[N] >= INT_MAX/2){
        cout << -1 << "\n";
        return 0;
    }
    stack<int> stk;
    int c = N;
    while(c){
        stk.push(c-par[c]);
        c = par[c];
    }
    while(stk.size()){
        cout << stk.top() << " ";
        stk.pop();
    }
}


Measured memory_bytes: 4940
#!/usr/bin/env python3
from sys import setrecursionlimit
setrecursionlimit(10**8)
INF = float("inf")


def main():

    T = int(input())
    for _ in range(T):
        N, A, B, C, D = map(int, input().split())
        memo = {0: 0, 1: D}

        def f(n):
            memo[n] = n*D
            ans = memo[n]
            for cost, p in zip((A, B, C), (2, 3, 5)):
                d, m = divmod(n, p)
                if d not in memo:
                    f(d)
                if d+1 not in memo:
                    f(d+1)
                ans = min(ans, memo[d] + cost + m*D)
                ans = min(ans, memo[d+1] + cost + (p-m)*D)
            memo[n] = ans
            return ans
        print(f(N))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 11560
H, W=list(map(int, input().split()))
S=[['.']*(W+2)] + [['.']+list(input())+['.'] for _ in range(H)] + [['.']*(W+2)]

def canPaint(h,w):
  if '#' in [S[h][w-1], S[h-1][w], S[h][w+1], S[h+1][w]]:
    return True
  else:
    return False

for h in range(1, H+1):
  for w in range(1, W+1):
    if S[h][w]=='#' and not canPaint(h,w):
      print('No')
      exit()
else:
  print('Yes')
  
      
    

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	long long int a[2*100000+10];
	int i=0,n,max=-1;
	long long int cou=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	
	for(i=0;i<n;i++){
		max=(max>a[i])?max:a[i];
		cou+=max-a[i];
	}
	
	printf("%lld",cou);	
}

Measured memory_bytes: 3264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <queue>
#include <fstream>
#include <iterator> // std::back_inserter
#include <chrono>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <float.h>
 
using namespace std;
 
int main(int argc, char *argv[])
{
    int a[5];

    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

    int ans=10000;
    int t = 0;

    for(int i=0; i<5; i++){
        for(int j=0; j<5; j++){
            if(i==j) t += a[j];
            else if(a[j] % 10 == 0) t += a[j];
            else t += ((a[j] / 10) + 1) * 10; 

            //cout << t;
        }
        if(ans > t) ans = t;
        t=0;
        //cout << "¥n";
    }

    cout << ans;

 
    return 0;
}


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

int s[4]={10,50,100,500};
int n,t[4],u[4],maxm,ans[4];

int calc(int x){
  int res=0;
  for(int i=3;i>=0;i--){
    res+=x/s[i];
    x%=s[i];
  }
  return res;
}

void solve(int pos,int cnt,int sum){
  if(pos==4){
    if(sum<n)return;
    cnt-=calc(sum-n);
    if(cnt<=maxm)return;
    for(int i=0;i<4;i++)ans[i]=u[i];
    maxm=cnt;
    return;
  }
  for(int i=0;i<=t[pos];i++){
    u[pos]=i;
    solve(pos+1,cnt+i,sum+i*s[pos]);
  }
}

int main(){
  cin>>n;
  while(1){
    for(int i=0;i<4;i++)cin>>t[i];
    maxm=-(1e9);
    solve(0,0,0);
    for(int i=0;i<4;i++){
      if(ans[i]==0)continue;
      cout<<s[i]<<" "<<ans[i]<<endl;
    }
    cin>>n;
    if(n==0)break;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
from itertools import product as pd

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
for i, j in pd(range(1 << h), range(1 << w)):
    temp = 0
    for x, y in pd(range(h), range(w)):
        if 1 << x & i and 1 << y & j:
            if c[x][y] == "#":
                temp += 1
    ans += temp == k
print(ans)

Measured memory_bytes: 9196
N = int(input())
strDict = {} 
for i in range(N):
    inStr = input()
    inList = []
    for j in range(len(inStr)):
        inList.append(inStr[j])
        inList.sort()
    sortStr = ''.join(inList)
    if sortStr in strDict:
        strDict[sortStr] = strDict[sortStr] + 1
    else:
        strDict[sortStr] = 1

anaglam = 0

for i in strDict.keys():
    anaglam = anaglam + strDict[i]*(strDict[i]-1)//2
    
print(anaglam)

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;

const string YES = "Yes";
const string NO = "No";

void solve()
{
  ll N;
  scanf("%lld",&N);
  if ((N/10)%111==0||(N%1000)%111==0) cout << YES << endl;
  else cout << NO << endl;
}

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


Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int maxn = (int)1e5;
vector <int> dp(maxn+5,-1);
vector <int> adj[(int)1e5+5];
int dfs(int x)
{
	if(dp[x]!=-1)
		return dp[x];
	int ans=0;
	for(int i=0;i<adj[x].size();i++)
	{
		ans=max(dfs(adj[x][i])+1,ans);
	}
	return dp[x]=ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin >> x >> y;
		adj[x].push_back(y);
	}
	int ans=-1;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,dfs(i));
	}
	cout << ans;
}

Measured memory_bytes: 8192
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(s;stdin.byLine())
    {
        string i;
        foreach(c;s)
        {
            switch(c)
            {
            case ' ': i~="101";break;
            case'\'': i~="000000";break;
            case ',': i~="000011";break;
            case '-': i~="10010001";break;
            case '.': i~="010001";break;
            case '?': i~="000001";break;
            case 'A': i~="100101";break;
            case 'B': i~="10011010";break;
            case 'C': i~="0101";break;
            case 'D': i~="0001";break;
            case 'E': i~="110";break;
            case 'F': i~="01001";break;
            case 'G': i~="10011011";break;
            case 'H': i~="010000";break;
            case 'I': i~="0111";break;
            case 'J': i~="10011000";break;
            case 'K': i~="0110";break;
            case 'L': i~="00100";break;
            case 'M': i~="10011001";break;
            case 'N': i~="10011110";break;
            case 'O': i~="00101";break;
            case 'P': i~="111";break;
            case 'Q': i~="10011111";break;
            case 'R': i~="1000";break;
            case 'S': i~="00110";break;
            case 'T': i~="00111";break;
            case 'U': i~="10011100";break;
            case 'V': i~="10011101";break;
            case 'W': i~="000010";break;
            case 'X': i~="10010010";break;
            case 'Y': i~="10010011";break;
            case 'Z': i~="10010000";break;
            default: assert(false);break;
            }
        }
        i~='0'.repeat().take((5-i.length%5)%5).array();
        string t;
        foreach(c;0..i.length/5)
        {
            int v=0;
            foreach(b;i[c*5..(c+1)*5]) v=(v<<1)+(b-'0');
            t~="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[v];
        }
        writeln(t);
    }
}

Measured memory_bytes: 1236
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt64(scanner) - 1
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)
	c := getNextInt64(scanner)
	d := getNextInt64(scanner)

	x := b - a
	if x < 0 {
		x = -x
	}

	ans := "NO"
	for i := n; i >= n-i; i-- {
		if i*c-(n-i)*d <= x && x <= i*d-(n-i)*c {
			ans = "YES"
			break
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        int s = new Scanner(System.in).nextInt();
        int i = 0;
        List<Integer> a = new ArrayList<>();
        for (int j = s; !a.contains(j); i++) {
            a.add(j);
            j = j % 2 == 0 ? j / 2 : j * 3 + 1;
        }
        System.out.println(i + 1);
    }
}

Measured memory_bytes: 23124
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,i,a[nmax],j,t,cur,ans;
map<int,int>mp;
int main()
{
    //freopen("sol.in","r",stdin);
    //freopen("sol.out","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	mp[a[i]-1]++;
	}
	sort(a+1,a+n+1);
	for(i=n;i>=1;i--)
	{
		if(mp[a[i]-1]<=0)continue;
		mp[a[i]-1]--;
		for(j=31;j>=0;j--)
		{
			if(a[i]&(1<<j))break;
			cur|=(1<<j);
		}
		t=j,cur=0;
		for(;j>=0;j--)
		{
			if(!(a[i]&(1<<j)))cur|=(1<<j);
		}
		for(j=31;j>=t;j--)
		{
			if(mp[cur]>0)
			{
				mp[cur]--;
				mp[a[i]-1]--;
				ans++;
				break;
			}
			cur^=(1<<j);
		}
		mp[a[i]-1]++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 48640
def gcd(a,b):
    if b==0 or a == 0  : return a + b
    return gcd(b, a%b)
N = int(input())
d1 = {}
d2 = {}
zero = 0
for _ in range(N):
    A,B = map(int, input().split())
    if A == 0 and B == 0 :
        zero += 1
        continue
    d = gcd(abs(A), abs(B))
    A,B = A//d, B//d
    if B < 0 or (B==0 and A < 0):
        A,B = -A,-B
    if A > 0 :
        if (A,B) not in d1:d1[(A,B)]=0
        d1[(A,B)]+=1
    else :
        if (A,B) not in d2:d2[(A,B)] = 0
        d2[(A,B)] += 1
ret = []
for (x,y),count in d1.items():
    if (-y, x) in d2 :
        ret.append((count, d2[(-y,x)]))
    else :
        ret.append((count, 0))
for (x,y),count in d2.items():
    if (y,-x) not in d1:
        ret.append((count, 0))
mod = 10 ** 9 + 7
ans = 1
for p,q in ret:
    if q == 0 :
        ans *= 2**p
        ans %= mod
    else :
        ans *= (2**p + 2**q -1 )
        ans %= mod
print( (ans - 1 + zero ) % mod )

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    // int MAX = 403;
    int h, w;
    cin >> h >> w;
    
    char m[h*w];
    rep(i, h*w){
        cin >> m[i];
    }

    UnionFind uf(h*w);
    
    rep(i,h*w){
        if(i%w != 0 && m[i]!=m[i-1]){
            uf.unite(i-1, i);
        }
        if(i>=w && m[i]!=m[i-w]){
            uf.unite(i-w, i);
        }
    }

    int c[h*w] = {0};
    int s[h*w] = {0};
    rep(i,h*w){
        if(m[i]=='.'){
            c[uf.root(i)]++;
        }else{
            s[uf.root(i)]++;
        }
    }

    ll sum = 0;
    rep(i,h*w){
        sum += (ll)c[i] * (ll)s[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 2304
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int n, m, a[100000 + 5];
pair<int, int > p[100000 + 5];
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= m; ++i) scanf("%d%d", &p[i].second, &p[i].first), p[i].second = -p[i].second, p[i].first = -p[i].first;
	sort(p + 1, p + 1 + m);
	int now = 1;
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= -p[i].second; ++j) {
			if (now > n) break ;
			if (-p[i].first < a[now]) break ;
			a[now] = -p[i].first;
			++now;
		}
	}
	LL ans = 0;
	for (int i = 1; i <= n; ++i) ans += a[i];
	cout << ans;
	return 0;
}

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

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> S(N);
    for(int i = 0; i < M; ++i){
        int k;
        cin >> k;
        for(int j = 0; j < k; ++j){
            int s;
            cin >> s;
            --s;
            S[s] |= 1<<i;
        }
    }
    int P = 0;
    for(int i = 0; i < M; ++i){
        int p;
        cin >> p;
        P |= p<<i;
    }
    int ans = 0;
    for(int s = 0; s < (1<<N); ++s){
        int t = 0;
        for(int i = 0; i < N; ++i){
            if(s >> i & 1){
                t ^= S[i];
            }
        }
        if(t == P){
            ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;
 
void insert(int A[],int n,int g){
  int i,j,v;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
      A[j+g]=v;
  }
}
 
void shellsort(int A[],int n){
  int i,j;
  for(i=1;;){
    if(i>n)break;
    G.push_back(i);
    i=3*i+1;
  }
  for(j=G.size()-1;j>=0;j--){
    insert(A,n,G[j]);
  }
}
int main(){
  int i,j;
 
  cin >> n;
  for(i=0;i<n;i++){
    cin >> A[i];
  }
  cnt=0;
   
  shellsort(A,n);
 
  cout<<G.size()<<endl;
  for(i=G.size()-1;i>=0;i--){
    cout << G[i];
    if(i){
    cout << " ";
    }
  }
  cout << endl;
  cout << cnt<<endl;
 
  for(i=0;i<n;i++){
    cout << A[i]<< endl;
  }
}

Measured memory_bytes: 7032
#include <iostream>

int main() {
    int n, d, x; std::cin >> n >> d >> x;
    d--;
    for (int i = 0; i < n; i++) {
        int v; std::cin >> v;
        x += 1 + (d / v);
    }
    std::cout << x << std::endl;
    return 0;
}

Measured memory_bytes: 3232
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(li[K-1])

Measured memory_bytes: 38256
def main():
  from heapq import heappush,heappop,heapify
  inf=2**31-1
  n,m,*t=map(int,open(0).read().split())
  z=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    z.extend([a,b,a+n*c,b+n*c])
  z={i:v for v,i in enumerate(sorted(set(z)))}
  try:
    z[1]
  except:
    print(-1)
    exit()
  edge=[[]for _ in range(len(z))]
  d={}
  l=[]
  for a,b,c in zip(t[::3],t[1::3],t[2::3]):
    if b<a:a,b=b,a
    i,j,x,y=z[a],z[b],z[a+n*c],z[b+n*c]
    if b==n:
      l.append(y)
    edge[i].append((1,x))
    edge[j].append((1,y))
    edge[x].extend([(0,i),(0,y)])
    edge[y].extend([(0,j),(0,x)])
  used=[False]+[True]*~-len(z)
  d=[0]+[inf]*~-len(z)
  edgelist=edge[0]
  heapify(edgelist)
  while edgelist:
    m=heappop(edgelist)
    if not used[m[1]]:
      continue
    d[m[1]]=m[0]
    used[m[1]]=False
    for e in edge[m[1]]:
      if used[e[1]]:
        heappush(edgelist,(e[0]+m[0],e[1]))
  a=min([d[i]for i in l]or[inf])
  print([a,-1][a==inf])
if __name__=='__main__':
  main()

Measured memory_bytes: 178068
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    int A,B,C;
    int N,M,K,X,Y,W,H;
    int ans;
    string S;
    int temp[100]={0};
    bool f=false;
    bool fir=true;

int main(){
    cin>>A>>B>>C;
    for(int i=1;i<=B;i++){
        if(((i*A)%B)==C){
            f=true;
            break;
        }
    }
    f?cout<<"YES":cout<<"NO";

    return 0;

}


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

int main()
{
	int A, B, K; cin >> A >> B >> K;
	int count = 0;
	for (int i = 100;; i--) {
		if (A%i == 0 and B%i == 0) {
			count++;
			if (count == K) {
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int array[100];
  int i, j, k, v;
  int n;

  scanf("%d", &n);
  if(n < 1 || n > 100)
    return 0;

  for(i = 0; i < n; i++){
    scanf("%d", &array[i]);
    if(array[i] < 0 || array[i] > 1000)
      return 0;
  }


  for(i = 0; i < n-1; i++)
    printf("%d ", array[i]);
  printf("%d\n", array[n-1]);


  for(i = 1; i < n-1; i++){
    v = array[i];
    j = i-1;
    while(j >= 0 && array[j] > v){
      array[j+1] = array[j];
      j--;
    }
    array[j+1] = v;


    for(k = 0; k < n-1; k++)
      printf("%d ", array[k]);
    printf("%d\n", array[n-1]);

  }

  v = array[n-1];
  j = n-2;
  while(j >= 0 && array[j] > v){
    array[j+1] = array[j];
    j--;
  }
  array[j+1] = v;

  if(n > 2){
    for(i = 0; i < n-1; i++)
      printf("%d ", array[i]);
    printf("%d\n", array[n-1]);
  }

  return 0;

}

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

void putChars(int n, char c) { rep(i, n) cout << c; }

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int h = ty - sy;
    int w = tx - sx;

    // 1往復目
    putChars(w, 'R');
    putChars(h, 'U');
    putChars(w, 'L');
    putChars(h, 'D');

    // 2往復目
    putChars(1, 'D');
    putChars(w + 1, 'R');
    putChars(h + 1, 'U');
    putChars(1, 'L');
    putChars(1, 'U');
    putChars(w + 1, 'L');
    putChars(h + 1, 'D');
    putChars(1, 'R');
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(void) {
	string S;
	cin >> S;
	if (S[0] == 'R') {
		if (S[1] == 'R') {
			if (S[2] == 'R') {
				cout << "3" << endl;
			}
			else {
				cout << "2" << endl;
			}
		}
		else {
			cout << "1" << endl;
		}
	}
	else if (S[1] == 'R') {
		if (S[2] == 'R') {
			cout << "2" << endl;
		}
		else {
			cout << "1" << endl;
		}
	}
	else if (S[2] == 'R') {
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int h,w; cin >> h >> w;
    int x,y; cin >> x >> y;
    cout << h*w - (x*w + y*h - x*y) << endl;
    return 0;
}


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

int main() {
  int n;
  int s = 0;
  cin >> n;
  while(n >= 500){
  	n -= 500;
    s += 1000;
  }
  while(n >= 5){
  	n -= 5;
    s +=5;
  }
  cout << s << endl;
}

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

using ll = long long;


// <expr> := <term> | <expr> <op1> <term>
// <term> := <term2> | <term> <op2> <term2>
// <term2> := <fact> | <term2> <op3> <fact>
// <fact> := (<expr>) | <number>

ll number(string const& s, int& p);
ll expr(string const& s, int& p, vector<vector<char>> const& op);
ll term(string const& s, int& p, vector<vector<char>> const& op);
ll term2(string const& s, int& p, vector<vector<char>> const& op);
ll fact(string const& s, int& p, vector<vector<char>> const& op);

ll number(string const& s, int& p) {
    ll res = 0;
    while(isdigit(s[p])) {
        res *= 10;
        res += s[p++] - '0';
    }
    return res;
}

ll expr(string const& s, int& p, vector<vector<char>> const& op) {
    ll v1 = term(s, p, op);
    while(find(op[0].begin(), op[0].end(), s[p]) != op[0].end()) {
        char o = s[p++];
        ll v2 = term(s, p, op);
        if(o == '+') {
            v1 += v2;
        } else if(o == '-') {
            v1 -= v2;
        } else {
            v1 *= v2;
        }
    }
    return v1;
}

ll term(string const& s, int& p, vector<vector<char>> const& op) {
    ll v1 = term2(s, p, op);
    while(find(op[1].begin(), op[1].end(), s[p]) != op[1].end()) {
        char o = s[p++];
        ll v2 = term2(s, p, op);
        if(o == '+') {
            v1 += v2;
        } else if(o == '-') {
            v1 -= v2;
        } else {
            v1 *= v2;
        }
    }
    return v1;
}

ll term2(string const& s, int& p, vector<vector<char>> const& op) {
    ll v1 = fact(s, p, op);
    while(find(op[2].begin(), op[2].end(), s[p]) != op[2].end()) {
        char o = s[p++];
        ll v2 = fact(s, p, op);
        if(o == '+') {
            v1 += v2;
        } else if(o == '-') {
            v1 -= v2;
        } else {
            v1 *= v2;
        }
    }
    return v1;
}

ll fact(string const& s, int& p, vector<vector<char>> const& op) {
    if(isdigit(s[p])) {
        return number(s, p);
    }
    ll res = expr(s, ++p, op);
    ++p;
    return res;
}

int main() {
    string s;
    cin >> s;
    ll res = numeric_limits<ll>::min();
    for(int i=0; i<3; ++i) {
        for(int j=0; j<3; ++j) {
            for(int k=0; k<3; ++k) {
                int p = 0;
                vector<vector<char>> op(3);
                op[i].push_back('+');
                op[j].push_back('-');
                op[k].push_back('*');
                res = max(res, expr(s, p, op));
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3192
#include <iostream>
using namespace std;
int N, M, a[15], b[15], c[15], x[109]; bool vis[15][109][109], dp[15][109][109];
bool solve(int pos, int l, int r) {
	if (r - l == 1) return x[l] == a[pos];
	if (vis[pos][l][r]) return dp[pos][l][r];
	for (int i = l + 1; i <= r - 1; ++i) {
		if (solve(b[pos], l, i) && solve(c[pos], i, r)) {
			dp[pos][l][r] = true;
		}
	}
	vis[pos][l][r] = true;
	return dp[pos][l][r];
}
int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> x[i];
	cin >> M;
	for (int i = 0; i < M; ++i) cin >> a[i] >> b[i] >> c[i], --b[i], --c[i];
	bool ans = solve(0, 0, N);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3308
N,Q = map(int,input().split())
S = input()
list = [list(map(int,input().split())) for i in range(Q)]

comu = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        comu[i+1] = comu[i] + 1
    else:
        comu[i+1] = comu[i]

for l,r in list:
    print(comu[r-1]-comu[l-1])

Measured memory_bytes: 30664
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define j1 j1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int S; cin>>S;

  bool yymm=false;
  bool mmyy=false;

  int ue=S/100;
  int sita=S%100;

  if(sita>=1 and sita<=12) yymm=true;
  if(ue>=1 and ue<=12) mmyy=true;

  string st;
  if(yymm and mmyy) st="AMBIGUOUS";
  if(!yymm and mmyy) st="MMYY";
  if(yymm and !mmyy) st="YYMM";
  if(!yymm and !mmyy) st="NA";

  cout<< st<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    string s;
    cin>>s;
    for (int i=0;i<s.length();i++){
        int kl=s[i]-'A';
        kl=(kl+x)%26;
        cout<<(char)(kl+'A');
    }
    return 0;
}


Measured memory_bytes: 256