akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int Change(int *change, int coin);

int main()
{
	int change;
	int cost;
	int answer;
	while(1){
		scanf("%d", &cost);
		if(cost==0){
			break;
		}
		answer=0;
		change = 1000 - cost;
		answer += Change(&change, 500);
		answer += Change(&change, 100);
		answer += Change(&change, 50);
		answer += Change(&change, 10);
		answer += Change(&change, 5);
		answer += Change(&change, 1);
		printf("%d\n", answer);
	}
	return 0;
}


int Change(int *change, int coin)
{
	int count;
	count = *change / coin;
	*change -= count*coin;
	return count;
}

Measured memory_bytes: 600
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		int[] array = new int[200];
		int max;
		
		Scanner stdin = new Scanner(System.in);
		
		
		
		while (stdin.hasNext()){
			int num = stdin.nextInt();
			array[num]++;
		}
		
		max = 0;
		
		for (int i = 0; i < array.length; i++){
			if (max < array[i])max = array[i];
		}
		
		for (int i = 0; i < array.length; i++){
			if (max == array[i])System.out.println(i);
		}
		
	}
}

Measured memory_bytes: 18136
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 7;
const long long INF = 1e15 + 7;

typedef long long ll;
typedef long double ld;

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

int n, a[N];
ll t[N * 4];

void build (int v, int tl, int tr){
  if (tl == tr) t[v] = a[tl];
  else {
    int tm = tl + tr >> 1;
    build (v * 2, tl, tm);
    build (v * 2 + 1, tm + 1, tr);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
}

ll get (int v, int tl, int tr, int l, int r){
  if (tl > r || tr < l) return 0;
  if (l <= tl && tr <= r) return t[v];
  int mid = tl + tr >> 1;
  return get (v + v, tl, mid, l, r) + get (v + v + 1, mid + 1, tr, l, r);
}

int main (){
  scanf ("%d", &n);
  forn (i, 1, n) scanf ("%d", a + i);
  build (1, 1, n);
  ll mn = INF;
  forn (i, 1, n - 1){
    ll cur = abs(get (1, 1, n, 1, i) - get (1, 1, n, i + 1, n));
    mn = min(mn, cur);
  }
  printf ("%lld\n", mn);
  return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b);
#define mins(a,b) a=min(a,b);
#define max3(a,b,c) max(a,max(b,c)) 
#define mix3(a,b,c) mix(a,mix(b,c))
#define pairi pair<int,int>

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

int main(){
   
    int n;cin>>n;
    vd p(n+1);repa(i,1,n+1)cin>>p[i];
    
    vvd dp(n+1,vd(n+1,0));
    dp[0][0]=1.0;

    int half=(n+1)/2;
    rep(i,n)rep(j,half){
        dp[i+1][j] += dp[i][j]*(1-p[i+1]);
        dp[i+1][j+1] += dp[i][j]*p[i+1];
    }

    // rep(i,n+1)rep(j,n+1)cerr<<"dp["<<i<<"]["<<j<<"] = "<<dp[i][j]<<endl;

    double ans=0;
    rep(i,half)ans+=dp[n][i];
    ans = 1-ans;

    printf("%.10f\n",ans);
    
    return 0;
}

Measured memory_bytes: 70656
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n, k;
	cin >> n >> k;

	vector<ll> a(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
		a[i]--;
	}

	vector<vector<ll>> s(62, vector<ll>(n));
	for (ll i = 0; i < n; i++)
	{
		s[0][i] = a[i];
	}

	for (ll i = 0; i < 60; i++)
	{
		for (ll j = 0; j < n; j++)
		{
			s[i + 1][j] = s[i][s[i][j]];
		}
	}

	ll cur = 0;
	for (ll i = 0; i < 60; i++)
	{
		if ((k >> i) & 1)
		{
			cur = s[i][cur];
		}
	}
	println(cur + 1);
}


Measured memory_bytes: 103300
#include <iostream>
using namespace std;
int main()
{
	int n,r=0,b=0;string s;
	cin>>n>>s;
	for (int i=0;i<s.size();i++)
	{
		if (s[i]=='R') {r++;}
		else {b++;}
	}
	if (r>b) {cout<<"Yes\n";}
	else {cout<<"No\n";}
	return 0;
}

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

using namespace std;

typedef struct{
    double x;
    double y;
}Point;

void koch(int n, Point p1, Point p2){
    if(n == 0) return;

    Point s, t, u;
    s.x = (2 * p1.x + p2.x) / 3;
    s.y = (2 * p1.y + p2.y) / 3;
    t.x = (p1.x + 2 * p2.x) / 3;
    t.y = (p1.y + 2 * p2.y) / 3;
    u.x = (t.x - s.x) / 2 - (t.y - s.y) * sqrt(3) / 2 + s.x;
    u.y = (t.x - s.x) * sqrt(3) / 2 + (t.y - s.y) / 2 + s.y;

    koch(n-1, p1, s);
    cout << s.x << " " << s.y << endl;
    koch(n-1, s, u);
    cout << u.x << " " << u.y << endl;
    koch(n-1, u, t);
    cout << t.x << " " << t.y << endl;
    koch(n-1, t, p2);
}

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

    Point p1, p2;
    p1.x = 0.0;
    p1.y = 0.0;
    p2.x = 100;
    p2.y = 0.0;

    cout << p1.x << " " << p1.y << endl;
    koch(n, p1, p2);
    cout << p2.x << " " << p2.y << endl;

    return 0;
}


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


int main(void) {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for(int i = 0; i < 3; i++) {
        if(S[i] == T[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
N,K,Q=map(int,input().split())
A=[0]*Q
C=[K-Q]*N

for i in range(Q):
    A[i]=int(input())
    C[A[i]-1]+=1
    
for i in range(N):
    if C[i]<=0:
        print('No')
    else :
        print('Yes')

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

using lint = int64_t;
const lint MOD = 1e9 + 7;

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int dist_sq = 0;
            for (int k = 0; k < d; k++) {
                dist_sq += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            for (int k = 0; k * k <= dist_sq; k++) {
                if (k * k == dist_sq) ans++;
            }
        }
    }

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

Measured memory_bytes: 256
#include <cstdio>
int cnt[105],n;
bool check(){
	int mx=n,mn=1;
	for (;!cnt[mx];mx--);
	for (;!cnt[mn];mn++);
	if (mn!=(mx+1)/2 || cnt[mn]!=(mx&1)+1) return 0;
	for (int i=mn+1;i<=mx;i++)
		if (cnt[i]<2) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	if (check()) printf("Possible\n");
		else printf("Impossible\n");
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
int n,temp;
bool f;
while(scanf("%d",&n)!=EOF){
temp=1;
f=true;
while(f){
if(n%(temp*2)!=0){
printf("%d",temp);
n-=temp;
f=false;
}
temp*=2;
}
while(n>0){
if(n%(temp*2)!=0){
printf(" %d",temp);
n-=temp;
}
temp*=2;
}
printf("\n");
}
}

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void func_to_create(){
    uint64_t x;
    cin >> x;
    int year = 0;
    uint64_t current = 100;
    uint64_t diff = x - current;
    while( diff > current / 100){
        year++;
        current = current + current / 100;
        diff = x - current;
        //cout <<  "year " << year << "current : " << current << endl;
    }
    cout << year + 1 << endl;

}
int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    func_to_create();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3652
n = int(input())

# 素因数分解
cf = dict()
for nn in range(1, n+1):
    cf.setdefault(2, 0)
    while nn%2 == 0:
        cf[2] += 1
        nn //= 2

    for f in range(3, int(nn**0.5)+ 1, 2):
        cf.setdefault(f, 0)
        while nn%f == 0:
            cf[f] += 1
            nn //= f
    if nn != 1:
        cf.setdefault(nn, 0)
        cf[nn] += 1

ans = 1
mod = 10**9+7
for v in cf.values():
    ans *= (v+1)
    ans %= mod
print(ans)


Measured memory_bytes: 68428
s = str(input())
L = [753]
for i in range(len(s) - 2):
  a = int(s[i:i + 3])
  L.append(a)
L.sort()
for j in range(len(L)):
  if L[j] == 753:
    if j == len(L) - 1:
      print(L[j] - L[j - 1])
      break
    if j == 0:
      print(L[j + 1] - L[j])
      break
    else:
      if L[j + 1] - L[j] <= L[j] - L[j - 1]:
        print(L[j + 1] - L[j])
      else:
        print(L[j] - L[j - 1])
      break

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    while(true){
        int n,x;
        cin >> n >> x;
        if(n==0 && x==0) break;

        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Colorful Blocks
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 998244353;

/* typedef */

typedef long long ll;

/* global variables */

int fs[MAX_N + 1], invfs[MAX_N + 1];

/* subroutines */

int powmod(int a, int n) {  // a^n % MOD
  int pm = 1;
  while (n > 0) {
    if (n & 1) pm = (ll)pm * a % MOD;
    a = (ll)a * a % MOD;
    n >>= 1;
  }
  return pm;
}

inline int nck(int n, int k) {  // nCk % MOD
  return (ll)fs[n] * invfs[n - k] % MOD * invfs[k] % MOD;
}

inline int nhk(int n, int k) {  // nHk % MOD
  return nck(n + k - 1, k);
}

void prepare_fracs(int n) {
  fs[0] = invfs[0] = 1;
  for (int i = 1; i <= n; i++) {
    fs[i] = (ll)fs[i - 1] * i % MOD;
    invfs[i] = powmod(fs[i], MOD - 2);
  }
}

/* main */

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

  prepare_fracs(n);

  int sum = 0;
  for (int i = 0; i <= k; i++) {
    int d = (ll)m * powmod(m - 1, n - 1 - i) % MOD * nhk(n - i, i) % MOD;
    sum = (sum + d) % MOD;
    //printf("i=%d, d=%d\n", i, d);
  }

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 4716
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int k = sc.nextInt();
    int t = sc.nextInt();

    Queue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

    for (int i = 0; i < t; i++) {
      queue.add(sc.nextInt());
    }

    while (queue.size() > 1) {
      int large1st = queue.remove();
      int large2nd = queue.remove();
      if (large1st > 1) {
        queue.add(large1st - 1);
      }
      if (large2nd > 1) {
        queue.add(large2nd - 1);
      }
    }
    if (queue.isEmpty()) {
      os.println(0);
    } else {
      os.println(queue.remove() - 1);
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

using namespace std;

const int MAX_LIST = 1e6;

typedef struct node {
    unsigned int key;
    struct node *next;
    struct node *prev;
} node_t;

node_t *init(){
    node_t *head = (node_t *)malloc(sizeof(node_t));
    if(head==NULL){ cout << "malloc failed!" <<endl;exit(1);}
    head->next = head;
    head->prev = head;
    head->key = 0;
    return head;
}

void pp_ele(node_t *node){
    cout << "node: "<<node;
    cout << " key: " << node->key;
    cout << " next: " << node->next;
    cout << " prev: " << node->prev << endl;
}

void pp_list(node_t *head){
    node_t *present = head->next;
    if(present == head){ return;}
    do{
        cout << (present)->key;
        present = present->next;
        if(present != head){cout << " ";}
    } while(present != head);
    cout << endl;
}

node_t *listSearch(node_t *head, unsigned int x){
    node_t *ans = head->next;
    while(ans != head){
        if(ans->key == x){return ans;}
        ans = ans->next;
    }
  //  cout << "this key does not exit in this list" <<endl;
    return head;
}

void insert_node(node_t *head, unsigned int x){
    node_t *ele = (node_t *)malloc(sizeof(node_t));
    if(ele==NULL){cout << "malloc failed!" << endl;exit(1);}
    ele->key = x;
    ele->next = head->next;
    (head->next)->prev = ele;
    head->next = ele;
    ele->prev = head;

    return;
}

void delete_node(node_t *head, unsigned int x){
    node_t *delElement = listSearch(head, x);
    if(delElement != head){
        (delElement->prev)->next = delElement->next;
        (delElement->next)->prev = delElement->prev;
        free(delElement);
    }
}

void deleteFirst(node_t *head){
    node_t *temp =head->next;
    head->next = (head->next)->next;
    (head->next)->prev = head;
    free(temp);
}

void deleteLast(node_t *head){
    node_t *temp = head->prev;
    ((head->prev)->prev)->next = head;
    head->prev = (head->prev)->prev;
    free(temp);
}

int main(){

    node_t *head =init();
    int n;
    string command,s;
    unsigned int operand;   
    

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> command;
        if(command.size() <= 6){cin >> operand;}

        if( command[0] == 'i'){
            insert_node(head, operand);
        }else if(command[0] == 'd'){
            if( command.size() > 6){
                if(command[6]== 'F'){
                    deleteFirst(head);
                }else if(command[6]== 'L'){
                    deleteLast(head);
                } 
            }else{
                delete_node(head,operand);
            }
        }
    } 
    pp_list(head);

    return 0;
}



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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        H: usize,
        W: usize,
        h: usize,
        w: usize
    }
    println!("{}", (H-h) * (W-w));
}


Measured memory_bytes: 4352
def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))


N = input_one_number()
A = input_multiple_number_as_list()

ans = [0] * N

for i in A:
 	ans[i-1] += 1

for anss in ans:
 	print(anss)

Measured memory_bytes: 32236
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll h,w;
ll c[10][10];
ll a[210][210];
ll cost[10];
struct edge{/*重み付き,有向*/
    int to , cost;/*toは接続先*/
    edge(ll to_ ,ll cost_ = 1){ to=to_; cost=cost_; };/*全てのcost=1 <=> 無向グラフ*/
};
bool operator<(edge e1 ,edge e2){return e1.cost < e2.cost; }
bool operator>(edge e1 ,edge e2){return e1.cost > e2.cost; }
using graph =  vector< vector<edge> >;
graph g; //for dijkstra
Vi dist; //for dijkstra. distance from start
void dijkstra(ll start){
    dist.resize(g.size()); dist.resize(g.size());
    rep(i,dist.size())dist[i]=INF;
    auto comp_pq = [](pair<ll,ll> x,pair<ll,ll> y){return x.second > y.second;};
    priority_queue< pair<ll,ll> , vector<pair<ll,ll>>, decltype(comp_pq)> pq{comp_pq};
    dist[start]=0; pq.push(mp(start,0));
    while (pq.size()>0){
        PLL p = pq.top();
        pq.pop();
        if(p.second > dist[p.first])continue;
        rep(i,g[p.first].size()){
            if(dist[p.first]!=INF){
                if(chmin(dist[g[p.first][i].to],dist[p.first]+g[p.first][i].cost)){
                    pq.push(mp(g[p.first][i].to,dist[g[p.first][i].to]));
                }
            }
        }
    }
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>h>>w;
    g.resize(10);
    rep(i,10){
        rep(j,10){
            cin>>c[i][j];
            g[j].pb(edge(i,c[i][j]));
        }
    }
    dijkstra(1);
    ll ans = 0;
    rep(i,h){
        rep(j,w){
            cin>>a[j][i];
            if(a[j][i] == -1){

            }else{
                ans += dist[a[j][i]];
            }
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
using namespace std;
#define ll long long int
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pair pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back

void solve()
{
    int n;
    cin >> n;
    cout << (1000-(n%1000))%1000;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}



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

int main()
{
    int n, y;
    cin >> n >> y;
    int sum = 0, k = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            sum = 10000 * i + 5000 * j;
            if (sum > y)
            {
                break;
            }
            k = abs(y - sum) / 1000;
            if (i + j + k == n)
            {
                cout << i << " " << j << " " << k;

                return 0;
            }
        }
    }
    cout << "-1 -1 -1";
    return 0;
}

Measured memory_bytes: 256
PROGRAM-ID.                      ABC_048_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(59).
    01 a       PIC 9(19).
    01 b       PIC 9(19).
    01 x       PIC 9(19).
    01 ans     PIC X(19).

    01 q1      PIC 9(19).
    01 q2      PIC 9(19).
    01 r       PIC 9(19).

    01 ZS      PIC Z(19)9.
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO a b x.

    DIVIDE x INTO a GIVING q1 REMAINDER r.
    DIVIDE x INTO b GIVING q2.

    SUBTRACT q1 FROM q2.
    IF r = 0 THEN
        ADD 1 TO q2
    END-IF.

    MOVE q2 TO ZS.
    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
int cmp(const void* a,const void* b)
{
	int* c=(int*)a;
	int* d=(int*)b;
	return *d-*c;
}
int main()
{
	int a[10];
	int i;
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	qsort(a,10,sizeof(int),cmp);
	printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
	return 0;
}

Measured memory_bytes: 604
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 28, 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;

bool compare(pair<pair<string,int> , int > a , pair<pair<string,int>,int>b){
    if(a.first.ff == b.first.ff){
        return a.ff.ss > b.ff.ss;
    }else{
        return a.first.ff < b.first.ff;
    }
}



auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    int n;
    cin>>n;

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

    rep((int)v.size()){
        int temp;
        string s;
        cin>>s>>temp;
        v[i].ff.ff = s;
        v[i].ff.ss = temp;
        v[i].ss = (i+1);
    }

    sort(all(v),compare);

    for(auto itr : v)
        cout<<itr.ss<<endl;



    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


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

int main() {
  int W, H, x, y, r;
  int safe_min_x, safe_max_x, safe_min_y, safe_max_y;
  cin >> W >> H >> x >> y >> r;
  safe_min_x = r; safe_max_x = W-r;
  safe_min_y = r; safe_max_y = H-r;

  if ((safe_min_x <= x && x <=safe_max_x)&&(safe_min_y <= y && y <= safe_max_y)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint N, M, S;
typedef pair<lint, lint> P;
using edge = pair<lint, P>;
vector<vector<edge> > G;
vector<lint> c, d;
const lint MAX_MONEY = 2500, INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
	if(S >= MAX_MONEY) S = MAX_MONEY;
	vector<vector<lint> > dp(N, vector<lint> (MAX_MONEY + 10, INF));
	priority_queue<pair<lint, P>, vector<pair<lint, P> >, greater<pair<lint, P> > > que;
	dp[0][S] = 0;
	que.push(make_pair(0, P(0 ,S)));
	while(que.size()){
		auto p = que.top(); que.pop();
		lint time = p.first, now = p.second.first, money = p.second.second;
		if(time > dp[now][money]) continue;

		if(money + c[now] <= MAX_MONEY){
			lint ns = money + c[now];
			lint ntime = time + d[now];
			if(chmin(dp[now][ns], ntime)) que.push(make_pair(ntime, P(now, ns)));
		}

		for(auto e : G[now]){
			if(money < e.second.first) continue;
			lint nv = e.first;
			lint ns = money - e.second.first;
			lint ntime = time + e.second.second;
			if(chmin(dp[nv][ns], ntime)) que.push(make_pair(ntime, P(nv, ns)));
		}
	}

	for(lint v = 1; v < N; v++){
		lint ans = INF;
		for(lint s = 0; s <= MAX_MONEY; s++) ans = min(ans, dp[v][s]);
		cout << ans << endl;
	}
}

signed main(){
	cin >> N >> M >> S;
	c.resize(N); d.resize(N); G.resize(N);
	for(lint i = 0; i < M; i++){
		lint u, v, a, b; cin >> u >> v >> a >> b; --u; --v;
		G[u].push_back(edge(v, P(a, b)));
		G[v].push_back(edge(u, P(a, b)));
	}
	for(lint i = 0; i < N; i++) cin >> c[i] >> d[i];
	solve();
}

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

int main() {
  int x[4][13]={{}};
  char a;
  int b,n;
  cin >> n;
  
  

  
  
  for(int i=0; i<n; i++){
    cin >> a >> b;
    b=b-1;
    if(a=='S')
      x[0][b]=1;
    else if(a=='H')
      x[1][b]=1;
    else if(a=='C')
      x[2][b]=1;
    else if(a=='D')
      x[3][b]=1;
  }
  for(int j=0; j<4; j++){
    for(int k=0; k<13; k++){
      if(x[j][k]!=1){
      if(j==0)
        cout << "S " << k+1 << endl;
      else if(j==1)
        cout << "H " << k+1 << endl;
      else if(j==2)
        cout << "C " << k+1 << endl;
      else if(j==3)
        cout << "D " << k+1 << endl;
      }
    }
  }
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a[33];
    int k;
    a[0]=1;
    a[1]=1;
     a[2]=1;
      a[3]=2;
       a[4]=1;
        a[5]=2;
         a[6]=1;
          a[7]=5;
           a[8]=2;
            a[9]=2;
             a[10]=1;
              a[11]=5;
               a[12]=1;
                a[13]=2;
                 a[14]=1;
                  a[15]=14;
                   a[16]=1;
                    a[17]=5;
                     a[18]=1;
                      a[19]=5;
                       a[20]=2;
                        a[21]=2;
                        a[22]=1;a[23]=15;a[24]=2;a[25]=2;a[26]=5;a[27]=4;a[28]=1;a[29]=4;a[30]=1;a[31]=51;

    cin>>k;
    cout<<a[k-1]<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
using namespace std;


int main() {
	priority_queue<int> arr[1000];
	int n,q,t,x;
	int query;
	cin >> n>>q;
	for (int i = 0; i < q; i++)
	{
		cin >> query>>t;
		switch (query)
		{
		case 0:
			cin >> x;
			arr[t].push(x);
			break;
		case 1:
			if (arr[t].size() == 0)
			{
			}
			else
			{
				cout << arr[t].top() << endl;
			}
			break;
		case 2:
			if (arr[t].size() != 0)
			{
				arr[t].pop();
			}

			break;
		}
	}
	

	return 0;
}


Measured memory_bytes: 4100
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define MAGIC cin.tie(NULL); ios_base::sync_with_stdio(false)
#define endl '\n'
//#define ll long long
#define mod (1000000007)
//#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
//#define MCONS 2001
//#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

int gcd(int a, int b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl
int dx[]{0, 1, 0, -1};
int dy[]{1, 0, -1, 0};

//const int NCONS = 3001;
//const int MCONS = 101;

vector<string> vec = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int32_t main()
{
    MAGIC;
    string str; cin >> str;
    
    for(int i = 0; i < vec.size(); i++)
    {
        if(str == vec[i])
        {
            cout << 7 - i;
            return 0;
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 888
arr = []
track = dict()
for _ in range(int(input())) :
    s = input()
    arr.append(s)
for i in arr :
    track[i] = 0
for i in arr :
    track[i]+=1
result = []
for i in track :
    result.append(track[i])
m = max(result)
g = []
for i in track :
    if track[i] == m :
        g.append(i)
g.sort()
for i in g :
    print(i)

Measured memory_bytes: 35220
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for _ in range(n)]
ans = n

for i in range(1,n+1):
	y = 0
	for j in range(1,d+1):
		if j * a[i-1] + 1 <= d:
			y += 1
	ans += y

print(ans + x)

Measured memory_bytes: 3064
/**
 *    Author:  "Robin Singh" !!!
 *    BrainyIsTheNewSexy     (CodeForces)
 *    rob_in_1               (Other OJs)
**/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IO  freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     
#define bk(i, j, k) for(int i = j-1; i >= k; i--)
#define mem(ptr)  memset(ptr, 0, sizeof ptr) 
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vll;
typedef vector < pair<int,int> > vpii;
typedef vector < pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long long INF = (1LL<<61);
const int inf = (1<<30);
const int nn = 1e6+5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends Here!*****************************************************]

int main()
{
    // IO;
    IOS;
    int n; cin >> n;
    if(n==1) cout << "Hello World";
    else {
    	int a, b; cin >> a >> b;
    	cout << a + b;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)/b;
}


int main(void){
    vector<ll>dp(1e5+10);
    ll n,k;
    cin>>n>>k;
    vector<ll>h(n);
    rep(i,n){
        cin>>h[i];
    }
    dp[0]=0;

    for(int i=0;i<n-1;++i){
        ll t=1e10;
        for(int j=0;i-j>=0 && j<k;++j){
            t=min(t,dp[i-j]+abs(h[i+1]-h[i-j]));
        }
        dp[i+1]=t;
    }
    cout<<dp[n-1];
}
/*

*/

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

using namespace std;
using ll = long long int;

ll get_winhand_score(char c, ll R, ll S, ll P) {
    if (c == 'r') {
        return P;
    } else if (c == 's') {
        return R;
    } else {
        return S;
    }
}

int main() {
    ll N, K, R, S, P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    char hands[N];
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (i < K) {
            ans += get_winhand_score(T[i], R, S, P);
            hands[i] = T[i];
        } else {
            if (T[i] == hands[i - K]) {
                hands[i] = '-';
            }else{
                ans += get_winhand_score(T[i], R, S, P);
                hands[i] = T[i];
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Taska solver = new Taska();
        solver.solve(1, in, out);
        out.close();
    }

    static class Taska {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            if (x == y) {
                out.println(0);
                return;
            }
            int d = Math.abs(Math.abs(x) - Math.abs(y));
            int ans = d;
            // make abs equal
            if (Math.abs(x + d) == Math.abs(y)) {
                if ((x + d) != y) ans++;
                out.println(ans);
                return;
            }
            ans++;
            x *= -1;
            if ((x + d) != y) ans++;
            out.println(ans);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 8404
// 2020-07-03 22:37:30
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct mint {
  ll divisor = 1000000007;
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % divisor) {
    if (val < 0) val += divisor;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = divisor, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += divisor;
    u %= divisor;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= divisor) val -= divisor;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += divisor;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % divisor;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % divisor;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
  friend std::string debug_s (mint a) noexcept {
    return std::to_string(a.val);
  }
};

void answer() {
  string k;
  int d;
  cin >> k >> d;
  vector<vector<mint> > dp(2, vector<mint>(d, 0));
  dp[0][0] = 1;
  rep(i, k.size()) {
    vector<vector<mint> > p(2, vector<mint>(d, 0));
    swap(p, dp);
    int c = k[i] - '0';
    rep(smaller, 2) rep(x, d) rep(j, 10) {
      if(!smaller && j > c) continue;
      dp[smaller || j < c][(x + j) % d] += p[smaller][x];
    }
  }
  cout << dp[0][0] + dp[1][0] - 1 << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin>>n;
    int a,b,c;
    a=n%10;
    n=n/10;
    b=n%10;
    n=n/10;
    c=n%10;
    if(a==7||b==7||c==7){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3588
#include"iostream"
using namespace std;
long long java[100], n;
long long memo[101][21];
long long rec(int index, int sum){
  if( sum < 0 || sum > 20) return 0;
  if( memo[index][sum]) return memo[index][sum];
  if( index == n - 1) return sum == java[n - 1];
  return memo[index][sum] = rec( index + 1, sum + java[index]) + rec( index + 1, sum - java[index]);
}
int main(){
  cin >> n;
  for(int i = 0 ; i < n ; i++ ) cin >> java[i];
  cout << rec( 1, java[0]) << endl;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	ll a,b,c,d;
	cin >> a >> b >> c  >> d;
	if(a+b==c+d) cout << "Balanced" << endl;
	else if(a+b>c+d) cout << "Left" << endl;
	else cout << "Right" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	long long n;

	std::cin >> n;

	long long digit_sum = 0;
	long long temp = n;

	while (temp != 0) {
		digit_sum += temp % 10;
		temp /= 10;
	}

	if (n % digit_sum == 0) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n;
    cin>>n;
    vector<int>div;
    int ans=0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            if(i!=1)
                div.push_back(i);
            if(i*i!=n)
                div.push_back(n/i);
        }
    }
    for(int i=1;i*i<=n-1;i++){
        if((n-1)%i==0){
            if(i!=1)
                ans++;
            if(i*i!=n-1)
                ans++;
        }
    }
    for(int i=0;i<div.size();i++){
        int nn=n,k=div[i];
        while(nn%k==0)
            nn/=k;
        if((nn-1)%k==0)
            ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
s = list(input())
s.pop(-1)
while len(s):
    ln = len(s)
    if ln%2 == 0:
        h = int(ln/2)
        lef = s[:h]
        rig = s[h:]
        if lef == rig:
            break
    s.pop(-1)
print(len(s))


Measured memory_bytes: 3060
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 main() {
    input!{
        n: usize,
        p: [usize; n],
    }
    let mut cnt = 0;
    for i in 0..n {
        if p[i] != i + 1 {
            cnt += 1;
        }
    }
    println!("{}", if cnt == 2 || cnt == 0 { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int H,W,K;
vector<string> field;

int main() {
  cin >>H >>W >>K;
  field.assign(H, ""); rep(i, H) cin >>field[i];
  int res = (H-1)*(W-1);

  vector<bool> cut; // 0~H-2行目の後に切り目を入れるかどうか(H-1のあとは切り目を入れるとする)
  vector<vector<int>> whites(2, vector<int>(H, 0));   // 最大Hコある行の領域について、現在何個のホワイトチョコレートが存在するか

  for (int i=0; i<1 << (H-1); i++){ // 横の切れ目の入れ方は2^(H-1)通り
    int ans = 0; // 何回切ったかな
    bool dame = false;
    cut.assign(H, false); cut[H-1] = true;
    rep(j, H-1){
      if ((i >> j) & 1){
        // j行目の後に切り目を入れる
        cut[j] = true; ans++;
      }
    }
    // 多分greedyにやって大丈夫
    whites.assign(2, vector<int>(H, 0));
    int whitemax = 0;
    rep(w, W){
      int hi = 0; // whitesのindex
      int white = 0; // 列wにおける各々の領域のホワイトチョコレート
      rep(h, H){
        white += field[h][w] - '0';
        if (cut[h]){
          // 行で見て次の領域へ
          if (white > K){ dame = true; break; } // 1列でK超えるようじゃこの横の切り方あかんやん
          whites[1][hi] = whites[0][hi] + white;
          chmax(whitemax, whites[1][hi]);
          hi++;
          white = 0;
        }
      }
      if (dame) break;
      // もしwhitemaxがKを超えていれば見たところの左側でカットすべきだったよね
      if (whitemax > K){
        whitemax = 0;
        ans++;
        rep(h, hi){
          whites[0][h] = whites[1][h] - whites[0][h];
          chmax(whitemax, whites[0][h]);
        }
      }else{
        rep(h, hi) whites[0][h] = whites[1][h];
      }
    }
    if (dame) continue;
    chmin(res, ans);
  }
  cout <<res <<endl;
}

// 2^9 = 512


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[1000005][2];
int main(){
for(int i=0;i<1000005;i++)for(int j=0;j<2;j++)dp[i][j]=inf;
dp[0][0]=0;
string s;
cin>>s;
int n=s.size();
reverse(all(s));
for(int i=0;i<n;i++){
   int now=s[i]-'0';
   chmin(dp[i+1][0],min(dp[i][0],dp[i][1])+now);
   chmin(dp[i+1][1],min(dp[i][0]+11-now,dp[i][1]+9-now));
}
cout<<min(dp[n][0],dp[n][1])<<endl;
}

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

int main(){
    int n, k;
    string s;

    cin >> n >> k;
    cin >> s;

    int score = 0;
    for(int i=0;i<n-1;i++){
        if(s.at(i)==s.at(i+1))
            score++;
    }
    int ans = min(score+2*k, n-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
string s;
llint cnt[26];

int main(void)
{
	cin >> n;
	cin >> s;
	
	llint ans = 0;
	for(int i = 0; i < n; i++){
		llint tmp = 1;
		for(int j = 0; j < 26; j++){
			if(s[i] == j+'a') continue;
			tmp *= cnt[j]+1;
			tmp %= mod;
		}
		ans += tmp, ans %= mod;
		cnt[s[i]-'a']++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512