akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535
#define EPS (1e-10)

int main()
{
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for(ll i = 0; i < a; i++) cin >> p[i];
    for(ll i = 0; i < b; i++) cin >> q[i];
    for(ll i = 0; i < c; i++) cin >> r[i];
    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());
    ll ans = 0;
    ll pi = 0, qi = 0, ri = 0;
    for(ll i = 0; i < x + y; i++){
        if(ri >= c){
            if(pi < x && qi < y){
                if(p[pi] > q[qi]){
                    ans += p[pi];
                    pi++;
                }else{
                    ans += q[qi];
                    qi++;
                }
            }else if(pi >= x){
                ans += q[qi];
                qi++;
            }else{
                ans += p[pi];
                pi++;
            }
        }else{
            if(pi < x && qi < y){
                if(r[ri] >= p[pi] && r[ri] >= q[qi]){
                    ans += r[ri];
                    ri++;
                }else if(p[pi] >= r[ri] && p[pi] >= q[qi]){
                    ans += p[pi];
                    pi++;
                }else{
                    ans += q[qi];
                    qi++;
                }
            }else if(pi >= x && qi < y){
                if(q[qi] > r[ri]){
                    ans += q[qi];
                    qi++;
                }else{
                    ans += r[ri];
                    ri++;
                }
            }else if(pi < x && qi >= y){
                if(p[pi] > r[ri]){
                    ans += p[pi];
                    pi++;
                }else{
                    ans += r[ri];
                    ri++;
                }
            }
        }
    }



    cout << ans << endl;

}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int main()
{
	int n;
	cin>>n;
	int i = 3;
	while(i<=n)
	{
		a[i] = -1;
		i = i + 3;
	}
	i = 5;
	while(i<=n)
	{
		a[i] = -1;
		i = i + 5;
	}

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

	
	return 0;
}

Measured memory_bytes: 7416
#include <bits/stdc++.h>
#define DBG
#define MAX_N 100000

using ll = long long;

ll penas[MAX_N] = {0};
ll acs[MAX_N] = {0};
bool ac_flgs[MAX_N];

using namespace std;

int main(){
  for (int i = 0; i < MAX_N; i++){
    ac_flgs[i] = false;
    acs[i] = 0;
    penas[i] = 0;
  }
  int n, m;
  cin >> n >> m;
  cin.ignore();

  if(m == 0){
    cout << 0 << " " << 0 << endl;
    return 0;
  }

  string s;
  int tmp;
  vector <int> p;
  vector <bool> r;

  for(int i = 0; i < m; i++){
    // デバッグ用
    cin >> tmp >> s;
    cin.ignore();
    p.push_back(tmp);
    if(s == "AC"){
      r.push_back(true);
    } else if(s == "WA"){
      r.push_back(false);
    } else {
#ifdef DBG
      cout << "i = " << i << ", Error! s = " << s << endl;
      return 0;
#endif
    }
    --tmp; // 0-origin
    if((s == "WA") && (ac_flgs[tmp] == false)){
      ++penas[tmp];
    } else if(s == "AC"){
      ac_flgs[tmp] = true;
    }
  }

  ll sum_ac = 0, sum_pena = 0;
  for (int i = 0; i < n; i++){
    if(ac_flgs[i] == true) ++sum_ac;
    if(ac_flgs[i] == true) sum_pena += penas[i];
  }

  cout << sum_ac << " " << sum_pena << endl;
  return 0;
}
    


Measured memory_bytes: 2556
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;

int main() {
    long long N;
    unordered_map<string, long long> search_table;
    cin >> N;
    for (long long i = 0; i < N; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (search_table.count(s) != 0) {
            search_table[s]++;
        } else {
            search_table[s] = 1;
        }
    }
    long long count = 0;
    for (auto itr = search_table.begin(); itr != search_table.end(); itr++) {
        if (itr->second != 1) {
            count += itr->second * (itr->second - 1) / 2;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 7328
#include <bits/stdc++.h>
#define ll long long int
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {
    fast();
    ll t;
    cin>>t;
    ll k,x,cnt=0;
    cin>>k;
    for(ll i=0;i<t;i++)
    {
        cin>>x;
        if(x>=k)
        cnt++;
    }
    cout<<cnt<<endl;
}

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

// AGC 012 A
int main() {
  int N;
  int a[300000];
  cin >> N;
  for (int i = 0; i < 3 * N; i++) cin >> a[i];

  sort(a, a + 3 * N, greater<int>());
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    sum += a[2 * i + 1];
  }
  cout << sum << endl;
}


Measured memory_bytes: 1408
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] S = Console.ReadLine().Split(' ')
                                         .Select(val => int.Parse(val))
                                         .ToArray();
        int q = int.Parse(Console.ReadLine());
        int[] T = Console.ReadLine().Split(' ')
                                         .Select(val => int.Parse(val))
                                         .ToArray();
        int cnt = 0;
        int i = 0;
        Array.Sort(T);
        for(int j = 0; j < q; j++)
        {
            while(i < n - 1 && S[i] < T[j]) i++;
            if(i < n && S[i] == T[j]) {
                cnt++;
                i++;
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 21096
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int temp=n;
  int mod;
  int sum=0,mul=1;
  while(temp)
  {
    mod=temp%10;
    if(mod==9)
      sum+=1*mul;
    else
      sum+=9*mul;
    temp/=10;
    mul*=10;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			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();
			}
			
			int b = a[0];
			int res = 1;
			
			for(int i=0;i<=n;i++) {
				if(b==2) {
					System.out.println(res);
					return;
				}
				
				b =a[b-1];
				res++;
			}
			
			System.out.println("-1");
			
		}

	}

Measured memory_bytes: 50680
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int dp[50][500][500];

int main(){
    int N,Ma,Mb; cin >> N >> Ma >> Mb;
    vector<int> a(N),b(N),c(N);
    rep(i,N){
        cin >> a[i] >> b[i] >> c[i];
    }
    int ans = INF;
    rep(i,50)rep(j,500)rep(k,500) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep(i,N)rep(j,500)rep(k,500){
        if(j-a[i] >= 0 && k-b[i] >= 0) dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j-a[i]][k-b[i]]+c[i]);
        dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
        if(j*Mb == k*Ma && j != 0 && k != 0) ans = min(ans,dp[i+1][j][k]);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


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

using namespace std;

int main(){
    string weather; cin >> weather;
    
    if(weather.at(0)=='S') cout << "Cloudy" << endl;
    if(weather.at(0)=='C') cout << "Rainy" << endl;
    if(weather.at(0)=='R') cout << "Sunny" << endl;
    
}



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

int main()
{
  int64_t n,k;
  cin>>n>>k;
  
  int64_t a=0;
  int64_t b=0;
    a=n%k;
  	
    b=a-k;
    if(b<0)
      b=b*(-1);
  
  cout<<min(a,b)<<endl;
}

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

typedef long long ll;

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0);


int main()
{
  ll a, b, pb ;
  cin >> a >> b ;

  if(a < b) {
    pb = a ;
    b-- ;
    while(b--) {
      a = a * 10 + pb ;
    }
    cout << a << endl ;
  }
  else {
    pb = b ;
    a-- ;
    while(a--) {
      b = b * 10 + pb ;
    }
    cout << b << endl ;
  }
}


Measured memory_bytes: 256
a,b,k = map(int, input().split())
while True:
    if k == 0:
        break

    if (a % 2) == 1:
        a = a - 1
    b = b + (a / 2)
    a = a / 2
    k = k - 1

    if k == 0:
        break

    if (b % 2) == 1:
        b = b - 1
    a = a + (b / 2)
    b = b / 2
    k = k - 1

a = int(a)
b = int(b)

print("{0} {1}".format(str(a), str(b)))

Measured memory_bytes: 38384
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: usize = iterator.next().unwrap().parse().unwrap();
    let mut b: usize = 100;
    let mut ans: usize = 0;
    while b < x {
        b += b / 100;
        ans += 1;
    }

    return ans.to_string();
}


Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <cmath>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

using namespace std;

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

    int64_t n;
    cin >> n;
    
    vector<char> ss;
    
    if(n == 0)
    {
        ss.push_back('0');
    }
    else
    {
        while(n != 0)
        {
            ss.push_back(n % -2 == 0 ? '0' : '1');
            n = n / -2 + (n % -2 == -1 ? 1 : 0);
        }
    }
    
    for(auto c = ss.rbegin(); c != ss.rend(); ++c)
    {
        cout << *c;
    }   
    cout << '\n';

    return 0;
}


Measured memory_bytes: 760
N,K=map(int,input().split())
k=0

cnt=[0 for _ in range(10**5)]
for j in range(N):
    a,b=map(int,input().split())
    cnt[a-1]+=b

for i in range(10**5):
    k+=cnt[i]
    if k>=K:
        print(i+1)
        break

Measured memory_bytes: 5928
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

const int N=20;
const int S=1<<N;
const int mod=1000000007;

int n,sz,x,y,m,ans;
int dp[S],g[N],cnt[S],bin[S];

void init(){
	int i,j;
	for (i=0;i<=sz;i++)
		for (j=0;j<n;j++) if ((i>>j)&1) cnt[i]++;
}

int main(){
	int i,s,ss,u,w;
	bin[0]=1; for (i=1;i<S;i++) bin[i]=2ll*bin[i-1]%mod;
	scanf("%d%d",&n,&m); sz=(1<<n)-1;
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y); x--; y--;
		g[x]|=1<<y;
	}
	init();
	dp[0]=1;
	for (s=1;s<=sz;s++) if ((s&1)==((s>>1)&1)){
		for (ss=s;ss;ss=(ss-1)&s) if ((ss&1)==((ss>>1)&1)){
			u=ss^s; w=1;
			for (i=0;i<n;i++) if ((s>>i)&1){
				if ((u>>i)&1) w=1ll*w*(bin[cnt[g[i]&ss]]-1)%mod;
				else w=1ll*w*bin[cnt[g[i]&u]]%mod;
			}
			(dp[s]+=1ll*dp[u]*w%mod)%=mod;
		}
	}
	ans=(bin[m]-dp[sz]+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

ll K;
ll a;
ll ans = -1;

int main() {
    cin >> K;
    rep(i, K) {
        a = ((a * 10) % K + 7) % K;
        //cout << a << endl;
        if (a % K == 0) {
            ans = i + 1;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
import math

N = int(input())
A = []
for j in range(N): 
    A.append([int(i) for i in input().split()])
    
for engine in A:
    engine.append(math.degrees(math.atan2(engine[1], engine[0])))

if len(A)==1:
    print(math.sqrt(A[0][0]**2 + A[0][1]**2))
    exit()

A.sort(key=lambda x: x[2])

A = A + A

mx = 0
for i in range(N):
    X = A[i][0]
    Y = A[i][1]
    temp = 0
    for j in range(i+1, i+N):
        if (math.sqrt(X**2 + Y**2)) > mx:
            mx = math.sqrt(X**2 + Y**2)
        X = X + A[j][0]
        Y = Y + A[j][1]
        #print(i, j, math.sqrt(X**2 + Y**2))
        if temp> math.sqrt(X**2 + Y**2):
            break
        temp = (math.sqrt(X**2 + Y**2))
        if (math.sqrt(X**2 + Y**2)) > mx:
            mx = math.sqrt(X**2 + Y**2)

print(mx)

Measured memory_bytes: 40048
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 3e5 + 100, OO = 1e16, T = 4500 + 100, M = 1e9 + 7, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
int dp[N], a[N], b[N], seg[4][N << 2], lazy[4][N << 2], sum[N];

void shift(int id, int c) {
	seg[id][c << 1] += lazy[id][c];
	seg[id][c << 1 | 1] += lazy[id][c];
	lazy[id][c << 1] += lazy[id][c];
	lazy[id][c << 1 | 1] += lazy[id][c];
	lazy[id][c] = 0;
}

void upd(int id, int c, int b, int e, int l, int r, int x) {
	if(r <= b || e <= l)
		return;
	if(l <= b && e <= r) {
		seg[id][c] += x;
		lazy[id][c] += x;
		return;
	}
	int mid = (b + e) >> 1;
	shift(id, c);
	upd(id, c << 1, b, mid, l, r, x), upd(id, c << 1 | 1, mid, e, l, r, x);
	seg[id][c] = min(seg[id][c << 1], seg[id][c << 1 | 1]);
}

int get(int id, int c, int b, int e, int l, int r) {
	if(r <= b || e <= l)
		return OO;
	if(l <= b && e <= r)
		return seg[id][c];
	int mid = (b + e) >> 1;
	shift(id, c);
	return min(get(id, c << 1, b, mid, l, r), get(id, c << 1 | 1, mid, e, l, r));
}

int32_t main() {
	use_fast;
	int n, e, t, h = 0;
	cin >> n >> e >> t;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	upd(1, 1, 0, n + 1, 0, 1, -2 * a[1]);
	for(int i = 1; i <= n; i++) {
		upd(1, 1, 0, n + 1, 0, i, 3 * (a[i] - a[i - 1]));
		upd(2, 1, 0, n + 1, 0, i, a[i] - a[i - 1]);
		if(i == 1) {
			dp[1] = t + a[1];
			upd(1, 1, 0, n + 1, i, i + 1, dp[i] - 2 * (a[i + 1] - a[i]));
			upd(2, 1, 0, n + 1, i, i + 1, dp[i]);
			continue;
		}
		while(2 * (a[i] - a[h]) >= t)
			h++;
//		cout << get(2, 1, 0, n + 1, h - 1, i) << endl;
		dp[i] = min(t + get(2, 1, 0, n + 1, h - 1, i), get(1, 1, 0, n + 1, 0, h - 1));
		upd(1, 1, 0, n + 1, i, i + 1, dp[i] - 2 * (a[i + 1] - a[i]));
		upd(2, 1, 0, n + 1, i, i + 1, dp[i]);
	}
	cout << e - a[n] + dp[n] << endl;
    return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



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

typedef long long ll;
ll n, a = 2, b = 1, t;
int main()
{
	cin >> n;
	if (n == 1) {cout << "1"; return 0;}
	n--;
	while (n--) {
		t = a + b;
		a = b;
		b = t;
	}
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int [][] A = new int[n][m];
		int [] 	c = new int[n];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
					A[i][j] = sc.nextInt();
			}
		}
		
		for(int i = 0; i < m; i++){
			int b = sc.nextInt();
			for(int j = 0; j < n; j++){
				c[j] += A[j][i] * b;
			}
		}
        for (int i = 0; i < n; i++) {
            System.out.println(c[i]);
        }
	}
}


Measured memory_bytes: 40736
#include <stdio.h>

int main() {
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	for (int i = 0; i < 2; i++) {
    for (int j = 2; j > i; j--) {
      if (a[j-1] > a[j]) {
        int temp = a[j-1];
        a[j-1] = a[j];
        a[j] = temp;
      }
    }
	}
	if(a[2] == (a[1] + a[0])){printf("Yes\n");} else {printf("No\n");}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int D; cin >> D;
    if(D % 9){
        Out(0);
        return 0;
    }
    D /= 9;
    int ans = 0;
    int dmax = 18;
    vec pow10(dmax + 1, 1);
    REP(i, dmax) pow10[i + 1] = pow10[i] * 10;
    FOR(d, 2, dmax + 1){
        vec v;
        REP(i, d) if(d - 1 - i > i) v.pb((pow10[d - 1 - i] - pow10[i]) / 9);
        //debug(d);
        //vdebug(v);
        
        int t = 1, D0 = D;
        REP(i, SZ(v)){
            assert(D0 % pow10[i] == 0);
            int k = ((D0 / pow10[i]) % 10 + 10) % 10;
            if(k != 0 && D0 < 0) k -= 10;
            D0 -= k * v[i];
            int tmp = 0;
            REP(a, 10) REP(b, 10){
                if(i == 0 && a == 0) continue;
                if(b - a == k) tmp++; 
            }
            t *= tmp;
        }
        if(d % 2) t *= 10;
        if(D0 == 0) ans += t;
    }
    Out(ans);

    return 0;
}


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

typedef long long ll;
const int N = 2e5 + 10;

void solve() {
	int n;
	scanf("%d", &n);
	int t = n / 1000 * 1000 + (n % 1000 > 0) * 1000;
	t -= n;
	printf("%d\n", t); 	
}

int main()
{
	int T = 1;
	//scanf("%d", &T);
	while(T--) {
		solve();
	}
}

Measured memory_bytes: 3824
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, M;
    cin >> N >> M;
    P A[N];
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        A[i] = P(a, b);
    }
    sort(A, A + N);

    int ret = 0;
    int num = 0;
    for (int i = 0; i < N; i++) {
        if (num >= M) break;

        if (num + A[i].second <= M) {
            ret += A[i].first * A[i].second;
            num += A[i].second;
        } else {
            int remain = M - num;
            ret += A[i].first * remain;
            break;
        }
    }
    cout <<ret << endl;
    return 0;
}

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

using namespace std;

int main()
{
	vector<int> v;
	int a, b, c, i;
	scanf("%d %d %d", &a, &b, &c);
	
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	
	sort(v.begin(), v.end());
	
	for(i = 0; i < v.size()-1; i++)
	{
		printf("%d ", v[i]);
	}
	printf("%d\n", v[i]);
	
	return 0;
}


Measured memory_bytes: 3252
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();//500
        int b = sc.nextInt();//100
        int c = sc.nextInt();//50

        int x = sc.nextInt();
//        int a = 2;
//        int b = 2;
//        int c = 2;
//
//        int x = 100;

        int cnt = 0;
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    int total = i * 500 + j * 100 + k * 50;
                    if(total == x){
                        cnt += 1;
                    }
                }
            }
        }


        System.out.println(cnt);

    }
}


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

using namespace std;

int main() {
  int n;
  bool f = false;
  while (cin >> n, n) {
    if (f) cout << endl;
    f = true;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int anscnt = 1e9;
    vector<int> ans(5, 0);
    for (int i = 0; i <= a; i++) {
      for (int j = 0; j <= b; j++) {
        for (int k = 0; k <= c; k++) {
          for (int l = 0; l <= d; l++) {
            int mm = 10 * i + 50 * j + 100 * k + 500 * l;
            if (mm < n) continue;
            int m = mm - n;
            vector<int> cnt(5, 0);
            while (m - 500 >= 0) m -= 500, cnt[3]++;
            while (m - 100 >= 0) m -= 100, cnt[2]++;
            while (m - 50 >= 0) m -= 50, cnt[1]++;
            while (m - 10 >= 0) m -= 10, cnt[0]++;
            int p = a + b + c + d + cnt[0] + cnt[1] + cnt[2] + cnt[3] -
                    (i + j + k + l);
            if (anscnt > p) {
              anscnt = p;
              ans[0] = i;
              ans[1] = j;
              ans[2] = k;
              ans[3] = l;
            }
          }
        }
      }
    }
    // cout << 10 << " " << ans[0] << endl;
    // cout << 50 << " " << ans[1] << endl;
    // cout << 100 << " " << ans[2] << endl;
    // cout << 500 << " " << ans[3] << endl;
    if (ans[0] != 0) cout << 10 << " " << ans[0] << endl;
    if (ans[1] != 0) cout << 50 << " " << ans[1] << endl;
    if (ans[2] != 0) cout << 100 << " " << ans[2] << endl;
    if (ans[3] != 0) cout << 500 << " " << ans[3] << endl;
  }
  return 0;
}


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

int main() {
    int n,count=1;
    cin>>n;
    
    int a[n+2],m[n+2];
    
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    
    m[1]=a[1];
    
    for(int i=2;i<=n;i++)
    {
        if(a[i]<m[i-1])
        {
            m[i]=a[i];
        }
        
        else
        {
            m[i]=m[i-1];
        }
    }
    
    for(int i=1;i<n;i++)
    {
        if(m[i]!=m[i+1])
        {
            count++;
        }
    }
    
    cout<<count<<endl;
	return 0;
}

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

int main() {
  int N;
  int a[100];
  bool F = true;
  
  cin >> N;
  for(int i=0; i<N; i++) cin >> a[i];
  sort(a, a+N);
  
  int A = 0;
  int B = 0;
  for(int i=0; i<N; i++){
    if(F){
      A += a[i];
      F = false;
    }else{
      B += a[i];
      F = true;
    }
  }
  int ans = (A > B) ? A - B : B - A;
  cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

type pair = (usize, usize);

// max = (n-1)(n-2)/2
fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let answer = solve(n, k);
    if !answer.0 {
        println!("-1");
        return;
    }
    println!("{}", answer.1);
    for p in answer.2 {
        println!("{} {}", p.0, p.1);
    }
}

fn solve(n: usize, k: usize) -> (bool, usize, Vec<pair>) {
   
    let max = (n - 1) * (n - 2) / 2;
    //println!("XXX max={}", max);
    if k > max {
        return (false, 0, Vec::new());
    }

    // base
    // assume node n is center
    let delta = max - k;
    let mut v = Vec::<pair>::with_capacity(n-1+delta);
    for i in 1..n {
        let p = (i, n);
        v.push(p);
    }

    
    //println!("XXX delta={}", delta);
    if delta == 0 {
        return (true, n - 1, v);
    }

    // additional
    let mut count = 0;
    for i in 1..n - 1 {
        for j in i + 1..n {
            let p = (i, j);
            v.push(p);
            count += 1;
            if count == delta {
                return (true, n - 1 + delta, v);
            }
        }
    }

    return (true, n - 1 + delta, v);
}


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

using namespace std;

int32_t main()
{
  int a, b, c; cin >> a >> b >> c;
  if (a==5 && b==5 && c==7) cout << "YES";
  else if (a==5 && b==7 && c==5) cout << "YES";
  else if (a==7 && b==5 && c==5) cout << "YES";
  else cout << "NO";
  return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
Y //= 1000
k = min((Y - N) // 4, Y // 5)
if 9 * k >= 2 * (Y - N):
    x = (Y - N) - 4 * k
    y = 9 * k - 2 * (Y - N)
    z = Y - 5 * k
    print(x, y, z)
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

bool chk_a(const string s)
{
    bool c = true;
    int f, b;

    f = b = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != '=' && s[i] != '#') 
            return false;
        if (c && s[i] == '#') 
            c = false;
        else if (s[i] == '=' && c)
            f++;
        else
            b++;
    }

    return (f == b) ? true : false;
}

bool chk_b(const string s)
{
    for (int i = 0; i < s.size(); i += 2) 
        if (s[i] != 'Q' || s[i + 1] != '=')
            return false;

    return true;
}

int main()
{
    int n;

    cin >> n;
    while (n--) {
        string inp;
        bool flag = false;

        cin >> inp;
        if (inp.size() >= 5 && inp[0] == '>' && inp[inp.size() - 1] == '~') {
            if (inp[1] == '\'') {  // Aの判定
                if (chk_a(inp.substr(2, inp.size() - 3))) {
                    cout << "A" << endl;
                    flag = true;
                }
            }
            else if (inp.size() >= 6 && inp[1] == '^' 
                     && inp[inp.size() - 2] == '~') {  // Bの判定
                if (chk_b(inp.substr(2, inp.size() - 4))) {
                    cout << "B" << endl;
                    flag = true;
                }
            }
        }

        if (!flag)
            cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
#define NIL -1
struct Node{int p, l, r;}; // parent, left, right
Node A[30];
int D[30];;

void getDepth(int u, int depth);
int getHeight(int u);
void print(int u);

int main() {
  int i, node;
  int n;
  cin >> n;
  for(i = 0;i < n; i++) {
    A[i].p = A[i].l = A[i].r = D[i] = NIL;
  }
  for (i = 0; i < n; i++) {
    cin >> node;
    cin >> A[node].l >> A[node].r;
    A[A[node].l].p = A[A[node].r].p = node;
  }
  int top;
  for (i = 0; i < n; i++) {
    if(A[i].p == NIL) {
      top = i;
      break;
    }
  }
  getDepth(top, 0);
  getHeight(n);
  for (i = 0; i < n; i++) {
    print(i);
  }
  return 0;
}

void getDepth(int u, int depth) {
  D[u] = depth;
  if(A[u].r != NIL) getDepth(A[u].r , depth+1);
  if(A[u].l != NIL) getDepth(A[u].l, depth+1);
}

int getHeight(int u) {
  int h1 = -1, h2 = -1;
  if(A[u].l != NIL) h1 = getHeight(A[u].l);
  if(A[u].r != NIL) h2 = getHeight(A[u].r);
  return max(h1, h2) + 1;
}


void print(int u) {
  cout << "node " << u << ": " << "parent = " << A[u].p;

  cout << ", sibling = ";
  if(A[u].p == NIL) cout << -1;
  else if(A[A[u].p].r != u) cout << A[A[u].p].r;
  else if(A[A[u].p].l != u) cout << A[A[u].p].l;

  cout << ", degree = ";
  if(A[u].l != NIL && A[u].r != NIL) cout << 2;
  else if(A[u].l != NIL || A[u].r != NIL) cout << 1;
  else cout << 0;

  cout << ", depth = " << D[u];
  cout << ", height = " << getHeight(u) << ", ";

  if(A[u].p == NIL) cout << "root";
  else if(A[u].l == NIL && A[u].r == NIL) cout << "leaf";
  else cout << "internal node";
  cout << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int n,a[128];

int main(){
    scanf("%d",&n);
    fore(i,0,n)scanf("%d",a+i);
    int r=0;
    fore(i,1,n){
        if(a[i]==a[i-1]){
            r++;
            a[i]=-1;
        }
    }
    printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 256
import Data.Array
import Data.Array.IO
import Control.Monad

type Grid = IOUArray (Int,Int) Char
type DP = IOUArray (Int,Int) Int

main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  xss <- replicateM h getLine 
  grid <- thaw $ listArray ((1,1),(h,w)) $ concat xss :: IO Grid
  dp <- newArray ((1,1),(h,w)) (10^9) :: IO DP

  readArray grid (1,1) >>= \r -> do
    if r == '#'
       then writeArray dp (1,1) 1
       else writeArray dp (1,1) 0

  forM_ [1..h] $ \i -> do
    forM_ [1..w] $ \j -> do
      d <- readArray dp (i,j) 
      g <- readArray grid (i,j) 
      forM_ [(i+1,j),(i,j+1)] $ \p@(i',j') -> do
        unless (i' > h || j' > w) $ do
          readArray grid p >>= \g' ->
            if (g' == '#') && (g == '.')
               then readArray dp p >>= \d' -> writeArray dp p $ min (d+1) d'
               else readArray dp p >>= \d' -> writeArray dp p $ min d d' 

  readArray dp (h,w) >>= print


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

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


template<class T>
bool chmax(T &a, const T &b) {
    if (a < b)
    {
        return b;
    }
    return a; 
}

template<class T>
bool chmin(T &a, const T &b) {
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0; 
}

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

    // if (a >= 1e8 || b >= 1e8 || c >= 1e8) a /= 100; b /= 100; c /= 10000;
    // cout << (a) << " " << (b) << " " << (c) << endl;
    string ans = (a + b + 2*(sqrt(a) * sqrt(b)) < c) ? "Yes" : "No";
    // cout << 2*(sqrt(a) * sqrt(b)) << " " << c << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int H, W;

void show(vector<string> v) {
  REP(i, v.size()) {
    cout << v[i] << endl;
  }
  cout << endl;
}

void dfs(vector<string> &v, int y, int x, char c) {
  v[y][x] = '.';

  // cout << "y = " << y << ", x = " << x << endl;
  REP(i, 4) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    // cout << "  ny = " << ny << ", nx = " << nx << ", c = " << c << endl;

    if (0 <= nx && nx < W && 0 <= ny && ny < H && v[ny][nx] == c) {
      dfs(v, ny, nx, c);
    }
  }
}

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

  while (true) {
    cin >> H >> W;

    if (H == 0 && W == 0) break;

    vector<string> v(H);
    REP(i, H) cin >> v[i];

    int ans = 0;

    REP(i, H)REP(j, W) {
      if (v[i][j] == '.') continue;

      // cout << "------------------------------" << endl;
      dfs(v, i, j, v[i][j]);
      // show(v);
      ans++;
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 4124
S = input()
p1 = ["1" if i%2==0 else "0" for i in range(len(S))]
p2 = ["0" if i%2==0 else "1" for i in range(len(S))]
print(min(bin((int(S,2)^int("".join(p1),2))).count("1"),bin((int(S,2)^int("".join(p2),2))).count("1")))

Measured memory_bytes: 4724
H, W = map(int, input().split())
MAX_VAL = 10**9
cost = [[MAX_VAL]*(W+1) for _ in range(H+1)]

field = ["#" * (W+1)]
for i in range(H):
    line = input()
    field.append("#" + line)

if field[1][1] == "#":
    cost[1][1] = 1
else:
    cost[1][1] = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if i * j == 1:
            continue

        if field[i][j] == ".":
            cost[i][j] = min(cost[i-1][j], cost[i][j-1])
        else:
            top_cost = cost[i-1][j]
            left_cost = cost[i][j-1]
            
            if field[i-1][j] == ".":
                top_cost += 1
            if field[i][j-1] == ".":
                left_cost += 1
            
            cost[i][j] = min(top_cost, left_cost)

print(cost[H][W])

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(v.begin(), v.end());

	ll L1 = 0; // L1 >= L2
	ll L2 = 0;
	while (v.size() >= 2) {
		if (v[0] == v[1]) {
			L2 = L1;
			L1 = v[0];
			v.erase(v.begin(), v.begin() + 2);
		}
		else v.erase(v.begin(), v.begin() + 1);
	}

	cout << L1 * L2 << endl;

	return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int answer=0;
	for (int i = 0; i < s.length(); ++i)
	{
		if (s[i]=='+') answer++;
		else answer--;
	}
	cout << answer;

	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


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

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}


int main()
{
    ll N, M;
    cin >> N >> M;
    vec a(N);
    REP(i,0,N) cin >> a[i];

    vec_b F(N);
    bool all_odd, all_even;
    ll d = -1;
    while(true) {
        if(a[0] % 2 == 0) {
            all_odd = false;
            all_even = true;
        }
        else {
            all_odd = true;
            all_even = false;
        }
        REP(i,1,N) {
            if(a[i] % 2 == 0 && all_odd) {
                all_odd = false;
                break;
            }
            else if(a[i] % 2 == 1 && all_even) {
                all_even = false;
                break;
            }
        }
        if(!all_even) break;
        REP(i,0,N) a[i] >>= 1;
        ++d;
    }
    if(!all_odd && !all_even) _PR(0);
    else {
        ll L = a[0];
        REP(i,1,N) L = lcm(L, a[i]);
        L *= (1 << d);
        _PR(M/L-M/(L*2));
    }

    return 0;
}

/*



*/

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

int main(){
  long long a,b;
  cin>>a>>b;
  if((a+b)%2==0){
    cout<<(a+b)/2<<endl;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = InputNumList();
            var n = nm[0];
            var m = nm[1];
            var list = new List<int>();
            for (int i = 0; i < n; i++)
            {
                list.Add(InputNum());
            }
            var rest = m - list.Sum();
            var ans = n;
            ans += rest / list.Min();
            WriteLine(ans);
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

Measured memory_bytes: 13396
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());

    long ppp[] = new long[N];
    long ppm[] = new long[N];
    long pmp[] = new long[N];
    long pmm[] = new long[N];
    long mpp[] = new long[N];
    long mpm[] = new long[N];
    long mmp[] = new long[N];
    long mmm[] = new long[N];

    for (int i = 0; i < N; i++) {
      long x = Long.parseLong(sc.next());
      long y = Long.parseLong(sc.next());
      long z = Long.parseLong(sc.next());
      ppp[i] = x + y + z;
      ppm[i] = x + y - z;
      pmp[i] = x - y + z;
      pmm[i] = x - y - z;
      mpp[i] = -x + y + z;
      mpm[i] = -x + y - z;
      mmp[i] = -x - y + z;
      mmm[i] = -x - y - z;
    }
    Arrays.sort(ppp);
    Arrays.sort(ppm);
    Arrays.sort(pmp);
    Arrays.sort(pmm);
    Arrays.sort(mpp);
    Arrays.sort(mpm);
    Arrays.sort(mmp);
    Arrays.sort(mmm);

    long ans = 0, sum;
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += ppp[i];
    }
    ans = Math.max(ans, sum);
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += ppm[i];
    }
    ans = Math.max(ans, sum);
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += pmp[i];
    }
    ans = Math.max(ans, sum);
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += pmm[i];
    }
    ans = Math.max(ans, sum);
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += mpp[i];
    }
    ans = Math.max(ans, sum);
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += mpm[i];
    }
    ans = Math.max(ans, sum);
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += mmp[i];
    }
    ans = Math.max(ans, sum);
    sum = 0;
    for (int i = N - 1; i > N - 1 - M; i--) {
      sum += mmm[i];
    }
    ans = Math.max(ans, sum);

    System.out.println(ans);
  }
}

Measured memory_bytes: 27092
#include<stdio.h>
int main(void) {
	int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int n;
	scanf("%d", &n);
	printf("%d", a[n -1]);
  
  return 0;
}

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

s = n - 1

li = [n]

for i in range(1, int(s**0.5) + 2):
    if s%i == 0:
        li.append(i)
        li.append(s//i)

for i in range(2, int(n**0.5) + 2):
    if n%i == 0:
        tmp = i
        result = n
        while True:
            if result < 1:
                break
            
            if result == 1:
                li.append(i)
                break
            
            if result%tmp == 0:
                result //= tmp
            else:
                result = result%tmp
                if result == 1:
                    li.append(i)
                    break
                else:
                    break
        
li = list(set(li))

print(len(li) - 1)

Measured memory_bytes: 3192
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int calc(ll x){
    int ret = 0;
    while (x) {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

ll piyo(ll mx, ll s){
    ll hoge = mx;
    VL d;
    while (mx) {
        d.push_back(mx % 10);
        mx /= 10;
    }
    int n = d.size();
    reverse(ALL(d));
    ll ret = 0;
    REP(i,n+1){
        if (i < n && d[i] == 0) continue;
        ll tmp = 0;
        ll r = s;
        REP(j,n){
            ll p = 0;
            if (j < i) p = min(d[j], r);
            else if (j == i) p = min(d[j] - 1, r);
            else p = min(9LL, r);
            r -= p;
            tmp = 10 * tmp + p;
        }
        if (r == 0) ret = max(ret, tmp);
    }
    // cout << hoge << " " << s << "    " << ret << endl;
    return ret;
}

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

    VL ans;

    ll m = 99999999999999999, ms = calc(m);
    while (m > 1) {
        ll n = 0;
        FOR(s,1,150){
            ll x = min(m * s / ms, m - 1);

            n = max(n, piyo(x, s));
        }
        ans.push_back(n);
        m = n;
        ms = calc(m);
    }

    sort(ALL(ans));
    REP(i,k) printf("%lld\n", ans[i]);
    return 0;
}


Measured memory_bytes: 256
//                          VIVEK UPADHYAY
//                          MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D

// g++ -std=c++11 file_name.cpp
// ./file_name.out
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int) a.size())
typedef long long ll ;
const int MAXN = 5*1e5 + 10;
ll inf  = 1e18 ;
int main () {
    
    int N , K ;
    cin >> N >> K ;
    vector<ll> a(N) ;
    for(int i =0 ; i < N ;i++)
        cin >> a[i] ;
    ll mx = 0 ;
    // choose farward
    vector<ll> v ;
    for(int i =0 ; i < N ; i++)
    {
        v.push_back(a[i]) ;
        if(i+1>K) break ;
        
        sort(v.begin(),v.end());
        
        reverse(v.begin(),v.end()) ;
        int sz = sz(v) , t= K - i - 1 ;
        
        ll sum =0 ;
        for(int j = 0 ; j < sz(v) ;j++)
        {
            if(sz-1 >= t)
                sum+=v[j] ;
            else if(v[j] > 0) sum+=v[j] ;
            sz-- ;
        }
        mx = max(mx,sum) ;
    }
    v.clear() ;
    reverse(a.begin(),a.end());
    for(int i =0 ; i < N ; i++)
    {
        v.push_back(a[i]) ;
        if(i+1>K) break ;
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end()) ;
        int sz = sz(v) , t= K - i - 1 ;
        ll sum =0 ;
        for(int j = 0 ; j < sz(v) ;j++)
        {
            if(sz-1 >= t)
                sum+=v[j] ;
            else if(v[j] > 0) sum+=v[j] ;
            sz-- ;
        }
        //if(sum==45) cout<<i<<endl;
        mx = max(mx,sum) ;
    }
    
    reverse(a.begin(),a.end());
    for(int i = 1 ; i < min(K,N) ;i++){
        
        for(int l = 1 ; l < K ;l++){
            v.clear() ;
            if(i + l > K) break ;
            for(int j = 0 ; j < min(N,i) ;j++)
                v.push_back(a[j]) ;
            
            int j = N - 1 , tmp = l ;
            while(j >= i && tmp > 0){
                v.push_back(a[j]) ;
                j-- ;
                tmp-- ;
            }
            sort(v.begin(),v.end()) ;
            reverse(v.begin(),v.end()) ;
            int sz = sz(v) , t= K - (i + l) ;
            ll sum =0 ;
            for(int j = 0 ; j < sz(v) ;j++)
            {
                if(sz-1 >= t)
                    sum+=v[j] ;
                else if(v[j] > 0) sum+=v[j] ;
                sz-- ;
            }
            
            mx = max(mx,sum) ;
        }
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
  char text[1200];
  int t;
  int arr[26] = {0};
  int l;
  int k;
  int c = 97;
  while(  scanf("%s", text) != EOF)
    {
  l = strlen(text);
  for(int i = 0; i < l; i++)
    {
      if(text[i] >= 65 && text[i] <=90)
	{
	  k = text[i];
	  k=k-65;
	  arr[k]++;
	}
      if(text[i] >= 97 && text[i] <= 122)
	{
	  k = text[i];
	  k = k-97;
	  arr[k]++;
	}
    }
    }
  for(int i = 0; i < 26; i++)
    {
      printf("%c : %d\n", c, arr[i]);
      c++;
    }
}



Measured memory_bytes: 2140