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

long long abs_ll (long long num) {
    if ( num < 0 )
        return num * -1;
    return num;
}

int main (void) {
    long long n, k;

    scanf("%lld%lld", &n, &k);

    long long ans = n % k;
    if ( ans > abs_ll(ans - k) )
        ans = abs_ll(ans - k);

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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 (b < a) { a = b; return 1; } return 0; }

lli dd[30][30];
lli depth[30][30];
bool vis[30][30];
    
int main(){


    lli h,w;
    cin>>h>>w;
    REP(i,0,h)REP(j,0,w){
        char tmp;
        cin>>tmp;
        if(tmp=='#')dd[i][j] = 1;
    }
    
    lli ans = 0;
    REP(si,0,h)REP(sj,0,w){
        if(dd[si][sj]==1)continue;
    
        queue<lli> qi,qj,qd;
        qi.push(si);
        qj.push(sj);
        qd.push(0);
        REP(i,0,h)REP(j,0,w){
            depth[i][j]=INF;
            vis[i][j]=false;
        }
        depth[si][sj]=0;
        vis[si][sj]=true;

        lli maxD= 0;
    
        while(qi.size()){
            lli topI = qi.front();
            lli topJ = qj.front();
            qi.pop(),qj.pop();
    
            lli di[8]={-1,0,1,0,-1,-1,1,1};
            lli dj[8]={0,1,0,-1,-1,1,1,-1};
    
            REP(i,0,4){
                lli nextI = topI + di[i];
                lli nextJ = topJ + dj[i];
                if(nextI<0 || nextI>=h || nextJ<0 || nextJ>=w)continue;
                if(dd[nextI][nextJ]!=0)continue;
                if(vis[nextI][nextJ])continue;
    
                vis[nextI][nextJ]=true;
                qi.push(nextI);
                qj.push(nextJ);
                depth[nextI][nextJ] = depth[topI][topJ] + 1;
                chmax(maxD,depth[nextI][nextJ]);
            }
        }
        chmax(ans,maxD);
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,power=0;
    int b[50]={};
    cin>>a;
    for(int z=1;z<=a;z++){
        cin>>b[z];
    }
    for(int y=1;y<=a-1;y++){
        //cout<<"N"<<endl;
        for(int x=y+1;x<=a;x++){
            if(x!=y){
                power+=b[x]*b[y];
            }
        }
    }
    cout<<power<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N;
    double ans = 0.0, A;
    scanf("%d", &N);
    for (int i = 1; i <= N ; ++i) {
        scanf("%lf", &A);
        ans += 1.0 / A;
    }
    ans = 1.0 / ans;
    printf("%lf", ans);
    return 0;
}

Measured memory_bytes: 128
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

int main()
{
  init_main();

  int n, m;
  ll x;
  cin >> n >> m >> x;
  ll c[15];
  ll a[15][15];
  rep(i, n)
  {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  ll Min = LINF;
  rep(bi, 1 << n)
  {
    bitset<12> bs(bi);
    ll sum[12] = {};
    ll cost = 0;
    rep(i, n)
    {
      if (!bs[i])
        continue;
      cost += c[i];
      rep(j, m)
      {
        sum[j] += a[i][j];
      }
    }

    //check
    bool b = true;
    rep(j, m)
    {
      if (sum[j] < x)
      {
        b = false;
        break;
      }
    }
    if (b)
    {
      chmin(Min, cost);
    }
  }
  cout << (Min == LINF ? -1 : Min) << "\n";
  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

typedef struct point{
  int x_elem;
  int y_elem;
}point;

point deg90rot(point vtx1, point vtx2){ // vtx1を中心にvtx2を90度回転させる関数
  point vtx;
  vtx.x_elem = vtx1.x_elem + vtx1.y_elem - vtx2.y_elem;
  vtx.y_elem = - vtx1.x_elem + vtx2.x_elem + vtx1.y_elem;
  return vtx;
}

int main(void){
  point vtx1, vtx2, vtx3, vtx4;
  scanf("%d%d%d%d", &vtx1.x_elem, &vtx1.y_elem, &vtx2.x_elem, &vtx2.y_elem);
  
  vtx4 = deg90rot(vtx1, vtx2);
  vtx3 = deg90rot(vtx4, vtx1);
  
  printf("%d %d %d %d\n", vtx3.x_elem, vtx3.y_elem, vtx4.x_elem, vtx4.y_elem);
  return 0;
}

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

int main() {
    vector<vector<int>> c(3,vector<int>(3));
    vector<int> a(3);
    vector<int> b(3);
    rep(i, 3) {
        rep(j, 3) {
            cin >> c.at(i).at(j);
        }
    }

    a.at(0) = 0;
    rep(i, 3) {
        b.at(i) = c.at(0).at(i) - a.at(0);
    }
    for (int i = 1; i < 3; i++) {
        a.at(i) = c.at(i).at(0) - b.at(0);
    }
    bool is_ans = true;

    rep(i, 3) {
        rep(j, 3) {
            if (c.at(i).at(j) != a.at(i) + b.at(j)) {
                is_ans = false;
                break;
            }
        }
    }

    if (is_ans) {
        puts("Yes");
    }
    else {
        puts("No");
    }
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010;

int n;
int a[N], b[N];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", a + i);
        b[i] = a[i];
    }
    sort(a + 1, a + 1 + n);

    for(int i = 1; i <= n; i++)
        if(b[i] == a[n]) printf("%d\n", a[n - 1]);
        else printf("%d\n", a[n]);
    return 0;
}


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

#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

#define debug(x) cout << "> " << #x << " = " << x << endl;
#define debug_at(arr, at) cout << "> " << #arr << "[" << at << "] = " << arr[at] << endl;
#define debug_pair(p) cout << "> " << #p << " = (" << p.first << ", " << p.second << ")" << endl;

using namespace std;

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

const int N = 51;
vector<ii> points;

void build(bool xx, map<int, int> &id, map<int, int> &rev) {
    set<int> all;
    for(auto p : points) {
        int x, y;
        tie(x, y) = p;
        if(xx) {
            all.insert(x);
        }
        else {
            all.insert(y);
        }
    }

    int av = 0;
    for(int k : all) {
        id[k] = av;
        rev[av] = k;
        av++;
    }
}

map<int, int> idx, revx;
map<int, int> idy, revy;

vector<int> adj[N];
void init() {
    build(true, idx, revx);
    build(false, idy, revy);

    for(auto p : points) {
        int x = idx[p.first];
        int y = idy[p.second];
        adj[x].push_back(y);
    }
    fori(i, 0, N) {
        sort(adj[i].begin(), adj[i].end());
    }
}

inline int many(int x, int y1, int y2) {
    auto ata = lower_bound(adj[x].begin(), adj[x].end(), y1);
    if(ata == adj[x].end() or (ata != adj[x].end() and *ata > y2)) return 0;

    int a = ata - adj[x].begin();

    auto atb = lower_bound(adj[x].begin(), adj[x].end(), y2);
    if(atb == adj[x].end() or (atb != adj[x].end() and *atb > y2)) {
        --atb;
    }
    int b = atb - adj[x].begin();
    int res = b - a + 1;
    return max(0, res);
}

inline int many(int x1, int x2, int y1, int y2) {
    int res = 0;
    fori(i, x1, x2 + 1) {
        res += many(i, y1, y2);
    }
    return res;
}

int n, k;

inline ll solve() {
    ll ans = 1LL << 62;
    fori(x1, 0, N) {
        if(revx.find(x1) == revx.end()) continue;

        fori(x2, x1, N) {
            if(revx.find(x2) == revx.end()) continue;

            fori(y1, 0, N) {
                if(revy.find(y1) == revy.end()) continue;

                fori(y2, y1, N) {
                    if(revy.find(y2) == revy.end()) continue;

                    int cont = many(x1, x2, y1, y2);
                    if(cont >= k) {
                        ll area = ((ll) revx[x2] - revx[x1]) * ((ll) revy[y2] - revy[y1]);

                        ans = min(ans, area);
                    }
                }
            }
        }
    }
    return ans;
}

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

    cin >> n >> k;
    fori(i, 0, n) {
        int x, y;
        cin >> x >> y;
        points.push_back({x, y});
    }
    init();

    ll ans = solve();
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int a,b;
    std::cin>>a>>b;
    if(a<=0 && b>=0)std::cout<<"Zero"<<std::endl;
    else{
        if(a>0 && b>0)std::cout<<"Positive"<<std::endl;
        else {
            if((b-a+1)%2==0)std::cout<<"Positive"<<std::endl;
            else std::cout<<"Negative"<<std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from math import ceil
n, h = map(int, input().split())
data1, data2 = [], []
for i in range(n):
    a, b = map(int, input().split())
    data1.append([a, b])
    data2.append([a, b])

data1 = sorted(data1, key = lambda x: x[0], reverse = True)
data2 = sorted(data2, key = lambda x: x[1], reverse = True)
ans = 0
while h > 0 and data1[0][0] < data2[0][1]:
    h -= data2[0][1]
    ans += 1
    del data2[0]
    if len(data2) == 0:
        break
ans += ceil(max(0, h) / data1[0][0])
print(ans)

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

using namespace std;

int m, n;
string s, t, res = "";

void printpath(vector<vector<pair<int, int>>>& p, pair<int, int> x){
    if(x.first == 0 || x.second == 0) return;
    auto xx = p[x.first][x.second];
    auto d = x.first + x.second - (xx.first + xx.second);
    if(d == 2){
        res += s[x.first - 1];
    }
    printpath(p, xx);
    return;
}

int main(){
    cin>>s>>t;
    m = s.length(), n = t.length();
    vector<vector<int>> dp(s.length()+ 1, vector<int>(t.length() + 1));
    vector<vector<pair<int, int>>> p(m + 1, vector<pair<int, int>>(n + 1));
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;                
                p[i][j] = {i-1, j-1};
            }else{
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
                p[i][j] = dp[i][j] == dp[i][j-1] ? make_pair(i, j-1) : make_pair(i-1, j);
            }
        }
    }
    printpath(p, {m, n});
    reverse(res.begin(), res.end());
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 106240
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)(1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	while (n % 111 != 0)n++;
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
f2::Char->Bool
f2 a=('a'<=a) && (a<='z')

f::String->String
f (x:y:xs)
   |not (x=='A')="WA"
   |head (reverse xs)=='C'="WA"
   |notElem 'C' xs="WA"
   |otherwise=if length (filter f2 (y:xs))==(length (y:xs))-1 then "AC" else "WA" 

main = do
       a<-getLine
       putStrLn $ f a

Measured memory_bytes: 380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        boolean[] ns = new boolean[1000000];
        for (int i = 2; i < (int) Math.sqrt(1000000); i++) {
            if (ns[i])
                continue;
            for (int j = 2; j < 999999 / i + 1; j++) {
                if (!ns[i * j]) {
                    ns[i * j] = true;
                }
            }
        }

        while ((line = br.readLine()) != null && !line.isEmpty()) {
            int n = Integer.parseInt(line);
            int m = 0;
            for (int i = 2; i < n + 1; i++) {
                if (!ns[i]) {
                    m++;
                }
            }
            System.out.println(m);
        }
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
const long double PI=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline long long read() {
	long long x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int main(){
    char c[5];
    for(int i=1;i<=4;++i)scanf("%c",&c[i]);
	printf((c[1]==c[2] && c[2]==c[3] || c[2]==c[3] && c[3]==c[4])?"Yes\n":"No\n");
    return 0;
} 

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
N = int(input())
Edges = [[] for i in range(N)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    Edges[a].append((b,c))
    Edges[b].append((a,c))
D = [float('inf') for i in range(N)]
def dfs(v,p,d):
    D[v] = d
    for e1,e2 in Edges[v]:
        if e1 != p:
            dfs(e1,v,d+e2)
Q,K = map(int,input().split())
dfs(K-1,-1,0)
for i in range(Q):
    x,y = map(int,input().split())
    print(D[x-1]+D[y-1])

Measured memory_bytes: 132588
N, M = map(int, input().split())

k = []
s = []
for _ in range(M):
    temp = list(map(int, input().split()))
    k.append(temp[0])
    s.append(temp[1:])

p = list(map(int, input().split()))

# bit全探索
c = 0
for i in range(2 ** N):
    b = []
    for j in range(N):
        b.append(i >> j & 1 > 0)
    flag = True
    for j in range(M):
        cc = 0
        for ss in s[j]:
            if b[ss-1]:
                cc += 1
        if cc % 2 != p[j]:
            flag = False
            break
    if flag:
        c += 1
print(c)


Measured memory_bytes: 3188
A, B, C, K = map(int, input().split())

x = K - A
if x == 0:
    print(A)
elif x < 0:
    print(K)
elif x > 0:
    y = x - B
    if y == 0:
        print(A)
    elif y < 0:
        print(A)
    elif y > 0:
        print(A - y)


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e6+50;
int n,m;
int l,r;
int a[maxn];
bool check(int mid)
{
	for(int i=0;i<=n-2;i++)
	{
		if((a[n+i]>mid&&a[n+i+1]>mid)||(a[n-i]>mid&&a[n-i-1]>mid))
			return false;
		if((a[n+i]<=mid&&a[n+i+1]<=mid)||(a[n-i]<=mid&&a[n-i-1]<=mid))
			return true;
	}
	if(a[1]<=mid)
		return true;
	return false;
}
int main()
{
	scanf("%d",&n);
	m=2*n-1;
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	l=0,r=m+1;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(check(mid))
			r=mid;
		else
			l=mid;
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define enld endl
int main(){
    ll l,r,ans=INF;
    cin>>l>>r;
    if(r-l+1>=2019)cout<<0<<endl;
    else{   
        for(ll i=l;i<r;i++){
            for(ll j=i+1;j<=r;j++){
                ans=min(ans,(i*j)%2019);
            }
        }
        cout<<ans<<endl;
    }

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(void){
  int N;
  cin>>N;
  int inc=0;
  int last;
  int c=0;
  cin>>last;
  for(int i=0;i<N-1;i++){
      int now;
      cin>>now;
      if(inc>0&&now<last){
          c+=1;
          inc=0;
      }else if(inc<0&&now>last){
          c+=1;
          inc=0;
      }else if(inc==0){
          inc=now-last;
      }
      last=now;
  }
  cout<<c+1<<endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i=0; i<N; i++)
    cin >> d.at(i);
  
  sort(d.begin(), d.end());
  int mc=1, nm=d.at(0);
  for (int j=1; j<N; j++) {
    if (d.at(j) > nm) {
      mc++;
      nm = d.at(j);
    }
  }
  cout << mc << endl;
}
    


Measured memory_bytes: 256
N = int(input())
L = []
for i in range(N):
  S, P = map(str, input().split())
  tmp = 100 - int(P)
  s1, s2, s3 = (tmp // 100) % 10, (tmp // 10) % 10, (tmp // 1) % 10
  s1, s2, s3 = str(s1), str(s2), str(s3)
  tmp2 = i + 1
  t1, t2, t3 = (tmp2 // 100) % 10, (tmp2 // 10) % 10, (tmp2 // 1) % 10
  t1, t2, t3 = str(t1), str(t2), str(t3)
  S = S[:] + s1 + s2 + s3 + t1 + t2 + t3
  L.append(S)
L.sort()
for i in range(N):
  tmp3 = 0
  base = 1
  for j in range(3):
    tmp3 += base * int(L[i][-j-1])
    base *= 10
  print(tmp3)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;



int main()
{
    long long a,b,n;
    scanf("%lld%lld%lld",&a,&b,&n);
    if(n>=b-1)
        printf("%lld\n",(a*(b-1))/b);
    else
        printf("%lld\n",(a*n)/b);
    return 0;
}


Measured memory_bytes: 3760
/*
[agc038] C - LCMs
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

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

class gf {
public:
    int n;
    static int mod_inv(int a, int m) {
        int u = 0, v = 1;
        while (a != 0) {
            int t = m / a;
            m -= t * a;
            u -= t * v;
            swap(a, m);
            swap(u, v);
        }
        return (u + MOD) % MOD;
    }
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf operator/(gf x) { return *this * x.inv(); }
    gf& operator+=(gf x) { return *this = (*this + x); }
    gf& operator-=(gf x) { return *this = (*this - x); }
    gf& operator*=(gf x) { return *this = (*this * x); }
    gf& operator/=(gf x) { return *this = (*this / x); }
    gf inv() { return gf(mod_inv(n, MOD)); }
};

int N;
int A[MAX_N];
gf w[MAX_A + 1];
gf cnt[MAX_A + 1];

ll solve() {
    for (int i = 1; i <= MAX_A; i++) {
        w[i] += gf(1) / i;
        for (int j = i * 2; j <= MAX_A; j += i) {
            w[j] -= w[i];
        }
    }

    for (int i = 0; i < N; i++) {
        cnt[A[i]] += 1;
    }

    gf ans = 0;
    for (int i = 1; i <= MAX_A; i++) {
        gf s = 0;
        for (int j = i; j <= MAX_A; j += i) {
            s += cnt[j] * j;
        }
        ans += w[i] * s * s;
    }

    for (int i = 0; i < N; i++) {
        ans -= A[i];
    }
    ans /= 2;

    return ans.n;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

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

    int N, K; cin >> N >> K;
    string S; cin >> S;
    S[K-1] = S[K-1] + 32;
    cout << S << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 892
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
const int N = 2e5 + 123;
int main(){
    speed;
    int n;
    cin >> n;
    vi s(n);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    sort(rall(s));
    ll x = 0, y = 0;
    for(int i = 0; i < n - 1; ++i){
        if(s[i] == s[i + 1] && x == 0){
            x = s[i];
            i++;
        }
        else if(s[i] == s[i + 1] && x != 0){
            if(y == 0){
                y = s[i];
                break;
            }
        }
    }
    cout << x * y;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

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

	int a, b;
	scanf("%d%d", &a, &b);
	int ans = max(a+b, max(a-b, a*b));
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>

using namespace std;

const int N = 1234567;
long long arr[N];
int n;
long long m;
long long get(int n)
{
  map<long long, long long> mod;
  long long cumSum = 0;
  for (int i = 0; i < n; i++)
  {
    cumSum += arr[i];
    mod[((cumSum % m) + m) % m]++;
  }

  long long result = 0;

  for (auto it : mod)
    if (it.second > 1)
      result += (it.second * (it.second - 1)) / 2;
  result += mod[0];
  return result;
}

int main()
{
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  cout << get(n) << endl;
}


Measured memory_bytes: 4992
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = list(input())
    for i in range(len(s)):
        if s[i] == 'U' or s[i] == 'D':
            pass
        elif i % 2 == 0 and s[i] == 'R':
            pass
        elif i % 2 == 1 and s[i] == 'L':
            pass
        else:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    sort(p.begin(), p.end());
    int d = 1000000000;
    for (int i = 0; i <= n - k; i++)
    {
        d = min(d, p[i + k - 1] - p[i]);
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<20)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
    int r;
    cin >> r;
    cout << r * 2 * 3.141;
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define clr(a, b) memset(a, b, sizeof(a))
#define Error(x) cout << #x << " = " << x << endl
#define iDEBUG freopen("in.txt", "r", stdin)
#define oDEBUG freopen("output.txt","w",stdout)
#define pb push_back
#define x first
#define y second
typedef long long ll;

using namespace std;
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

int main()
{_
    int n, m;

    cin >> n >> m;
    m /= 1000;
    for (int x=0; x<=m/10; x++)
        for (int y=0; y<=m/5; y++)
        {
            int z = n - (x + y);
            if (z < 0) continue;
            if (x+y+z == n && x*10+y*5+z == m)
            {
                cout << x << " " << y << " " << z;
                return 0;
            }
        }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
from functools import reduce

n, m = map(int, input().split())

mod = 10 ** 9 + 7
ans = 0
c = 1
p1 = 1
p2 = reduce(lambda ac, v: ac * v % mod, range(m, m - n, -1), 1)
for i in range(n + 1):
    if i > 0:
        c = (c * (n - i + 1) * pow(i, mod - 2, mod)) % mod
        p1 = (p1 * (m - i + 1)) % mod
        p2 = (p2 * pow(m - i + 1, mod - 2, mod)) % mod
    x = c * p1 * (p2 ** 2)
    if i % 2 == 0:
        ans += x
    else:
        ans -= x
    ans %= mod
print(ans)


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

int main(){
  uint64_t a, b, c;
  cin >> a >> b >> c;
  bool ans = false;
  long double d = 2*powl(a*b,0.5);
  int64_t e = c-a-b;
  if(d < e ) ans = true;
  puts(ans ? "Yes" : "No");
}
  


Measured memory_bytes: 384
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll k;
	cin>>k;
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
	    ll val;
	    cin>>val;
	    if(val>=k)
	    {
	        ans++;
	    }
	}
	cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 384
#include <stdio.h>
int main(){
	int n,i,x;
	do{
		scanf("%d",&n);
	}while(!(n>=3 && n<=10000));
	
	for(i=1;i<=n;i++){
		x=i;
		if(x%3==0){
			printf(" %d",i);
			continue;
		}
		do{
			if(x%10==3){
				printf(" %d",i);
				break;
			}
			x/=10;
		}while(x);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
int a[11][331];
bool e[10];
void m(int d, int s){
    for(int i=0;i<10;i++){
        if(e[i])continue;
        a[d][s+d*i]++;
        if(d<10){
            e[i]=true;
            m(d+1,s+d*i);
            e[i]=false;
        }
    }
}
int main(void){
    memset(a,0,sizeof(a));
    memset(e,0,sizeof(e));
    m(1,0);
    int n,s;
    while(~scanf("%d%d",&n,&s)){
        if(n<0||n>10||s<0||s>330)puts("0");
        else printf("%d\n",a[n][s]);
    }
    return 0;
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  int N;
  cin >> N; // 税込価格 
  double X; // 税抜

  X = double(N / 1.08); // 税抜
  int X_floor = int(floor(X));
  int X_ceil = int(ceil(X));
  
  double estN_floor = X_floor*1.08;
  double estN_ceil = X_ceil*1.08;

  int estN_floor_int = int(floor(estN_floor));
  int estN_ceil_int = int(floor(estN_ceil));

  // cout << "X:       " << X << endl; 
  // cout << "X_floor: " << X_floor << endl; 
  // cout << "X_ceil:  " << X_ceil << endl; 
  // cout << "------" << endl;
  // cout << "estN_floor: " << estN_floor << endl;
  // cout << "estN_ceil:  " << estN_ceil << endl;
  // cout << "------" << endl;
  // cout << "estN_floor_int: " << estN_floor_int << endl;
  // cout << "estN_ceil_int:  " << estN_ceil_int << endl;
  
  bool isFloor = (estN_floor == N);
  bool isCeil = (estN_ceil == N);

  bool isFloorInt = (estN_floor_int == N);
  bool isCeilInt = (estN_ceil_int == N);

  // cout << endl;
  // cout << "=== ans ===" << endl;

  if (isFloor) {
    cout << X_floor << endl;
  } else if (isCeil) {
    cout << X_ceil << endl;
  } else if (isFloorInt) {
    cout << X_floor << endl;
  } else if (isCeilInt) {
    cout << X_ceil << endl;
  } else {
    cout << ":(" << endl;
  }
  

}

Measured memory_bytes: 384
class S:
    def solve(self, n, k):
        self.n = n
        return self.dfs(0, k, False)
    def dfs(self, x, y, free=False):
        if y == 0:
            return 1
        if x >= len(self.n):
            return 0
        if free:
            return 9 * self.dfs(x + 1, y - 1, free) + self.dfs(x + 1, y, free)
        else:
            t = int(self.n[x])
            r = 0
            if t > 0:
                r += 1 * self.dfs(x + 1, y - 1, False)
                r += (t - 1) * self.dfs(x + 1, y - 1, True)
            r += self.dfs(x + 1, y, t > 0)
            return r


n = raw_input()
k = input()
print S().solve(n, k)


Measured memory_bytes: 34152
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=1005;
const int MOD=1e9+7;
 

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
 
int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
*/

int a,b;
cin>>a>>b;
int x=a%b;
cout<<min(a%b,abs(x-b));

}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        Console.WriteLine(Console.ReadLine().Substring(0, 3));
    }
}

Measured memory_bytes: 25888
mod utils {
    use std::error::Error;
    use std::io::stdin;
    use std::str::FromStr;

    #[allow(dead_code)]
    pub fn read_line<T>() -> Result<Vec<T>, Box<Error>>
    where
        T: FromStr,
        T::Err: 'static + Error,
    {
        let mut line = String::new();
        let _ = stdin().read_line(&mut line)?;
        let parsed_line = line.split_whitespace()
            .map(|x| x.parse::<T>())
            .collect::<Result<Vec<T>, T::Err>>()?;

        Ok(parsed_line)
    }

    #[allow(dead_code)]
    pub fn read_lines<T>(n: usize) -> Result<Vec<Vec<T>>, Box<Error>>
    where
        T: FromStr,
        T::Err: 'static + Error,
    {
        (0..n).map(|_| read_line()).collect()
    }
}

fn is_prime(n: u32) -> bool {
    if n == 2 {
        return true;
    } else if n < 2 || n % 2 == 0 {
        return false;
    }

    let mut i = 3;
    while i <= (n as f64).sqrt() as u32 {
        if n % i == 0 {
            return false;
        }
        i += 2;
    }

    true
}

fn solve() -> Result<(), Box<std::error::Error>> {
    let n = utils::read_line::<usize>()?[0];
    let matrix = utils::read_lines::<u32>(n)?;

    let mut n_primes = 0;

    for x in matrix.iter() {
        n_primes += if is_prime(x[0]) { 1 } else { 0 }
    }

    println!("{}", n_primes);

    Ok(())
}

fn main() {
    match solve() {
        Err(err) => panic!("{}", err),
        _ => (),
    };
}



Measured memory_bytes: 5048
import java.io.IOException
import java.lang.NumberFormatException
import java.lang.StringBuilder
import kotlin.math.max

object BMain{
    fun solve(){
        val n = nextInt()
        val l = LongArray(n){ nextLong()}
        var ans = 0
        for (i in 0 until n){
            for( j in i+1 until n){
                for(k in j+1 until n){
                    if(check(l[i], l[j], l[k])) ans++
                }
            }
        }

        println(ans)
    }

    fun check (a: Long, b: Long, c: Long): Boolean{
        if(a == b || b == c || a == c){
            return false
        }

        return a + b > c && b + c > a && a + c > b
    }





    // Scanner based on uwi-san's Java code
    val stream = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0

    fun hasNextByte(): Boolean{
        if(ptr < buflen){
            return true
        }else{
            ptr = 0
            try{
                buflen = stream.read(buffer)
            }catch (e: IOException){
                e.printStackTrace()
            }
            if(buflen <= 0){
                return false
            }
        }
        return true
    }

    fun readByte() =
        if(hasNextByte()) buffer[ptr++]
        else -1

    fun isPrintableChar(c: Byte) = c in 33..126

    fun hasNext(): Boolean{
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
        return hasNextByte()
    }

    fun next(): String{
        if(!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while(isPrintableChar(b)){
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun nextLong(): Long{
        if(!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if(b == '-'.toByte()){
            minus = true
            b = readByte()
        }
        if(b !in '0'.toByte()..'9'.toByte())
            throw NumberFormatException()
        while(true){
            if(b in '0'.toByte()..'9'.toByte()){
                n *= 10
                n += b - '0'.toByte()
            }else if(!isPrintableChar(b)){
                return if(minus) -n else n
            }else{
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextInt(): Int{
        val n1 = nextLong()
        if(n1 !in Int.MIN_VALUE..Int.MAX_VALUE)
            throw NumberFormatException()
        return n1.toInt()
    }

    fun nextDouble() = next().toDouble()
}

fun main(){
    BMain.solve()
}



Measured memory_bytes: 34684
t,x,y=[],[],[];n=int(input())
for _ in range(n):
  a,b,c=map(int,input().split())
  t.append(a);x.append(b),y.append(c)
for i in range(n):
  if i==0:
    r1=t[i]
    r2=x[i]+y[i]
  else:
    r1=t[i]-t[i-1]
    r2=abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
  if not (r1>=r2 and r1%2==r2%2):
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 17384
#include <stdio.h>
#include <cstdlib>

int main(void){
	int N;
	long long int res;
	long long int min=9223372036854775807;
	long long int sumb = 0;
	long long int a[200000]={0};
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%lld",&a[i]);
		sumb += a[i];
	}
	long long int suma=0;
	for(int i=0;i<N-1;i++){
		suma += a[i];
		sumb -= a[i];
		res = std::abs(suma-sumb);
		if(res < min){
			min = res;
		}
	}
	printf("%lld\n",min);
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>
#include <ctype.h>
#include<stdlib.h>


int Integer(char *s) {

	int i,n,answer=0;
	char temp;

	for(i=0;i<strlen(s)/2;i++) {
		temp=s[i];
		s[i]=s[(strlen(s)-1)-i];
		s[(strlen(s)-1)-i]=temp;
	}

	i=0;
	while(i<=strlen(s)-1) {

		if(isdigit(s[i+1]))
			n=atoi(&s[i+1]);
		else
			n=1;


			switch(s[i]) {
			case 'i':
				answer+=n;
				break;
			case 'x':
				answer+=10*n;
				break;
			case 'c':
				answer+=100*n;
				break;
			case 'm':
				answer+=1000*n;
				break;
			}
			if(isdigit(s[i+1]))
				i+=2;
			else
				i++;
	}
	return answer;
}


int main() {

	int n;
	char s1[10],s2[10];
	int  sum,digit;
	char answer[10];
	int i,j;

	scanf("%d",&n);
	for(i=0;i<n;i++) {
		scanf("%s %s",s1,s2);
		sum=Integer(s1)+Integer(s2);

		for(j=0;j<10;j++)
			answer[j]='\0';

		digit=1000,j=0;
		while(sum>0) {
			if(sum/digit>0) {
				if(sum/digit>=2) {
					sprintf(&answer[j],"%d",sum/digit);
					j++;
				}
				if(digit==1000)
					answer[j]='m';
				else if(digit==100)
					answer[j]='c';
				else if(digit==10)
					answer[j]='x';
				else
					answer[j]='i';
				sum-=(sum/digit)*digit;
				j++;
			}
			digit/=10;
		}
		printf("%s\n",answer);
	}
	return 0;
}

Measured memory_bytes: 620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int w = sc.nextInt();
			int[] v = new int [n+1];
			int[] we = new int [n+1];
			int[][] dp = new int[n+1][w+1];
			for(int i=1;i<n+1;i++) {
				v[i] = sc.nextInt();
				we[i] = sc.nextInt();
			}
			
			for(int i=1;i<n+1;i++) {
				for(int j=1;j<w+1;j++) {
					if(j < we[i]) {
						dp[i][j] = dp[i-1][j];
					}
					else {
						dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - we[i]] + v[i]);
					}
				}
			}
			System.out.println(dp[n][w]);
			
		}
	}
}




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

int ans(string T,string S)
{
    int s = S.size();
    int t = T.size();
    int final = INT_MAX;
    // int min_change = 0;
    for(int i = 0; i < t -s +1; i++)
    {
        int min_change = 0;
        for(int j =0; j < s;j++)
        {
            if(S[j]!=T[i+j])
            {
                min_change++;
            }
        }

        final = min(final,min_change);
    }
    return final;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    string S;
    string T;
    cin>>S;
    cin>>T;
    int anaa = ans(S,T);
    cout<< anaa<<"\n";
    return 0;
    
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  int r = N % 10;
  if (r == 3) cout << "bon" << endl;
  else if (r == 0 || r == 1 || r == 6 || r == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
  return 0;
}


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

int main(){
    long long N;
    cin >> N;
    long long sum = 0, i;
    for(i = 1; i <= N; i++){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>

#define A 1000000

int main() {
	static char used[A + 1];
	int a, i;

	scanf("%d", &a);
	i = 0;
	while (1) {
		i++;
		if (used[a])
			break;
		used[a] = 1;
		a = a % 2 == 0 ? a / 2 : a * 3 + 1;
	}
	printf("%d\n", i);
	return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	c := 0
	for _, x := range strings.Split(s, "") {
		n, _ := strconv.Atoi(x)
		c += n
	}
	if c % 9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

ll max(ll m1, ll m2){
	return (m1>m2)?m1:m2;
}

int main(){
	ll n,totWt;
	cin >> n >> totWt;
	ll wt[n];
	ll val[n];

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

	// Let dp[i][j] denote the maximum value he can carry if he
	// has a sack of weight j and considers upto i items
	// Either he can keep ith item:
		// dp[i-1][j-wt[i]] + val[i]
	// Else he could just ignore it
		// dp[i-1][j]


	ll dp[n][totWt+1];
	for(int i=0 ; i<n ; i++){
		for(int j=0 ; j<=totWt ; j++){
			if(i==0 && j==0){
				dp[i][j] = 0;
			}else if(i==0 && j!=0){
				if(j >= wt[i]){dp[i][j] = val[i];}
				else{dp[i][j] = 0;}
			}else if(i!=0 && j==0){
				dp[i][j] = 0;
			}else{
				if(j >= wt[i]){
					dp[i][j] = max(dp[i-1][j-wt[i]] + val[i], dp[i-1][j]);	
				}else{
					dp[i][j] = dp[i-1][j];
				}
			}
		}
	}
	cout << dp[n-1][totWt] << "\n";
	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    int ans;
    
    if(n % 1000 == 0) ans = 0;
    else ans = 1000 - (n % 1000);

    cout << ans << endl;

    

    //cout << fixed << setprecision(6) << ans << endl;

    return 0;
    
}

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

int main(){
  ll n;
  cin >> n;
  map<ll,ll> mp;
  mp[0]++;
  ll s = 0;
  rep(i,n){
    ll a;
    cin >> a;
    s += a;
    mp[s] ++;
  }
  ll ans = 0;
  for(auto p : mp){
    ll q = p.second;
    ans += q*(q-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 16044
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  // find x s.t. a^x = b
  static T log(T a,T b){
    const T sq=40000;
    unordered_map<T, T> dp;
    dp.reserve(sq);
    Mint res(1);
    for(Int r=0;r<sq;r++){
      if(!dp.count(res.v)) dp[res.v]=r;
      res*=a;
    }
    Mint p=Mint(a).inv().pow(sq);
    res=b;
    for(Int q=0;q<=MOD/sq+1;q++){
      if(dp.count(res.v)){
        T idx=q*sq+dp[res.v];
        if(idx>0) return idx;
      }
      res*=p;
    }
    assert(0);
    return T(-1);
  }

  static Mint comb(long long n,Int k){
    Mint num(1),dom(1);
    for(Int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

//INSERT ABOVE HERE
using M = Mint<Int>;
M dp[2][2][2][100];
Int used[2][2][2][100]={};

Int l,r;
M dfs(Int s,Int a,Int b,Int k){
  //cout<<s<<" "<<a<<" "<<b<<" "<<k<<endl;
  if(k<0) return M(1);
  M &res=dp[s][a][b][k];
  if(used[s][a][b][k]) return res;
  res=M(0);
  used[s][a][b][k]=1;

  Int lb=(l>>k)&1;
  Int ub=(r>>k)&1;
  for(Int p=0;p<2;p++){
    for(Int q=0;q<=p;q++){
      if(!s&&(p!=q)) continue;
      if(!a&&(q<lb)) continue;
      if(!b&&(p>ub)) continue;
      Int na=a||(q>lb);
      Int nb=b||(p<ub);
      res+=dfs(s||p||q,na,nb,k-1);
    }
  }
  //cout<<s<<" "<<a<<" "<<b<<" "<<k<<":"<<res<<endl;
  return res;
}

signed main(){
  cin>>l>>r;
  cout<<dfs(0,0,0,62)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll q,h,s,d;
    cin>>q>>h>>s>>d;
    ll n;
    cin>>n;
    n*=4;
    
    h=min(h,q*2);
    s=min(s,h*2);
    d=min(d,s*2);
    ll ans=ll(n/8)*d;
    n%=8;
    ans+=ll(n/4)*s;
    n%=4;
    ans+=ll(n/2)*h;
    n%=2;
    ans+=ll(n)*q;
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256