akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

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


int main(){
    long N, M;
    string S,T;

    cin >> N >> M;
    cin >> S >> T;
    long lcdev = gcd(N,M);
    long lcmul = (N * M) / lcdev;
    //printf("%d\n",lcmul);
    
 
    int NGflag = 0;
    //i j 0 0 5 3 10 6
    for(int i = 0; i < lcdev; i++)
    {
        if (S[i*N/lcdev] != T[i*M/lcdev]){
            NGflag = 1;
        }
    }


    if (NGflag == 0){
        cout << lcmul << endl;
    } else {
        cout << "-1" << endl;
    }

}

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

ll ans;
vector<pair<pair<int,int>,pair<int,ll>>> d;
int n,m,q;
void dfs(vector<int> u, int i){
	if(u.size() == n){
		ll count = 0;
		rep(j,q){
			if(u[d[j].first.second] - u[d[j].first.first] == d[j].second.first) count += d[j].second.second;
		}
		ans = max(ans, count);
	}else{
		for (int j = i; j <= m; ++j) {
			u.push_back(j);
			dfs(u,j);
			u.pop_back();
		}
	}
	return ;
}

int main(){
	cin >> n >> m >> q;
	d.resize(q);
	rep(i,q){
		int a,b,c;
		ll e;
		cin >> a >> b >> c >> e;
		a--;
		b--;
		d[i] = make_pair(make_pair(a,b), make_pair(c,e));
	}
	vector<int> v;
	dfs(v, 1);
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m;
double p;
vvi g;

int main(){
	cin>>n>>m>>p;
	g=vvi(n,vi(n));
	p/=100;
	int S=1<<n;
	vi DP(S);
	vd dp(S,1),a(m+1);
	a[0]=1;
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u][v]++;
		g[v][u]++;
		a[i]=a[i-1]*p;
	}
	for(int i=1;i<S;i++){
		int I=0;
		while(!(i&1<<I)) I++;
		int T=i-(1<<I);
		DP[i]=DP[T];
		for(int j=0;j<n;j++) if(g[I][j]&&(i&1<<j)) DP[i]++;
		int J=T&(T-1);
		while(J!=T){
			int U=J+(1<<I);
			dp[i]-=dp[U]*a[DP[i]-DP[U]-DP[i-U]];
			J=T&(J-1);
		}
	}
	cout<<syosu(11)<<dp[S-1]<<endl;
}

Measured memory_bytes: 3300
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    string s;
    int ans = 0;
    cin >> s ;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == '1')
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int n;
    cin >> n;
    vi a(n);

    int sum = 0;
    double av;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    av = (double)sum/(double)n;

    double mind = 100;
    int res = 1000;
    rep(i, n) {
        if(mind > abs((double)a[i]-av)) {
            res = i; 
            mind = abs((double)a[i]-av);
        }
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ans=0
ch=list(map(int,input().split()))
ch.sort()
if m>sum(ch):
  print(n-1)
else:
  sum=0
  i=0
  while sum<m and ans!=n:
    sum+=ch[ans]
    ans+=1
    if sum > m:
      ans-=1
      break
  print(ans)


Measured memory_bytes: 2940
d = list(map(int,input().split()))
at = []
at.append(["."]*(d[1]+2))
for i in range(d[0]):
  at.append(list(input()))
  at[i+1].insert(0,".")
  at[i+1].insert(d[1]+1,".")
at.append(["."]*(d[1]+2))
l = [[1,0],[0,1],[-1,0],[0,-1]]
re = True
op = False
ppp = True
def ao(k, re,op,l,ppp,d):
  for a in range(1,d[0]):
    for b in range(1,d[1]+1):
      for dx,dy in l:
        if k[a][b] =="#" and k[a+dx][b+dy] ==".":
          re = False
        if k[a][b] =="#" and k[a+dx][b+dy] =="#":
          op = True
      if op == True:
        re = True
      if re == False:
        ppp = False
      op = False
      re = True
  if ppp == False:
    return False
  else:
    return True
 
if ao(at,re,op,l,ppp,d) == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 40048
s = str(input())
a, b, c, d = int(s[0]), int(s[1]), int(s[2]), int(s[3])
ans = ""

for op1 in ["+", "-"]:
    for op2 in ["+", "-"]:
        for op3 in ["+", "-"]:
            sum_ = a
            if op1 == "+":
                sum_ += b
            else:
                sum_ -= b
            if op2 == "+":
                sum_ += c
            else:
                sum_ -= c
            if op3 == "+":
                sum_ += d
            else:
                sum_ -= d
            if sum_ == 7:
                ans = "{}{}{}{}{}{}{}=7".format(a, op1, b, op2, c, op3, d)
        if sum_ == 7:
            break
    if sum_ == 7:
        break
print(ans)


Measured memory_bytes: 38256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<=(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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

	int n;
	cin >> n;
	string x;
	cin >> x;
	int res = 0;
	rep(i, 0, n-3) {
		if (x[i] == 'A' && x[i+1] =='B' && x[i+2] == 'C') {
			++res;
		}
	}
	cout << res << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    string a=s[0];
    int cnt = 0;
    int max = 1;
    vector<int> num;
    rep(i, n) if (s[i] == a) {
        cnt++;
    }
    else {
        if (cnt > max) {
            num.clear();
            num.push_back(i-cnt);
            max = cnt;
        }
        else if (cnt == max) {
            num.push_back(i-cnt);
        }
        a = s[i];
        cnt = 1;
        continue;
    }
    if (cnt > max) {
        num.clear();
        num.push_back(n-cnt);
        vector<int> num;
    }
    else if (cnt == max) {
        num.push_back(n-cnt);
    }
    rep(i, num.size()) {
        cout << s[num[i]] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 15224
#include<iostream>
#include<cmath>

int main(){
    int K, S;
    std::cin >> K >> S;

    int counter=0;
    for(int x=0; x<=K; x++){
        for(int y=0; y<=K; y++){
            int z = S - x - y;
            if(0 <= z && z <= K){
                counter++;
            }
        }
    }

    std::cout << counter << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <limits>
#include <type_traits>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a > b)
	{
		swap(a, b);
	}

	if (b - c <= b - a && c - a <= b - a)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//?????????????????°????????????
int getChar(char ch) 
{
    if ( ch == 'A') return 1;
    else if ( ch == 'C') return 2;
    else if ( ch == 'G') return 3;
    else if ( ch == 'T') return 4;
    else return 0;
}

//????????????????????°??????????????????key???????????????
long long getKey(char str[]) 
{
    long long sum = 0, p = 1, i;
    for ( i = 0; i < strlen(str); i++ ) {
        sum += p * (getChar(str[i]));
        p *= 5;
        
    }
    return sum;
}

int h1(int key) 
{
    return key % M;
}

int h2(int key) 
{
    return 1 + (key % (M - 1));
}

int find(char str[])
{
    long long key, i, h;
    key = getKey(str);
    for ( i = 0;; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if ( strcmp(H[h], str) == 0) return 1;
        else if ( strlen(H[h]) == 0) return 0;
        
    }
    return 0;
}

int insert(char str[]) 
{
    long long key, i, h;
    key = getKey(str); //??????????????°????????????
    for ( i = 0; ; i++) {
        h = h1((key) + i * h2(key)) % M;
        if ( strcmp(H[h], str) == 0) return 1;
        else if ( strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}


int main()
{
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for ( i = 0; i < n; i++) {
        scanf(" %s %s", com, str);
        if ( com[0] == 'i' ){
            insert(str);
        } else {
            if ( find(str) ) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
    
}

Measured memory_bytes: 14916
n = int(input())
n1 = 19*5 + 20*5
n2 = 20*10
for _ in range(n):
    y,m,d = map(int,input().split())
    ans = (999-y)//3*(n1*2+n2)
    if (999-y)%3 == 1:
        ans += n2
    elif (999-y)%3 == 2:
        ans += n1+n2
    if y%3 == 0:
        ans += (10-m)*20
    else:
        if m%2 == 0:
            ans += (10-m)//2*39
        else:
            ans += (10-m)//2*39+19
    if m%2 == 0 and y%3 != 0:
        ans += 19-d+1
    else:
        ans += 20-d+1
    print(ans)



Measured memory_bytes: 5592
import java.util.Scanner; // ?????¨?????????????????????

public class Main {
    public static void main(String[] args) {
        // ?????????????????\?????????????????¨?????? sc ??????????????? (???????????????????????????????????????????????°???????????????).
        Scanner sc = new Scanner(System.in);

        // ????????? sc ??? int ?????¨??????????????????.
        int S = sc.nextInt();

        // ??????????¨??????????.
        int h = 0;
        int m = 0;
        int s = 0;
        h = S / (60 * 60);
        S =  S % (60 * 60);
        m = S / 60;
        S =  S % 60;
        s = S;
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 26324
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define xx first
#define yy second

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 2e5+1;

ll maxProductSubarrayOfSizeK(ll A[], int n, int k)
{
    sort(A, A + n);
    ll product = 1;
    if (A[n - 1] == 0 && (k & 1))
        return 0;
    if (A[n - 1] <= 0 && (k & 1)) {
        for (int i = n - 1; i >= n - k; i--)
            product = (product*A[i])%M;
        return product;
    }
    int i = 0;
    int j = n - 1;
    if (k & 1) {
        product = (product*A[j])%M;
        j--;
        k--;
    }
    k >>= 1;
    for (int itr = 0; itr < k; itr++) {
        ll left_product = A[i] * A[i + 1];
        ll right_product = A[j] * A[j - 1];
        if (left_product > right_product) {
            product = (product*(left_product%M))%M;
            i += 2;
        }
        else {
            product = (product*(right_product%M))%M;
            j -= 2;
        }
    }
    return product;
}


int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T=1;
//cin>>T;
while(T--){
int n,k;
cin>>n>>k;
ll arr[n];
for(int i=0;i<n;i++)cin>>arr[i];

cout<<(maxProductSubarrayOfSizeK(arr,n,k)+M)%M<<"\n";
}
return 0;
}

/*_*/


Measured memory_bytes: 5208
use proconio::{input, marker::Usize1};

fn main() {
    input!(n: usize, uv: [(Usize1, Usize1); n - 1]);
    let mut g = vec![vec![]; n];
    for (u, v) in uv {
        g[u].push(v);
        g[v].push(u);
    }
    let mut t = 0;
    let mut dist = vec![];
    for _ in 0..2 {
        let s = t;
        dist = vec![std::u32::MAX; n];
        dist[s] = 0;
        let mut que = std::collections::VecDeque::from(vec![s]);
        loop {
            if let Some(x) = que.pop_front() {
                for &y in &g[x] {
                    if dist[y] == std::u32::MAX {
                        dist[y] = dist[x] + 1;
                        que.push_back(y);
                    }
                }
            } else {
                break;
            }
        }
        t = dist
            .iter()
            .copied()
            .enumerate()
            .max_by_key(|&(_, d)| d)
            .unwrap()
            .0;
    }

    let diam = dist.iter().copied().max().unwrap();
    let mut path = vec![t];
    for d in (0..diam).rev() {
        let y = g[*path.last().unwrap()]
            .iter()
            .copied()
            .find(|&y| dist[y] == d)
            .unwrap();
        path.push(y);
    }

    let mut chunk_sizes: Vec<_> = path.iter().copied().map(|x| g[x].len()).collect();
    *chunk_sizes.first_mut().unwrap() += 1;
    *chunk_sizes.last_mut().unwrap() += 1;
    chunk_sizes.iter_mut().for_each(|x| *x -= 1);
    if chunk_sizes.iter().sum::<usize>() != n {
        println!("-1");
        std::process::exit(0);
    }

    let ans = vec![
        chunk_sizes.clone(),
        chunk_sizes.iter().copied().rev().collect(),
    ]
    .into_iter()
    .map(|chunk_sizes| {
        let pos: Vec<_> = std::iter::once(0)
            .chain(chunk_sizes.into_iter())
            .scan(0, |state, x| {
                *state += x;
                Some(*state)
            })
            .collect();
        let mut ans: Vec<_> = (0..n).collect();
        for i in 0..pos.len() - 1 {
            let l = pos[i];
            let r = pos[i + 1];
            ans[l..r].rotate_left(1);
        }
        ans
    })
    .min()
    .unwrap();

    println!(
        "{}",
        ans.iter()
            .map(|x| (x + 1).to_string())
            .fold("".to_string(), |acc, s| if acc.is_empty() {
                s
            } else {
                acc + " " + s.as_str()
            })
    );
}


Measured memory_bytes: 13580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,p,q,t;
    vector<ll>v;
    deque<ll>dq;
    cin>>p>>q;
    n=p-2*q;
    if(n>0) cout<<n<<endl;
    else cout<<0<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h.at(i);
  vector<vector<ld>> temp(n, vector<ld>(2));
  for (int i = 0; i < n; i++) {
    temp.at(i).at(0) = max(a - t + h.at(i) * 0.006, t - h.at(i) * 0.006 - a);
    temp.at(i).at(1) = i + 1;
  }
  sort(temp.begin(), temp.end());
  cout << temp.at(0).at(1) << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int ans = 0;
    for(int i = 0; i < str.length(); i++) {
      if (str.charAt(i) == '+') ans++;
      else ans--;
    }
    System.out.println(ans);
  }
}


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

struct Card {
  char suit;
  char value;
};

void swap(struct Card A[], int i, int j) {
  Card tmp = A[i];
  A[i] = A[j];
  A[j] = tmp;
}
  

void bubble_sort(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    for (int j = N-1; j > i; j--) {
      if (A[j].value < A[j-1].value) {
        swap(A, j, j-1);
      }
    }
  }
}

void selection_sort(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {    
    int min_j = i;
    for (int j = i+1; j < N; j++) {
      if (A[j].value < A[min_j].value) min_j = j;
    }
    swap(A, i, min_j);
  }
}

void print_card(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool is_stable(struct Card A1[], struct Card A2[], int N) {
  for (int i = 0; i < N; i++) {
    if (A1[i].suit != A2[i].suit) return false;
  }
  return true;
}

int main() {
  Card C_b[36], C_s[36];
  int i, N;

  cin >> N;
  for (i = 0; i < N; i++) cin >> C_b[i].suit >> C_b[i].value;
  for (i = 0; i < N; i++) C_s[i] = C_b[i];

  bubble_sort(C_b, N);
  selection_sort(C_s, N);

  print_card(C_b, N);
  cout << "Stable" << endl;
  print_card(C_s, N);
  if (is_stable(C_b, C_s, N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}    



Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main()
{
    int n;cin >> n;
    long int arr[n],cnt2 = 0,cnt = 0;
    for(int i = 0;i < n;i++)cin >> arr[i];
    for(int i = 0;i < n;i++)
    {
        if(arr[i] >= arr[i+1])cnt++;
        else
        {
            if(cnt2 < cnt)
                cnt2 = cnt;
            cnt = 0;
        }
    }
    cout << cnt2;
    return 0;
}


Measured memory_bytes: 1024
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl;
#define nl cout << endl
#define hello cout << "hello" << endl;
#define sp(x) fixed << setprecision(x)
#define re return

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s) 
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n) 
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}
void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LONG_MIN,minl = LONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	ll n;
	R(n);
	string s;
	while(n > 0)
	{
		if(n%26 == 0)
		{
			s.pb('z');
			n/=26;
			n--;
		}
		else
		{
			s.pb(n%26 -1 + 'a');
			n/=26;
		}
	}
	rev(all(s));
	W(s);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


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

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        Arrays.sort(a);
        int sum = 0;
        for(int w:a) sum+=w;
        sum-=a[n-1];
        String ans = a[n-1]<sum?"Yes":"No";
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    vpl ab(N);
    rep(i, N){
        ll a, b; cin >> a >> b;
        ab[i] = {a,b};
    }
    sort(ALL(ab));
    priority_queue<ll> pq; ll idx = 0;
    ll ans = 0;
    FOR(d, 1, M+1){
        while(idx < N && ab[idx].ff <= d){
            pq.push(ab[idx].ss);
            idx++;
        }
        if(!pq.empty()){
            ans += pq.top(); pq.pop();
        }
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 2936
import math
n, d = map(int, input().split())
coos = []
cnt = 0
chk = 0
for i in range(0, n):
    coo = list(map(int, input().split()))
    coos.append(coo)
for i in range(n-1):
    for j in range(i+1, n):
        chk = 0
        for k in range(d):
            chk += (coos[i][k] - coos[j][k])**2
        chk = math.sqrt(chk)
        if chk.is_integer() == True:
            cnt+=1
        else:
            continue
print(cnt)

Measured memory_bytes: 38512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] test = Console.ReadLine().ToString().Split(' ');
            String n = test[0];
            String x = test[1];
            String y = test[2];

            if(Int32.Parse(x)+Int32.Parse(y) <= Int32.Parse(n)){
                if(Int32.Parse(x) > Int32.Parse(y)){
                    Console.WriteLine("{0} {1}", y,0);
                }else{
                    Console.WriteLine("{0} {1}", x,0);
                }

            }else{
                int min = Int32.Parse(x) + Int32.Parse(y) - Int32.Parse(n);
                if(Int32.Parse(x) > Int32.Parse(y)){
                    Console.WriteLine("{0} {1}", y,min);
                }else{
                    Console.WriteLine("{0} {1}", x,min);
                }

            }
        }
    }
}

Measured memory_bytes: 13140
import java.util.*;
public class Main {
	public static void main(String[] args) {
		B();
	}
	
	// R+X = 2G
	public static void A() {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		System.out.println(2*g-r);
	}
	
	//シミュレート
	public static void B() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ret = 1;
		for(int i=0;i<N;i++) {
			if(ret<K) ret += ret;
			else ret += K;
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void) {

    int n,k,s;
    cin>>n>>k>>s;
    vi v(n);
    rep(i,k)v[i]=s;
    for(int i=k;i<n;i++){
        if(s==1000000000){
            v[i]=1;
        } else {
            v[i]=1000000000;
        }
    }
    rep(i,n-1){
        cout<<v[i]<<" ";
    }cout<<v[n-1]<<endl;

}


Measured memory_bytes: 1664
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

import java.io.BufferedReader;



public class Main{

    public static void main(String[] args) throws IOException {

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int k = sc.nextInt();
        int x = sc.nextInt();

        for (int i = x-k+1; i < (x-k+1) + 2*k -1; i++) {
            out.print(i+" ");
        }

        out.flush();

    }

}



class Scanner {
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream system) {
        br = new BufferedReader(new InputStreamReader(system));
    }

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public char nextChar() throws IOException {
        return next().charAt(0);
    }

    public Long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public boolean ready() throws IOException {
        return br.ready();
    }

    public void waitForInput() throws InterruptedException {
        Thread.sleep(3000);
    }


}



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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  cout << (A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0) ? "YES" : "NO") << endl;
}


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

int main() {
  int N, count;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++)
    cin >> D.at(i);
  
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (D.at(i) == D.at(j))
        D.at(j) = 0;
    }
  }
  
  count = N;
  for (int i = 0; i < N; i++) {
    if (D.at(i) == 0)
      count--;
  }
  
  cout << count;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String...args){
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    switch(n){
      case 1: System.out.println("Hello World"); break;
      case 2: int a = s.nextInt(), b = s.nextInt(); System.out.println(a + b); break;
    }
  }
}

Measured memory_bytes: 21844
#include <stdio.h>
#define inf 10000005
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define Max 105

int n,M[Max][Max];

void dijkstra();

int main(){
  int i,k,c,u,v,j;
  scanf("%d",&n);
  for(i=0; i < n; i++){
    for(j=0; j < n; j++){
      M[i][j]=inf;
    }
  }

  for(i=0; i < n; i++){
    scanf("%d%d",&u,&k);
    for(j=0; j < k; j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }

  dijkstra();

  return 0;
}

void dijkstra(){
  int miniv,i,v,u,d[Max],color[Max];

  for(i=0; i < n; i++){
    d[i]=inf;
   color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;

  while(1){
    miniv=inf;
    u=-1;
    for(i=0; i < n; i++){
      if(miniv >d[i] && color[i] != BLACK){
        u=i;
        miniv=d[i];
      }
    }

    if(u==-1) break;
    color[u]=BLACK;

    for(v=0; v < n; v++){
     if(color[v] != BLACK && M[u][v] != inf){
        if(d[v] > d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          color[v]=GRAY;
        }
      }
    }
  }

  for(i=0; i < n; i++){
    printf("%d ",i);
    if(d[i]==inf){
      printf("1\n");
    }
    else printf("%d\n",d[i]);
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >>x;
  for(int i =x ;i>0;i--){
    for(int j= 2;j<x;j++){
      int sum =j;
      while(sum <=x){
        sum *=j;
        if(sum == i){
          cout << i;
          return 0;
        }
      }
    }
    if(i==1){
      cout << 1;
    }
  }
}

Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL A,B;
	LL ans=0;

	cin >> A >> B;

	if(A - B > 1){
		ans = 2 * A - 1;
	}else if(B - A > 1){
		ans = 2 * B - 1;
	}else{
		ans = A + B;
	}

	cout << ans << endl;

	return 0;

}

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

string S;
int N;

void input() {
    cin >> N;
    cin >> S;
}

void solve() {
    input();
    string tmp = "No";
    int K = N / 2;
    if(N % 2 == 0 && S.substr(0, K) == S.substr(K, K)) tmp = "Yes";
    cout << tmp << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 256
#入力整数1つ
r,g,b,n= (int(i) for i in input().split())       #入力整数横2つ以上

s = 0
for i in range(n//r+1):
    for k in range((n-r*i)//g+1):
        left = n-(r*i+k*g)
        if left%b == 0 and left>=0:s+=1
print(s)


Measured memory_bytes: 2940
#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define N 200010
#define MAX 1000000000000000000
#define MOD 1000000007

#include <stdio.h>

int main (void) {
    int a, b, c;

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

    if ((a == b && b != c) || (b == c && c != a) || (c == a && a != b)) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}



Measured memory_bytes: 1608
#include <iostream>
#include<string.h>
#include<cstdio>
#define M 1046527
#define L 14

using namespace std;

char H[M][L];


int getChar(char ch){
  if (ch == 'A') return 1;
  else if (ch == 'C') return 2;
  else if (ch == 'G') return 3;
  else if (ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) {return key % M;}
int h2(int key) {return 1+(key % (M-1)); }

int hash_f(int key, int i){
    return (h1(key) + i * h2(key)) %M;
}

int find(char str[]){
    long long key = getKey(str);
    
    for(long long i = 0; ; i++){
        long long h = hash_f(key, i);
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}


int insert(char str[]){
  long long key, i;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    long long h = hash_f(key, i);
    if( strcmp(H[h],str) == 0 ) return 1;  //strcmp(str1, str2) はstr1とstr2が等しいなら０を返す関数
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(void){
    // Your code here!
    int n;
    char str[L], com[9];
    for(int i = 0; i < M;i++) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for(int i = 0; i < n;i++){
        scanf("%s %s", com, str);
        
        if(com[0] == 'i'){
            insert(str);
        }else{
            if(find(str)) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 17544
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  int cnt0 = 0, cnt1 = 0;
  REP(i, S.length()) {
    if (i % 2 == 0) {
      if (S[i] == '0') {
        cnt1++;

      } else {
        cnt0++;
      }

    } else {
      if (S[i] == '0') {
        cnt0++;

      } else {
        cnt1++;
      }
    }
  }
  cout << min(cnt0, cnt1);

  return 0;
}

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

const int N = 1e5+10;
int a[N];

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n; i++){
    int A; cin >> A;
    a[A]++;
  }

  int cnt = 0,cnt2 = 0;
  for(int i = 0; i < N; i++){
    if(a[i] == 0) continue;
    if(a[i]%2 == 1) cnt++;
    else cnt2++;
  }
  if(cnt2%2 == 1) cout << cnt + cnt2 - 1 << endl;
  else cout << cnt + cnt2 << endl;

  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;
std::vector<std::vector<LL>>G, memo;

LL dp(LL i, bool f, LL p)
{
	if (memo[i][f] != -1) return memo[i][f];
	LL res1 = (f ? 1 : 0), res2 = 1;
	for (auto v : G[i])
	{
		if (v == p) continue;
		(res1 *= dp(v, false, i)) %= mod;
		(res2 *= dp(v, true, i)) %= mod;
	}
	return memo[i][f] = (res1 + res2) % mod;
}

int main()
{
	LL N;
	in >> N;
	std::vector<LL>x(N - 1), y(N - 1);
	rep(i, N - 1) in >> x[i] >> y[i];

	G.resize(N + 1);
	rep(i, N - 1)
	{
		G[x[i]].push_back(y[i]);
		G[y[i]].push_back(x[i]);
	}

	memo.resize(N + 1);
	rep(i, memo.size()) memo[i].resize(2, -1);
	out << dp(1, true, -1) << std::endl;
}


Measured memory_bytes: 21120
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

int i,j,k,N,M,A[100],X,Y;

int main()
{
  cin>>N>>M;
  X=0;
  for(i=0;i<N;i++)
  {
    cin>>A[i];
    X+=A[i];
  }
  Y=0;
  for(i=0;i<N;i++)
  {
    if(A[i]*4*M>=X)
    {
      Y++;
    }
    
  }
  
  if(Y>=M)
  {
    cout<<"Yes";
  }
  else
  {
    cout <<"No";
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}
//BEGIN CUT HERE
template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    int n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(int l,int r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};
//END CUT HERE
//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string t,p;
  cin>>t>>p;
  using ll = long long;
  const ll MOD = 1e9+7;
  const ll B = 1777771;
  using RH = RollingHash<ll, MOD, B>;
  RH rt(t),rp(p);
  for(int i=0;i<(int)t.size()-(int)p.size()+1;i++){
    if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<"\n";
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 19760
N,Y=map(int,input().split())

for i in range(N+1):
    for j in range(N-i+1):
        ans=10000*(N-i-j)+5000*j+1000*i
        if ans==Y:
            print(N-i-j,j,i)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 65364
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int prime[100000];
bool p[300005]={true};
int cnt=0;

void init(){
  rep(i,300005)p[i]=true;
}

void is_prime(){
  for(int i=2;i<300005;i++){
    if((i%7==1||i%7==6)&&p[i]){
      prime[cnt]=i;
      cnt++;
      for(int j=i;j<300005;j=j+i){
	p[j]=false;
      }
    }
  }    
}

void solve(int n){
  vi v;
  for(int i=0;i<cnt;i++){
    if(n%prime[i]==0){
      v.pb(prime[i]);
    }
    if(n<prime[i])break;
  }
  sort(all(v));
  rep(i,v.size())cout<<" "<<v[i];
  cout<<endl;
}

int main(){
  int n;
  init();
  is_prime();
  /*
  rep(i,100)cout<<prime[i]<<endl;
  return 0;
  */
  while(cin>>n){
    if(n==1)break;
    cout<<n<<":";
    solve(n);
  }
  return 0;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

vector<vector<pair<ll,ll> > > v(222222);

ll dist[2][222222];
ll dp[2][222222];

void dijkstra(int id,int a)
{
	REP(i,222222)dist[id][i] = INF;
	dist[id][a] = 0;
	dp[id][a] = 1;
	
	priority_queue<P,vector<P>,greater<P> > pq;
	
	pq.push(MP(0,a));
	
	while(!pq.empty())
	{
		P p = pq.top();pq.pop();
		int node = p.SE;
		ll dis = p.FI;
		
		if(dist[id][node] < dis)continue;
		
		REP(i,v[node].size())
		{
			int saki = v[node][i].FI;
			int kyo = v[node][i].SE;
			if(dist[id][saki] > dist[id][node] + kyo)
			{
				dist[id][saki] = dist[id][node] + kyo;
				dp[id][saki] = dp[id][node];
				pq.push(MP(dist[id][saki],saki));
			}
			else if(dist[id][saki] == dist[id][node] + kyo)
			{
				dp[id][saki] = (dp[id][saki] + dp[id][node])%MOD;
			}
		}
	}
}

int main()	
{
	ll n,m;cin >> n >> m;
	ll s,t;cin >> s >> t;
	s--;t--;
	vector<pair<pair<ll,ll>,ll > > edge;
	
	REP(i,m)
	{
		ll a,b,d;cin >> a >> b >> d;
		a--;b--;
		v[b].PB(MP(a,d));
		v[a].PB(MP(b,d));
		edge.PB(MP(MP(a,b),d));
	}
	
	dijkstra(0,s);
	dijkstra(1,t);
	
	/*
	SHOW1d(dist[0],n)
	SHOW1d(dp[0],n)
	SHOW1d(dist[1],n)
	SHOW1d(dp[1],n)
	*/
	
	ll ans = dp[0][t]*dp[1][s]%MOD;
	//cout << "ans is " << ans << endl;
	ll kyo = dist[0][t];
	REP(i,n)
	{
		if(dist[0][i] == dist[1][i] && dist[0][i] + dist[1][i] == kyo)
		{
			ll tmp = (dp[0][i]*dp[0][i]%MOD)*(dp[1][i]*dp[1][i]%MOD)%MOD;
		//	cout << "tmp1 is " << tmp << endl;
			ans = (ans + MOD - tmp)%MOD;
		}
	}
	
	REP(i,m)
	{
		ll a = edge[i].FI.FI;
		ll b = edge[i].FI.SE;
		if(dist[0][a] > dist[0][b])swap(a,b);
		if(dist[0][a] + dist[1][b] + edge[i].SE == kyo)
		{
			ll A = dist[0][a];
			ll B = dist[1][b];
			ll C = dist[0][a] + edge[i].SE;
			ll D = dist[1][b] + edge[i].SE;
			if(max(A,B) < min(C,D))
			{
				ll tmp = (dp[0][a]*dp[0][a]%MOD)*(dp[1][b]*dp[1][b]%MOD)%MOD;
			//	cout << "tmp2 is " << tmp << ' ' << a << ' ' << b << endl;
				ans = (ans + MOD - tmp)%MOD;
			}
		}
	}
		
	cout << ans%MOD << endl;
	
	return 0;
}

Measured memory_bytes: 29356
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


const int MAX = 500000, MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

struct rolling_hash64 {
    int n;
    vector<long long> hs, pw;
    rolling_hash64(){}
    rolling_hash64(const string &s) {
        n = s.size();
        hs.assign(n+1,0);
        pw.assign(n+1,0);
        pw[0] = 1;
        for (int i = 0; i < n; i++) {
            hs[i+1] = hs[i]*base+s[i];
            pw[i+1] = pw[i]*base;
        }
    }

    long long hash(int l, int r) { return hs[r]-hs[l]*pw[r-l]; }
    bool match(int l1, int r1, int l2, int r2) { return hash(l1,r1) == hash(l2,r2); }
};

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    vector<ll> ta(n), tb(n);
    rep(i,n) ta[i] = a[i] ^ a[(i+1)%n];
    rep(i,n) tb[i] = b[i] ^ b[(i+1)%n];

    string sa, sb; //2倍文字列
    rep(i,n){
        string tosai = to_string(ta[i]);
        while(tosai.size() < 10) {
            tosai = "0" + tosai;
        }
        sa += tosai;

        string tosbi = to_string(tb[i]);
        while(tosbi.size() < 10) {
            tosbi = "0" + tosbi;
        }
        sb += tosbi;
    }
    rolling_hash ra(sa+sa), rb(sb);
    rep(k,n){
        if (
            ra.hash(k*10, k*10 + n*10, 0) == rb.hash(0, n*10, 0) &&
            ra.hash(k*10, k*10 + n*10, 1) == rb.hash(0, n*10, 1)
        ) {
            cout << k << " " << (a[k] ^ b[0]) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 201488